diff options
author | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-10-20 20:05:40 +0200 |
---|---|---|
committer | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-11-06 22:53:42 +0100 |
commit | 7ffed667d4ed1214e31d9f13bc1bd30f116c1b79 (patch) | |
tree | 2a867e45b149d463a7317cec905797e29d03ae45 | |
parent | fce201e6565008a24195eba3e8162c1f383e0112 (diff) | |
download | rneovim-7ffed667d4ed1214e31d9f13bc1bd30f116c1b79.tar.gz rneovim-7ffed667d4ed1214e31d9f13bc1bd30f116c1b79.tar.bz2 rneovim-7ffed667d4ed1214e31d9f13bc1bd30f116c1b79.zip |
Review: Remove long_u: memfile: Enable -Wconversion.
- Add memfile.c to converted files list.
- Fix conversion issues:
* bhdr_T : bh_page_count : int -> unsigned.
* bhdr_T : bh_flags : char -> unsigned.
* mf_new() : page_count : int -> unsigned.
* mf_get() : page_count : int -> unsigned.
* mf_release() : page_count : int -> unsigned.
* mf_alloc_bhdr() : page_count : int -> unsigned.
* mf_trans_add() : page_count : int -> unsigned.
* mf_put() : flags : int -> unsigned.
-rw-r--r-- | src/nvim/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/nvim/memfile.c | 31 | ||||
-rw-r--r-- | src/nvim/memfile_defs.h | 8 | ||||
-rw-r--r-- | src/nvim/memline.c | 4 |
4 files changed, 26 insertions, 18 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 57fb0fb50e..5b97cf5f40 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -45,6 +45,7 @@ set(CONV_SOURCES hashtab.c log.c map.c + memfile.c memory.c misc2.c profile.c diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index e2fe62f583..0e70865834 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -43,8 +43,10 @@ /// mf_trans_del() may translate negative to positive block number /// mf_fullname() make file name full path (use before first :cd) +#include <assert.h> #include <errno.h> #include <inttypes.h> +#include <limits.h> #include <string.h> #include "nvim/vim.h" @@ -116,7 +118,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) { - mfp->mf_page_size = blocksize; + assert(blocksize <= UINT_MAX); + mfp->mf_page_size = (unsigned)blocksize; } } @@ -147,7 +150,9 @@ memfile_T *mf_open(char_u *fname, int flags) --shift; } - mfp->mf_used_count_max = (p_mm << shift) / page_size; + assert(p_mm << shift >= p_mm); // check we don't overflow + assert(p_mm < UINT_MAX); // check we can cast to unsigned + mfp->mf_used_count_max = (unsigned)(p_mm << shift) / page_size; if (mfp->mf_used_count_max < 10) mfp->mf_used_count_max = 10; } @@ -254,7 +259,7 @@ void mf_new_page_size(memfile_T *mfp, unsigned new_size) /// /// @param negative TRUE if negative block number desired (data block) /// @param page_count Desired number of pages. -bhdr_T *mf_new(memfile_T *mfp, int negative, int page_count) +bhdr_T *mf_new(memfile_T *mfp, int negative, unsigned page_count) { // If we reached the maximum size for the used memory blocks, release one. // If a bhdr_T is returned, use it and adjust the page_count if necessary. @@ -311,8 +316,7 @@ bhdr_T *mf_new(memfile_T *mfp, int negative, int page_count) // Init the data to all zero, to avoid reading uninitialized data. // This also avoids that the passwd file ends up in the swap file! - (void)memset((char *)(hp->bh_data), 0, - (size_t)mfp->mf_page_size * page_count); + (void)memset((char *)(hp->bh_data), 0, mfp->mf_page_size * page_count); return hp; } @@ -322,7 +326,7 @@ bhdr_T *mf_new(memfile_T *mfp, int negative, int page_count) // Caller should first check a negative nr with mf_trans_del(). // // @return NULL if not found -bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, int page_count) +bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, unsigned page_count) { // check block number exists if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min) @@ -369,7 +373,7 @@ bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, int page_count) /// @param infile Block should be in file (needed for recovery). void mf_put(memfile_T *mfp, bhdr_T *hp, int dirty, int infile) { - int flags = hp->bh_flags; + unsigned flags = hp->bh_flags; if ((flags & BH_LOCKED) == 0) EMSG(_("E293: block was not locked")); @@ -558,7 +562,7 @@ static void mf_rem_used(memfile_T *mfp, bhdr_T *hp) /// - Tried to create swap file but couldn't. /// - All blocks are locked. /// - Unlocked dirty block found, but flush failed. -static bhdr_T *mf_release(memfile_T *mfp, int page_count) +static bhdr_T *mf_release(memfile_T *mfp, unsigned page_count) { // don't release while in mf_close_file() if (mf_dont_release) @@ -654,7 +658,7 @@ int mf_release_all(void) } /// Allocate a block header and a block of memory for it. -static bhdr_T *mf_alloc_bhdr(memfile_T *mfp, int page_count) +static bhdr_T *mf_alloc_bhdr(memfile_T *mfp, unsigned page_count) { bhdr_T *hp = xmalloc(sizeof(bhdr_T)); hp->bh_data = xmalloc(mfp->mf_page_size * page_count); @@ -811,7 +815,7 @@ static int mf_trans_add(memfile_T *mfp, bhdr_T *hp) // Otherwise use mf_blocknr_max. blocknr_T new_bnum; bhdr_T *freep = mfp->mf_free_first; - int page_count = hp->bh_page_count; + unsigned page_count = hp->bh_page_count; if (freep != NULL && freep->bh_page_count >= page_count) { new_bnum = freep->bh_bnum; // If the page count of the free block was larger, reduce it. @@ -980,7 +984,7 @@ static void mf_hash_free_all(mf_hashtab_T *mht) /// @return A pointer to a mf_hashitem_T or NULL if the item was not found. static mf_hashitem_T *mf_hash_find(mf_hashtab_T *mht, blocknr_T key) { - mf_hashitem_T *mhi = mht->mht_buckets[key & mht->mht_mask]; + mf_hashitem_T *mhi = mht->mht_buckets[(unsigned long)key & mht->mht_mask]; while (mhi != NULL && mhi->mhi_key != key) mhi = mhi->mhi_next; return mhi; @@ -989,7 +993,7 @@ static mf_hashitem_T *mf_hash_find(mf_hashtab_T *mht, blocknr_T key) /// Add item to hashtable. Item must not be NULL. static void mf_hash_add_item(mf_hashtab_T *mht, mf_hashitem_T *mhi) { - long_u idx = mhi->mhi_key & mht->mht_mask; + long_u idx = (unsigned long)mhi->mhi_key & mht->mht_mask; mhi->mhi_next = mht->mht_buckets[idx]; mhi->mhi_prev = NULL; if (mhi->mhi_next != NULL) @@ -1010,7 +1014,8 @@ static void mf_hash_add_item(mf_hashtab_T *mht, mf_hashitem_T *mhi) static void mf_hash_rem_item(mf_hashtab_T *mht, mf_hashitem_T *mhi) { if (mhi->mhi_prev == NULL) - mht->mht_buckets[mhi->mhi_key & mht->mht_mask] = mhi->mhi_next; + mht->mht_buckets[(unsigned long)mhi->mhi_key & mht->mht_mask] = + mhi->mhi_next; else mhi->mhi_prev->mhi_next = mhi->mhi_next; diff --git a/src/nvim/memfile_defs.h b/src/nvim/memfile_defs.h index 3141e700dd..ebecdea3a0 100644 --- a/src/nvim/memfile_defs.h +++ b/src/nvim/memfile_defs.h @@ -64,11 +64,11 @@ typedef struct bhdr { struct bhdr *bh_next; /// next block header in free or used list struct bhdr *bh_prev; /// previous block header in used list char_u *bh_data; /// pointer to memory (for used block) - int bh_page_count; /// number of pages in this block + unsigned bh_page_count; /// number of pages in this block -#define BH_DIRTY 1 -#define BH_LOCKED 2 - char bh_flags; // BH_DIRTY or BH_LOCKED +#define BH_DIRTY 1U +#define BH_LOCKED 2U + unsigned bh_flags; // BH_DIRTY or BH_LOCKED } bhdr_T; /// A block number translation list item. diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 04ee0d7f55..f0062c22bd 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -41,6 +41,7 @@ * mf_get(). */ +#include <assert.h> #include <errno.h> #include <inttypes.h> #include <string.h> @@ -2725,7 +2726,8 @@ static void ml_flush_line(buf_T *buf) */ static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count) { - bhdr_T *hp = mf_new(mfp, negative, page_count); + assert(page_count >= 0); + bhdr_T *hp = mf_new(mfp, negative, (unsigned)page_count); DATA_BL *dp = (DATA_BL *)(hp->bh_data); dp->db_id = DATA_ID; dp->db_txt_start = dp->db_txt_end = page_count * mfp->mf_page_size; |