chiark / gitweb /
tree-wide: use STRLEN() to allocate buffer of constant size
authorThomas Haller <thaller@redhat.com>
Wed, 13 Dec 2017 07:41:11 +0000 (08:41 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 13 Dec 2017 07:41:11 +0000 (08:41 +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

index 565902c7b844e13a39ad50d3732f2b3601b63432..a2d51d807076adb9953e148901d19706f76cfb3c 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);