diff options
author | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-11-22 21:06:22 +0100 |
---|---|---|
committer | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-11-24 17:20:09 +0100 |
commit | 389470bd141fa22546b461f358b39d7dcbeac19e (patch) | |
tree | f727e3b2e7f7240f1aa3bccea03d651e5bce3fd7 /src | |
parent | 1c25f1d9475ad763138c67f538aee37ef9ab5aee (diff) | |
download | rneovim-389470bd141fa22546b461f358b39d7dcbeac19e.tar.gz rneovim-389470bd141fa22546b461f358b39d7dcbeac19e.tar.bz2 rneovim-389470bd141fa22546b461f358b39d7dcbeac19e.zip |
Fix substitute newline: Memory functions: Improve style.
`try_malloc` was changed in 8bb2c2c0742c57150655e18cf8418a758cebdce8 to
avoid a warning when size is 0. Then, this improves some things on that:
- Use local vars instead of changing parameters.
- Homogenize style for other related functions.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/memory.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/nvim/memory.c b/src/nvim/memory.c index c2c406a235..f305c4628f 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -49,11 +49,11 @@ static void try_to_free_memory(void) /// @return pointer to allocated space. NULL if out of memory void *try_malloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1) { - size = size ? size : 1; - void *ret = malloc(size); + size_t allocated_size = size ? size : 1; + void *ret = malloc(allocated_size); if (!ret) { try_to_free_memory(); - ret = malloc(size); + ret = malloc(allocated_size); } return ret; } @@ -102,10 +102,12 @@ void *xmalloc(size_t size) void *xcalloc(size_t count, size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE_PROD(1, 2) FUNC_ATTR_NONNULL_RET { - void *ret = count && size ? calloc(count, size) : calloc(1, 1); + size_t allocated_count = count && size ? count : 1; + size_t allocated_size = count && size ? size : 1; + void *ret = calloc(allocated_count, allocated_size); if (!ret) { try_to_free_memory(); - ret = count && size ? calloc(count, size) : calloc(1, 1); + ret = calloc(allocated_count, allocated_size); if (!ret) { OUT_STR(e_outofmem); out_char('\n'); @@ -123,10 +125,11 @@ void *xcalloc(size_t count, size_t size) void *xrealloc(void *ptr, size_t size) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALLOC_SIZE(2) FUNC_ATTR_NONNULL_RET { - void *ret = size ? realloc(ptr, size) : realloc(ptr, 1); + size_t allocated_size = size ? size : 1; + void *ret = realloc(ptr, allocated_size); if (!ret) { try_to_free_memory(); - ret = size ? realloc(ptr, size) : realloc(ptr, 1); + ret = realloc(ptr, allocated_size); if (!ret) { OUT_STR(e_outofmem); out_char('\n'); |