1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-05 09:17:44 +03:00

tree-wide: use STRLEN() to allocate buffer of constant size

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.
This commit is contained in:
Thomas Haller 2017-12-13 08:41:11 +01:00
parent 6febe75da7
commit dbcb4a900e
2 changed files with 2 additions and 2 deletions

View 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);

View 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);