From 6d95d721e0f0314fe5cd1fd91c1122fd07f5881c Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 30 Apr 2026 22:02:01 +0000 Subject: [PATCH] Simplify function: return const strings, not static buffer --- libnetutil/netutil.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index 46c80b7e0..2f5198095 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -1989,14 +1989,11 @@ int islocalhost(const struct sockaddr_storage *ss) { } -char *nexthdrtoa(u8 nextheader, int acronym){ - -static char buffer[129]; -memset(buffer, 0, 129); +static const char *nexthdrtoa(u8 nextheader, int acronym){ #define HDRTOA(num, short_name, long_name) \ case num: \ - strncpy(buffer, acronym ? short_name : long_name, 128);\ + return (acronym ? short_name : long_name);\ break; switch(nextheader){ @@ -2151,13 +2148,12 @@ switch(nextheader){ HDRTOA(253, "experimental1", "Use for experimentation and testing") HDRTOA(254, "experimental2", "Use for experimentation and testing") default: - strncpy(buffer, acronym ? "unknown" : "Unknown protocol", 128);\ break; } /* End of switch */ - return buffer; + return (acronym ? "unknown" : "Unknown protocol"); } /* End of nexthdrtoa() */