mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
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.
This commit is contained in:

committed by
Thiago de Arruda

parent
7bdd1f1898
commit
0e998066b2
26
src/misc2.c
26
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
|
||||
|
Reference in New Issue
Block a user