From c2f3e361c52ec4e7149ea1d8c6a1202e0873da8e Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 19 Apr 2017 19:11:50 +0300 Subject: *: Add comment to all C files --- src/nvim/memfile.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/memfile.c') diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 5d6639c4d0..efaf1f94c5 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + /// An abstraction to handle blocks of memory which can be stored in a file. /// This is the implementation of a sort of virtual memory. /// -- cgit From 7d895ee05329d520a5d26c3dc7ede10ab9a36d94 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:19:57 +0300 Subject: memfile: Fix V547: always true condition `blocksize` was checked against UINT_MAX after it was checked against MAX_SWAP_PAGE_SIZE which makes it always pass the check. Better use STATIC_ASSERT instead. --- src/nvim/memfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/memfile.c') diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index efaf1f94c5..1abc69727c 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -54,6 +54,7 @@ #include "nvim/memory.h" #include "nvim/os_unix.h" #include "nvim/path.h" +#include "nvim/assert.h" #include "nvim/os/os.h" #include "nvim/os/input.h" @@ -108,7 +109,8 @@ memfile_T *mf_open(char_u *fname, int flags) if (mfp->mf_fd >= 0 && os_fileinfo_fd(mfp->mf_fd, &file_info)) { uint64_t blocksize = os_fileinfo_blocksize(&file_info); if (blocksize >= MIN_SWAP_PAGE_SIZE && blocksize <= MAX_SWAP_PAGE_SIZE) { - assert(blocksize <= UINT_MAX); + STATIC_ASSERT(MAX_SWAP_PAGE_SIZE <= UINT_MAX, + "MAX_SWAP_PAGE_SIZE must fit into an unsigned"); mfp->mf_page_size = (unsigned)blocksize; } } -- cgit From 953f26bace041f481e79b67b64401aa07259055c Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 16 Nov 2016 09:24:10 -0500 Subject: vim-patch:7.4.1975 Problem: On MS-Windows large files (> 2Gbyte) cause problems. Solution: Use "off_T" instead of "off_t". Use "stat_T" instead of "struct stat". Use 64 bit system functions if available. (Ken Takata) https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe Only the off_T changes are relevant, since all the "struct stat" usage is abstracted by libuv. --- src/nvim/memfile.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/memfile.c') diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 1abc69727c..9429703620 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -115,18 +115,18 @@ memfile_T *mf_open(char_u *fname, int flags) } } - off_t size; + off_T size; // When recovering, the actual block size will be retrieved from block 0 // in ml_recover(). The size used here may be wrong, therefore mf_blocknr_max // must be rounded up. if (mfp->mf_fd < 0 || (flags & (O_TRUNC|O_EXCL)) - || (size = lseek(mfp->mf_fd, (off_t)0L, SEEK_END)) <= 0) { + || (size = vim_lseek(mfp->mf_fd, 0L, SEEK_END)) <= 0) { // no file or empty file mfp->mf_blocknr_max = 0; } else { - assert(sizeof(off_t) <= sizeof(blocknr_T) + assert(sizeof(off_T) <= sizeof(blocknr_T) && mfp->mf_page_size > 0 && mfp->mf_page_size - 1 <= INT64_MAX - size); mfp->mf_blocknr_max = (((blocknr_T)size + mfp->mf_page_size - 1) @@ -689,9 +689,9 @@ static int mf_read(memfile_T *mfp, bhdr_T *hp) return FAIL; unsigned page_size = mfp->mf_page_size; - // TODO(elmart): Check (page_size * hp->bh_bnum) within off_t bounds. - off_t offset = (off_t)(page_size * hp->bh_bnum); - if (lseek(mfp->mf_fd, offset, SEEK_SET) != offset) { + // TODO(elmart): Check (page_size * hp->bh_bnum) within off_T bounds. + off_T offset = (off_T)(page_size * hp->bh_bnum); + if (vim_lseek(mfp->mf_fd, offset, SEEK_SET) != offset) { PERROR(_("E294: Seek error in swap file read")); return FAIL; } @@ -716,7 +716,7 @@ static int mf_read(memfile_T *mfp, bhdr_T *hp) /// - Write error in swap file. static int mf_write(memfile_T *mfp, bhdr_T *hp) { - off_t offset; // offset in the file + off_T offset; // offset in the file blocknr_T nr; // block nr which is being written bhdr_T *hp2; unsigned page_size; // number of bytes in a page @@ -745,9 +745,9 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp) hp2 = hp; } - // TODO(elmart): Check (page_size * nr) within off_t bounds. - offset = (off_t)(page_size * nr); - if (lseek(mfp->mf_fd, offset, SEEK_SET) != offset) { + // TODO(elmart): Check (page_size * nr) within off_T bounds. + offset = (off_T)(page_size * nr); + if (vim_lseek(mfp->mf_fd, offset, SEEK_SET) != offset) { PERROR(_("E296: Seek error in swap file write")); return FAIL; } -- cgit From d258ac8ed21b3a202212792688b237d0741f6844 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 13 Aug 2017 18:46:09 +0200 Subject: io: more guards against NULL filename (#7159) References ac055d677aa9 References #4370 --- src/nvim/memfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/memfile.c') diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 9429703620..4428dd42aa 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -895,6 +895,7 @@ static bool mf_do_open(memfile_T *mfp, char_u *fname, int flags) { // fname cannot be NameBuff, because it must have been allocated. mf_set_fnames(mfp, fname); + assert(mfp->mf_fname != NULL); /// Extra security check: When creating a swap file it really shouldn't /// exist yet. If there is a symbolic link, this is most likely an attack. -- cgit