util: Make virExpandN return void

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Jiri Denemark 2021-03-20 00:37:04 +01:00
parent 7d2fd6ef01
commit 52ef4a9af2
2 changed files with 8 additions and 10 deletions

View File

@ -66,12 +66,12 @@ int virReallocN(void *ptrptr,
* allocated memory. On failure, 'ptrptr' and 'countptr' are not * allocated memory. On failure, 'ptrptr' and 'countptr' are not
* changed. Any newly allocated memory in 'ptrptr' is zero-filled. * changed. Any newly allocated memory in 'ptrptr' is zero-filled.
* *
* Returns zero on success, aborts on OOM * Aborts on OOM
*/ */
int virExpandN(void *ptrptr, void virExpandN(void *ptrptr,
size_t size, size_t size,
size_t *countptr, size_t *countptr,
size_t add) size_t add)
{ {
if (*countptr + add < *countptr) if (*countptr + add < *countptr)
abort(); abort();
@ -80,7 +80,6 @@ int virExpandN(void *ptrptr,
abort(); abort();
memset(*(char **)ptrptr + (size * *countptr), 0, size * add); memset(*(char **)ptrptr + (size * *countptr), 0, size * add);
*countptr += add; *countptr += add;
return 0;
} }
/** /**
@ -192,8 +191,7 @@ virInsertElementsN(void *ptrptr, size_t size, size_t at,
if (inPlace) { if (inPlace) {
*countptr += add; *countptr += add;
} else { } else {
if (virExpandN(ptrptr, size, countptr, add) < 0) virExpandN(ptrptr, size, countptr, add);
abort();
} }
/* memory was successfully re-allocated. Move up all elements from /* memory was successfully re-allocated. Move up all elements from

View File

@ -36,7 +36,7 @@
/* Don't call these directly - use the macros below */ /* Don't call these directly - use the macros below */
int virReallocN(void *ptrptr, size_t size, size_t count) int virReallocN(void *ptrptr, size_t size, size_t count)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
int virExpandN(void *ptrptr, size_t size, size_t *count, size_t add) void virExpandN(void *ptrptr, size_t size, size_t *count, size_t add)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
void virResizeN(void *ptrptr, size_t size, size_t *alloc, size_t count, size_t desired) void virResizeN(void *ptrptr, size_t size, size_t *alloc, size_t count, size_t desired)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
@ -78,7 +78,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. * This macro is safe to use on arguments with side effects.
* *
* Returns 0 on success, aborts on OOM * Aborts on OOM
*/ */
#define VIR_EXPAND_N(ptr, count, add) virExpandN(&(ptr), sizeof(*(ptr)), &(count), add) #define VIR_EXPAND_N(ptr, count, add) virExpandN(&(ptr), sizeof(*(ptr)), &(count), add)