From cf409d15fa78275e2606c4c53b550198ab5ef5c1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 27 Apr 2018 14:28:35 +0200 Subject: [PATCH] tree-wide: use newa() rather than alloca() where we can --- src/basic/calendarspec.c | 2 +- src/basic/process-util.c | 2 +- src/cgtop/cgtop.c | 2 +- src/journal/journal-file.c | 4 ++-- src/journal/journal-send.c | 2 +- src/test/test-condition.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 24867f807b..a30de78dc2 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -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; diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 960920d3dd..4180769ee8 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -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); diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index de5083bdde..de7ecf54cd 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -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) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 07c25abb89..036594c735 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -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; diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index 0da07a1941..e0526a02ca 100644 --- a/src/journal/journal-send.c +++ b/src/journal/journal-send.c @@ -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); diff --git a/src/test/test-condition.c b/src/test/test-condition.c index 18f325f72f..eeea778679 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -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);