NetworkManager/shared
Thomas Haller d5ad315f11 shared: suppress -Werror=stringop-overflow= warning in nm_strndup_a()
nm_strndup_a() uses strncpy() because we want the behavior of clearing out
the memory after the first NUL byte. But that can cause a compiler warning:

    CC       src/settings/plugins/keyfile/libNetworkManager_la-nms-keyfile-utils.lo
  In file included from ../../shared/nm-default.h:279,
                   from ../../src/settings/plugins/keyfile/nms-keyfile-utils.c:20:
  In function ‘_nm_strndup_a_step’,
      inlined from ‘nms_keyfile_loaded_uuid_is_filename’ at ../../src/settings/plugins/keyfile/nms-keyfile-utils.c:65:9:
  ../../shared/nm-glib-aux/nm-macros-internal.h:1661:3: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
   1661 |   strncpy (s, str, len);
        |   ^~~~~~~~~~~~~~~~~~~~~
  ../../src/settings/plugins/keyfile/nms-keyfile-utils.c: In function ‘nms_keyfile_loaded_uuid_is_filename’:
  ../../src/settings/plugins/keyfile/nms-keyfile-utils.c:48:8: note: length computed here
     48 |  len = strlen (filename);
        |        ^~~~~~~~~~~~~~~~~

It's true that the len argument of _nm_strndup_a_step() depends on the
string length of the source string. But in this case it's safe, because
we checked that the destination buffer is exactly the right size too.
By that reasoning we should use memcpy() or strcpy(), but both are
unsuitable. That is because we want nm_strndup_a() to behave like
strndup(), which means we need to handle cases where the len argument
is larger than the string length of the source string. That is, we want
always to return a buffer of size len+1, but we want to copy only the
characters up to the first NUL byte, and clear out the rest. That's what
strncpy() does for us.

Silence the warning.
2019-07-16 10:48:38 +02:00
..
c-list shared/c-list: reimport 2019-04-14 17:22:04 +02:00
c-rbtree shared/c-rbtree: reimport 2019-04-14 17:23:01 +02:00
c-siphash shared/c-siphash: reimport 2019-04-14 17:23:25 +02:00
c-stdaux shared: patch c-stdaux.h to not include <stdatomic.h> 2019-04-14 17:17:52 +02:00
n-acd shared/n-acd: reimport 2019-04-14 17:23:50 +02:00
n-dhcp4 n-dhcp4: client/probe: fix memory leak 2019-07-05 11:09:28 +02:00
nm-glib-aux shared: suppress -Werror=stringop-overflow= warning in nm_strndup_a() 2019-07-16 10:48:38 +02:00
nm-libnm-core-aux all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-libnm-core-intern all: drop empty first line from sources 2019-06-11 10:15:06 +02:00
nm-std-aux all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-udev-aux all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-utils libnm: add nm_connection_to_dbus_full() with options argument 2019-06-28 16:48:17 +02:00
systemd shared: add nm_sd_dns_name_to_wire_format() 2019-07-05 11:04:32 +02:00
meson.build systemd: add dns-domain utils to systemd static library 2019-07-05 11:04:32 +02:00
nm-default.h all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-meta-setting.c libnm-core: add ovs-dpdk setting 2019-06-14 12:10:20 +02:00
nm-meta-setting.h libnm-core: add ovs-dpdk setting 2019-06-14 12:10:20 +02:00
nm-test-libnm-utils.h all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-test-utils-impl.c all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-version-macros.h.in all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00