Skip to content

Commit

Permalink
Suppress strncpy truncation warnings with GCC 8 and later.
Browse files Browse the repository at this point in the history
These warnings are bogus as the code is correct so we suppress them in
the places they occur.
  • Loading branch information
net147 authored and sgtatham committed Sep 26, 2018
1 parent 822d2fd commit b5c8404
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions unix/uxnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,14 @@ Socket new_unix_listener(SockAddr listenaddr, Plug plug)

memset(&u, '\0', sizeof(u));
u.su.sun_family = AF_UNIX;
#if __GNUC__ >= 8
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wstringop-truncation"
#endif // __GNUC__ >= 8
strncpy(u.su.sun_path, listenaddr->hostname, sizeof(u.su.sun_path)-1);
#if __GNUC__ >= 8
# pragma GCC diagnostic pop
#endif // __GNUC__ >= 8
addr = &u;
addrlen = sizeof(u.su);

Expand Down
7 changes: 7 additions & 0 deletions unix/uxpty.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,17 @@ static void setup_utmp(char *ttyname, char *location)
memset(&utmp_entry, 0, sizeof(utmp_entry));
utmp_entry.ut_type = USER_PROCESS;
utmp_entry.ut_pid = getpid();
#if __GNUC__ >= 8
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wstringop-truncation"
#endif // __GNUC__ >= 8
strncpy(utmp_entry.ut_line, ttyname+5, lenof(utmp_entry.ut_line));
strncpy(utmp_entry.ut_id, ttyname+8, lenof(utmp_entry.ut_id));
strncpy(utmp_entry.ut_user, pw->pw_name, lenof(utmp_entry.ut_user));
strncpy(utmp_entry.ut_host, location, lenof(utmp_entry.ut_host));
#if __GNUC__ >= 8
# pragma GCC diagnostic pop
#endif // __GNUC__ >= 8
/*
* Apparently there are some architectures where (struct
* utmpx).ut_tv is not essentially struct timeval (e.g. Linux
Expand Down

0 comments on commit b5c8404

Please sign in to comment.