From b5c840431a0bf443ff81d8cc32458d52774512f2 Mon Sep 17 00:00:00 2001 From: Jonathan Liu Date: Wed, 26 Sep 2018 23:20:25 +1000 Subject: [PATCH] Suppress strncpy truncation warnings with GCC 8 and later. These warnings are bogus as the code is correct so we suppress them in the places they occur. --- unix/uxnet.c | 7 +++++++ unix/uxpty.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/unix/uxnet.c b/unix/uxnet.c index e13b9485..e0a7cb77 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -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); diff --git a/unix/uxpty.c b/unix/uxpty.c index a8429d76..41a96747 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -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