Skip to content

Commit

Permalink
Disable invalid warning about use of strncpy()
Browse files Browse the repository at this point in the history
GCC 10+ is producing a warning that strncpy() may truncate without valid
nul termination, however, the code is easily checked that nul
termination is added immediately afterwards.

Signed-off-by: Loren M. Lang <[email protected]>
Signed-off-by: Aaron Conole <[email protected]>
  • Loading branch information
penguin359 authored and apconole committed Aug 16, 2024
1 parent 6c947ee commit f7d0f97
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/lldp.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ typedef __u64 u64;
#ifdef HAVE_STRLCPY
#define STRNCPY_TERMINATED(DEST, SRC, N) \
(void)strlcpy(DEST, SRC, N)
#elif __GNUC__ >= 10
#define STRNCPY_TERMINATED(DEST, SRC, N) \
do { \
if((N) > 0) { \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"") \
strncpy (DEST, SRC, (N) - 1); \
_Pragma("GCC diagnostic pop") \
DEST[(N) - 1] = '\0'; \
} \
} while (false)
#else
#define STRNCPY_TERMINATED(DEST, SRC, N) \
do { \
Expand Down

0 comments on commit f7d0f97

Please sign in to comment.