]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use STRLEN() to allocate buffer of constant size 7625/head
authorThomas Haller <thaller@redhat.com>
Wed, 13 Dec 2017 07:41:11 +0000 (08:41 +0100)
committerThomas Haller <thaller@redhat.com>
Wed, 13 Dec 2017 10:12:19 +0000 (11:12 +0100)
Using strlen() to declare a buffer results in a variable-length array,
even if the compiler likely optimizes it to be a compile time constant.

When building with -Wvla, certain versions of gcc complain about such
buffers. Compiling with -Wvla has the advantage of preventing variably
length array, which defeat static asserts that are implemented by
declaring an array of negative length.

src/basic/fd-util.c
src/libsystemd-network/sd-dhcp-lease.c

index f3863722eebbcb2f4eb1c5e9ecba574a78da1ab4..a0820a9667d6d8a89df3a8ae2bfd9bd5100a0c52 100644 (file)
@@ -368,7 +368,7 @@ bool fdname_is_valid(const char *s) {
 }
 
 int fd_get_path(int fd, char **ret) {
-        char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
+        char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
         int r;
 
         xsprintf(procfs_path, "/proc/self/fd/%i", fd);
index 7063bd986e81dc849cf45e59b4e0813c64981178..a186bca38f6a9170a58a7666c98abec704ab3736 100644 (file)
@@ -987,7 +987,7 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
         }
 
         LIST_FOREACH(options, option, lease->private_options) {
-                char key[strlen("OPTION_000")+1];
+                char key[STRLEN("OPTION_000")+1];
 
                 xsprintf(key, "OPTION_%" PRIu8, option->tag);
                 r = serialize_dhcp_option(f, key, option->data, option->length);