1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +03:00

Add repalloc0 and repalloc0_array

These zero out the space added by repalloc.  This is a common pattern
that is quite hairy to code by hand.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/b66dfc89-9365-cb57-4e1f-b7d31813eeec@enterprisedb.com
This commit is contained in:
Peter Eisentraut
2022-11-12 20:31:27 +01:00
parent 30d98e14a8
commit b4b7ce8061
10 changed files with 48 additions and 71 deletions

View File

@@ -1395,6 +1395,26 @@ repalloc_extended(void *pointer, Size size, int flags)
return ret;
}
/*
* repalloc0
* Adjust the size of a previously allocated chunk and zero out the added
* space.
*/
void *
repalloc0(void *pointer, Size oldsize, Size size)
{
void *ret;
/* catch wrong argument order */
if (unlikely(oldsize > size))
elog(ERROR, "invalid repalloc0 call: oldsize %zu, new size %zu",
oldsize, size);
ret = repalloc(pointer, size);
memset((char *) ret + oldsize, 0, (size - oldsize));
return ret;
}
/*
* MemoryContextAllocHuge
* Allocate (possibly-expansive) space within the specified context.