Skip to content

Commit

Permalink
lib/net: avoid warning in log_if_name()
Browse files Browse the repository at this point in the history
Newer GCC was issuing the following warning for the call of
strncpy() in log_if_name():

/usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: ‘__builtin_strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~

The warning is not proper because the code is already handling
string trucations.

This commit disable -Wstringop-truncation for that single call of
strncpy() using #pragma.
  • Loading branch information
AltraMayor committed Jun 10, 2024
1 parent f4353b4 commit 36c8d99
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,10 @@ log_if_name(char *if_name, size_t len, const struct gatekeeper_if *iface,
}
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy(if_name, iface->name, len);
#pragma GCC diagnostic pop
if (unlikely(if_name[len - 1] != '\0')) {
G_LOG(CRIT, "%s(%s/%u): bug: len = %lu < strlen(iface->name) = %lu\n",
__func__, iface->name, port_id,
Expand Down

0 comments on commit 36c8d99

Please sign in to comment.