diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-03-29 01:05:04 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-31 07:31:47 -0300 |
commit | 0e998066b2533de3cf87ece1068839e60e128f1a (patch) | |
tree | 0dc09cd25ef39a59e6f9c1c41493e11bacea8f79 /src/misc2.c | |
parent | 7bdd1f1898c6c94326e4642d8f51f74cc14b5f9d (diff) | |
download | rneovim-0e998066b2533de3cf87ece1068839e60e128f1a.tar.gz rneovim-0e998066b2533de3cf87ece1068839e60e128f1a.tar.bz2 rneovim-0e998066b2533de3cf87ece1068839e60e128f1a.zip |
xrealloc(): similar to xmalloc()
Replaced all calls to realloc by xrealloc. All `== NULL` tests can be removed
and the code within `!= NULL` tests can be unwrapped.
Diffstat (limited to 'src/misc2.c')
-rw-r--r-- | src/misc2.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/misc2.c b/src/misc2.c index 143a106c40..3218de2156 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -696,6 +696,32 @@ void *xmalloc(size_t size) return ret; } +/// realloc() wrapper +/// +/// @see {xmalloc} +/// @param size +/// @return pointer to reallocated space. Never NULL +void *xrealloc(void *ptr, size_t size) +{ + void *ret = realloc(ptr, size); + + if (!ret && !size) + ret = realloc(ptr, 1); + + if (!ret) { + try_to_free_memory(); + ret = realloc(ptr, size); + if (!ret && !size) + ret = realloc(ptr, 1); + if (!ret) { + OUT_STR("Vim: Error: Out of memory.\n"); + preserve_exit(); + } + } + + return ret; +} + /// Old low level memory allocation function. /// /// @deprecated use xmalloc() directly instead |