]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use newa() instead of alloca() wherever we can 11566/head
authorLennart Poettering <lennart@poettering.net>
Sat, 26 Jan 2019 14:52:18 +0000 (15:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 26 Jan 2019 15:17:04 +0000 (16:17 +0100)
Typesafety is nice. And this way we can take benefit of the new size
assert() the previous commit added.

13 files changed:
src/basic/path-util.h
src/basic/process-util.h
src/basic/string-util.h
src/journal/audit-type.h
src/journal/journal-send.c
src/journal/journald-audit.c
src/libsystemd-network/network-internal.c
src/libsystemd/sd-bus/bus-objects.c
src/libsystemd/sd-bus/bus-socket.c
src/network/netdev/netdev.c
src/nspawn/nspawn-network.c
src/resolve/resolved-dns-dnssec.c
src/tmpfiles/tmpfiles.c

index 094aa47c01deb87e5da3d00a319d0992205c8369..86c5a577cb46d2db8ad0cf3e1256fe91a5878c15 100644 (file)
@@ -131,7 +131,7 @@ char *prefix_root(const char *root, const char *path);
                         _ret = _path;                                   \
                 else {                                                  \
                         _l = strlen(_root) + 1 + strlen(_path) + 1;     \
-                        _n = alloca(_l);                                \
+                        _n = newa(char, _l);                            \
                         _p = stpcpy(_n, _root);                         \
                         while (_p > _n && _p[-1] == '/')                \
                                 _p--;                                   \
index 496e14d3de17667217e455c43471bf9f9dd39b8c..c85ea30ecc78544719b22ec625c3ca7e9d61b20a 100644 (file)
@@ -24,8 +24,8 @@
                 if (_pid_ == 0) {                                       \
                         _r_ = ("/proc/self/" field);                    \
                 } else {                                                \
-                        _r_ = alloca(STRLEN("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
-                        sprintf((char*) _r_, "/proc/"PID_FMT"/" field, _pid_);                       \
+                        _r_ = newa(char, STRLEN("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
+                        sprintf((char*) _r_, "/proc/"PID_FMT"/" field, _pid_); \
                 }                                                       \
                 _r_;                                                    \
         })
index a5b5a16a5d0f553d3c1713d5b4de1fce0e8f8601..38070abb22f89ecd2a78702055c6e5840b61aaf0 100644 (file)
@@ -6,6 +6,7 @@
 #include <stddef.h>
 #include <string.h>
 
+#include "alloc-util.h"
 #include "macro.h"
 
 /* What is interpreted as whitespace? */
@@ -111,7 +112,7 @@ char *strjoin_real(const char *x, ...) _sentinel_;
                 size_t _i_;                                           \
                 for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
                         _len_ += strlen(_appendees_[_i_]);              \
-                _p_ = _d_ = alloca(_len_ + 1);                          \
+                _p_ = _d_ = newa(char, _len_ + 1);                      \
                 for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
                         _p_ = stpcpy(_p_, _appendees_[_i_]);            \
                 *_p_ = 0;                                               \
index 069a883490d69b0b071d3327996bd2caa1a82db9..98e5c39420e6360e812fa5f24c6d618f95b8b34a 100644 (file)
@@ -4,6 +4,7 @@
 #include <alloca.h>
 #include <stdio.h>
 
+#include "alloc-util.h"
 #include "macro.h"
 
 const char *audit_type_to_string(int type);
@@ -15,7 +16,7 @@ int audit_type_from_string(const char *s);
                 const char *_s_;                                        \
                 _s_ = audit_type_to_string(type);                       \
                 if (!_s_) {                                             \
-                        _s_ = alloca(STRLEN("AUDIT") + DECIMAL_STR_MAX(int)); \
+                        _s_ = newa(char, STRLEN("AUDIT") + DECIMAL_STR_MAX(int)); \
                         sprintf((char*) _s_, "AUDIT%04i", type);        \
                 }                                                       \
                 _s_;                                                    \
index 87056435fcdd9973237e1f8c230884b4a5057975..8618454131bcb70c02c0a9d90d012fcc1de873bb 100644 (file)
@@ -30,7 +30,7 @@
                 const char *_func = (func);       \
                 char **_f = &(f);                 \
                 _fl = strlen(_func) + 1;          \
-                *_f = alloca(_fl + 10);           \
+                *_f = newa(char, _fl + 10);       \
                 memcpy(*_f, "CODE_FUNC=", 10);    \
                 memcpy(*_f + 10, _func, _fl);     \
         } while (false)
@@ -403,7 +403,7 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve
         identifier = strempty(identifier);
 
         l = strlen(identifier);
-        header = alloca(l + 1 + 1 + 2 + 2 + 2 + 2 + 2);
+        header = newa(char, l + 1 + 1 + 2 + 2 + 2 + 2 + 2);
 
         memcpy(header, identifier, l);
         header[l++] = '\n';
index 345e43ef44f7d3627be1b50cf922c24d397345fb..accbad418047c1d5f1e21ea56b3159e67f8542a5 100644 (file)
@@ -162,7 +162,7 @@ static int map_generic_field(const char *prefix, const char **p, struct iovec **
         if (e <= *p || e >= *p + 16)
                 return 0;
 
-        c = alloca(strlen(prefix) + (e - *p) + 2);
+        c = newa(char, strlen(prefix) + (e - *p) + 2);
 
         t = stpcpy(c, prefix);
         for (f = *p; f < e; f++) {
index b3b134d65057c467d108c222da695313198b4c63..0348e7fa9dabe93ce39f2bddc8c5f1c5300afa8b 100644 (file)
@@ -52,7 +52,7 @@ int net_get_unique_predictable_data(sd_device *device, uint64_t *result) {
 
         l = strlen(name);
         sz = sizeof(sd_id128_t) + l;
-        v = alloca(sz);
+        v = newa(uint8_t, sz);
 
         /* fetch some persistent data unique to this machine */
         r = sd_id128_get_machine((sd_id128_t*) v);
index d0538104ae251100f2e1ffd1f366040d646d6bfc..58329f3fe7885b9b68fa6fc7932e1317ff35760d 100644 (file)
@@ -1149,7 +1149,7 @@ static int object_manager_serialize_path_and_fallbacks(
                 return 0;
 
         /* Second, add fallback vtables registered for any of the prefixes */
-        prefix = alloca(strlen(path) + 1);
+        prefix = newa(char, strlen(path) + 1);
         OBJECT_PATH_FOREACH_PREFIX(prefix, path) {
                 r = object_manager_serialize_path(bus, reply, prefix, path, true, error);
                 if (r < 0)
@@ -1500,7 +1500,7 @@ static int bus_find_parent_object_manager(sd_bus *bus, struct node **out, const
         if (!n) {
                 char *prefix;
 
-                prefix = alloca(strlen(path) + 1);
+                prefix = newa(char, strlen(path) + 1);
                 OBJECT_PATH_FOREACH_PREFIX(prefix, path) {
                         n = hashmap_get(bus->nodes, prefix);
                         if (n)
@@ -2114,7 +2114,7 @@ _public_ int sd_bus_emit_properties_changed_strv(
                 if (bus->nodes_modified)
                         continue;
 
-                prefix = alloca(strlen(path) + 1);
+                prefix = newa(char, strlen(path) + 1);
                 OBJECT_PATH_FOREACH_PREFIX(prefix, path) {
                         r = emit_properties_changed_on_interface(bus, prefix, path, interface, true, &found_interface, names);
                         if (r != 0)
@@ -2291,7 +2291,7 @@ static int object_added_append_all(sd_bus *bus, sd_bus_message *m, const char *p
         if (bus->nodes_modified)
                 return 0;
 
-        prefix = alloca(strlen(path) + 1);
+        prefix = newa(char, strlen(path) + 1);
         OBJECT_PATH_FOREACH_PREFIX(prefix, path) {
                 r = object_added_append_all_prefix(bus, m, s, prefix, path, true);
                 if (r < 0)
@@ -2462,7 +2462,7 @@ static int object_removed_append_all(sd_bus *bus, sd_bus_message *m, const char
         if (bus->nodes_modified)
                 return 0;
 
-        prefix = alloca(strlen(path) + 1);
+        prefix = newa(char, strlen(path) + 1);
         OBJECT_PATH_FOREACH_PREFIX(prefix, path) {
                 r = object_removed_append_all_prefix(bus, m, s, prefix, path, true);
                 if (r < 0)
@@ -2626,7 +2626,7 @@ static int interfaces_added_append_one(
         if (bus->nodes_modified)
                 return 0;
 
-        prefix = alloca(strlen(path) + 1);
+        prefix = newa(char, strlen(path) + 1);
         OBJECT_PATH_FOREACH_PREFIX(prefix, path) {
                 r = interfaces_added_append_one_prefix(bus, m, prefix, path, interface, true);
                 if (r != 0)
index ed185131b83ae40215398b0453191cc67b2db2b4..30d6455b6fc76344ecdde97a402690e3e5548726 100644 (file)
@@ -981,7 +981,7 @@ int bus_socket_write_message(sd_bus *bus, sd_bus_message *m, size_t *idx) {
                 return r;
 
         n = m->n_iovec * sizeof(struct iovec);
-        iov = alloca(n);
+        iov = newa(struct iovec, n);
         memcpy_safe(iov, m->iovec, n);
 
         j = 0;
index 65959f4a03f308a22699b0cb77f573db28154349..0263917468789f8884b3393d7325a3eaa60ab6f6 100644 (file)
@@ -481,7 +481,7 @@ int netdev_get_mac(const char *ifname, struct ether_addr **ret) {
 
         l = strlen(ifname);
         sz = sizeof(sd_id128_t) + l;
-        v = alloca(sz);
+        v = newa(uint8_t, sz);
 
         /* fetch some persistent data unique to the machine */
         r = sd_id128_get_machine((sd_id128_t*) v);
index 9d0f8a9956b3fc47b93728f93915183f397c31da..c028b5755a841bf39890c94c8b0f238aff072f1e 100644 (file)
@@ -67,7 +67,7 @@ static int generate_mac(
         if (idx > 0)
                 sz += sizeof(idx);
 
-        v = alloca(sz);
+        v = newa(uint8_t, sz);
 
         /* fetch some persistent data unique to the host */
         r = sd_id128_get_machine((sd_id128_t*) v);
index 335fd477800888ad587ab8165c7fd66bf91d6d5c..14acc4e77db58c9029d1ce72c8e223f3fdd26d6a 100644 (file)
@@ -402,7 +402,7 @@ static int dnssec_ecdsa_verify(
         if (rrsig->rrsig.signature_size != key_size * 2)
                 return -EINVAL;
 
-        q = alloca(key_size*2 + 1);
+        q = newa(uint8_t, key_size*2 + 1);
         q[0] = 0x04; /* Prepend 0x04 to indicate an uncompressed key */
         memcpy(q+1, dnskey->dnskey.key, key_size*2);
 
index 03a9e1d1f0243df99fb9899bb047b16e30b44f92..b66765b407ee5c1ca9545dd118e84a5a3676136e 100644 (file)
@@ -3130,7 +3130,7 @@ static int link_parent(ItemArray *a) {
                 return 0;
 
         path = a->items[0].path;
-        prefix = alloca(strlen(path) + 1);
+        prefix = newa(char, strlen(path) + 1);
         PATH_FOREACH_PREFIX(prefix, path) {
                 ItemArray *j;