tree-wide: use newa() rather than alloca() where we can

This commit is contained in:
Lennart Poettering 2018-04-27 14:28:35 +02:00
parent 1232c44718
commit cf409d15fa
6 changed files with 7 additions and 7 deletions

View File

@ -104,7 +104,7 @@ static void normalize_chain(CalendarComponent **c) {
if (n <= 1)
return;
j = b = alloca(sizeof(CalendarComponent*) * n);
j = b = newa(CalendarComponent*, n);
for (i = *c; i; i = i->next)
*(j++) = i;

View File

@ -1433,7 +1433,7 @@ int fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret
va_end(ap);
/* Allocate strv */
l = alloca(sizeof(char *) * (n + 1));
l = newa(char*, n + 1);
/* Fill in arguments */
va_start(ap, path);

View File

@ -627,7 +627,7 @@ static void display(Hashmap *a) {
if (!terminal_is_dumb())
fputs(ANSI_HOME_CLEAR, stdout);
array = alloca(sizeof(Group*) * hashmap_size(a));
array = newa(Group*, hashmap_size(a));
HASHMAP_FOREACH(g, a, i)
if (g->n_tasks_valid || g->cpu_valid || g->memory_valid || g->io_valid)

View File

@ -1965,7 +1965,7 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
#endif
/* alloca() can't take 0, hence let's allocate at least one */
items = alloca(sizeof(EntryItem) * MAX(1u, n_iovec));
items = newa(EntryItem, MAX(1u, n_iovec));
for (i = 0; i < n_iovec; i++) {
uint64_t p;
@ -3581,7 +3581,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
n = journal_file_entry_n_items(o);
/* alloca() can't take 0, hence let's allocate at least one */
items = alloca(sizeof(EntryItem) * MAX(1u, n));
items = newa(EntryItem, MAX(1u, n));
for (i = 0; i < n; i++) {
uint64_t l, h;

View File

@ -518,7 +518,7 @@ _public_ int sd_journal_sendv_with_location(
assert_return(iov, -EINVAL);
assert_return(n > 0, -EINVAL);
niov = alloca(sizeof(struct iovec) * (n + 3));
niov = newa(struct iovec, (n + 3));
memcpy(niov, iov, sizeof(struct iovec) * n);
ALLOCA_CODE_FUNC(f, func);

View File

@ -608,7 +608,7 @@ static void test_condition_test_group(void) {
ngroups_max = sysconf(_SC_NGROUPS_MAX);
assert(ngroups_max > 0);
gids = alloca(sizeof(gid_t) * ngroups_max);
gids = newa(gid_t, ngroups_max);
ngroups = getgroups(ngroups_max, gids);
assert(ngroups >= 0);