NetworkManager/shared/nm-glib-aux
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
..
nm-c-list.h shared: add nm_c_list_elem_free_steal() util 2019-07-02 17:52:53 +02:00
nm-dbus-aux.c shared: add nm_dbus_connection_signal_subscribe_name_owner_changed() helper 2019-05-12 09:56:36 +02:00
nm-dbus-aux.h shared: add nm_dbus_connection_call_start_service_by_name() helper 2019-05-12 09:56:36 +02:00
nm-dedup-multi.c all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-dedup-multi.h all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-enum-utils.c all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-enum-utils.h all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-errno.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-errno.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-glib.h shared/glib: unconditionally redefine g_object_ref()/g_object_ref_sink() as typesafe macro 2019-06-26 09:53:54 +02:00
nm-hash-utils.c shared: add nm_pdirect_hash()/nm_pdirect_equal() 2019-07-10 12:43:06 +02:00
nm-hash-utils.h shared: add nm_pdirect_hash()/nm_pdirect_equal() 2019-07-10 12:43:06 +02:00
nm-io-utils.c shared: add nm_utils_file_stat() util 2019-06-26 09:53:54 +02:00
nm-io-utils.h shared: add nm_utils_file_stat() util 2019-06-26 09:53:54 +02:00
nm-jansson.h all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-json-aux.c shared: add nm_json_aux_gstr_append_*() helper 2019-05-23 18:09:49 +02:00
nm-json-aux.h shared: add JSON helper functions for NMValueType 2019-05-23 18:09:49 +02:00
nm-keyfile-aux.c shared: add NMKeyFileDB API 2019-05-07 16:41:21 +02:00
nm-keyfile-aux.h shared: add NMKeyFileDB API 2019-05-07 16:41:21 +02:00
nm-logging-fwd.h shared: implement _nm_utils_monotonic_timestamp_initialized() in "nm-logging-stub.c" 2019-05-22 20:04:08 +02:00
nm-macros-internal.h shared: suppress -Werror=stringop-overflow= warning in nm_strndup_a() 2019-07-16 10:48:38 +02:00
nm-obj.h all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-random-utils.c all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-random-utils.h all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-secret-utils.c all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-secret-utils.h all: drop emacs file variables from source files 2019-06-11 10:04:00 +02:00
nm-shared-utils.c shared: add nm_utils_strv_dup() util 2019-06-28 16:48:17 +02:00
nm-shared-utils.h shared: add NM_CMP_DIRECT_STRCMP() macro 2019-07-10 12:43:06 +02:00
nm-time-utils.c shared: implement _nm_utils_monotonic_timestamp_initialized() in "nm-logging-stub.c" 2019-05-22 20:04:08 +02:00
nm-time-utils.h shared: implement _nm_utils_monotonic_timestamp_initialized() in "nm-logging-stub.c" 2019-05-22 20:04:08 +02:00
nm-value-type.h shared: fix return in nm_value_type_to_variant()/nm_value_type_get_variant_type() 2019-05-27 13:27:13 +02:00