mirror of
https://github.com/systemd/systemd.git
synced 2025-03-25 18:50:18 +03:00
util: add greedy_realloc0()
Compared to greedy_realloc(), this sets all newly allocated memory to 0. As the old variant has been used a lot for string-handling, we avoid changing it as clearing memory is not needed there.
This commit is contained in:
parent
a0a6be9f6a
commit
4545a231fc
@ -5806,6 +5806,20 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need) {
|
||||
return q;
|
||||
}
|
||||
|
||||
void* greedy_realloc0(void **p, size_t *allocated, size_t need) {
|
||||
size_t prev = *allocated;
|
||||
uint8_t *q;
|
||||
|
||||
q = greedy_realloc(p, allocated, need);
|
||||
if (!q)
|
||||
return NULL;
|
||||
|
||||
if (*allocated > prev)
|
||||
memset(&q[prev], 0, *allocated - prev);
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
bool id128_is_valid(const char *s) {
|
||||
size_t i, l;
|
||||
|
||||
|
@ -669,8 +669,11 @@ char *strextend(char **x, ...) _sentinel_;
|
||||
char *strrep(const char *s, unsigned n);
|
||||
|
||||
void* greedy_realloc(void **p, size_t *allocated, size_t need);
|
||||
void* greedy_realloc0(void **p, size_t *allocated, size_t need);
|
||||
#define GREEDY_REALLOC(array, allocated, need) \
|
||||
greedy_realloc((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
|
||||
#define GREEDY_REALLOC0(array, allocated, need) \
|
||||
greedy_realloc0((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
|
||||
|
||||
static inline void _reset_errno_(int *saved_errno) {
|
||||
errno = *saved_errno;
|
||||
|
Loading…
x
Reference in New Issue
Block a user