mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
util: Make virReallocN return void
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
1107c0b9c3
commit
9eb7e9e817
@ -45,12 +45,11 @@ VIR_LOG_INIT("util.alloc");
|
||||
*
|
||||
* Returns zero on success, aborts on OOM
|
||||
*/
|
||||
int virReallocN(void *ptrptr,
|
||||
void virReallocN(void *ptrptr,
|
||||
size_t size,
|
||||
size_t count)
|
||||
{
|
||||
*(void **)ptrptr = g_realloc_n(*(void**)ptrptr, size, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,8 +75,7 @@ void virExpandN(void *ptrptr,
|
||||
if (*countptr + add < *countptr)
|
||||
abort();
|
||||
|
||||
if (virReallocN(ptrptr, size, *countptr + add) < 0)
|
||||
abort();
|
||||
virReallocN(ptrptr, size, *countptr + add);
|
||||
memset(*(char **)ptrptr + (size * *countptr), 0, size * add);
|
||||
*countptr += add;
|
||||
}
|
||||
@ -136,8 +134,7 @@ void virResizeN(void *ptrptr,
|
||||
void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove)
|
||||
{
|
||||
if (toremove < *countptr) {
|
||||
if (virReallocN(ptrptr, size, *countptr -= toremove) < 0)
|
||||
abort();
|
||||
virReallocN(ptrptr, size, *countptr -= toremove);
|
||||
} else {
|
||||
g_free(*((void **)ptrptr));
|
||||
*((void **)ptrptr) = NULL;
|
||||
|
@ -34,7 +34,7 @@
|
||||
*/
|
||||
|
||||
/* Don't call these directly - use the macros below */
|
||||
int virReallocN(void *ptrptr, size_t size, size_t count)
|
||||
void virReallocN(void *ptrptr, size_t size, size_t count)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
void virExpandN(void *ptrptr, size_t size, size_t *count, size_t add)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
|
||||
@ -61,7 +61,7 @@ int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
|
||||
*
|
||||
* This macro is safe to use on arguments with side effects.
|
||||
*
|
||||
* Returns 0 on success, aborts on OOM
|
||||
* Aborts on OOM
|
||||
*/
|
||||
#define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user