]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
coregrind/m_gdbserver/remote-utils.c (prepare_resume_reply): Use memcpy
authorMark Wielaard <mark@klomp.org>
Thu, 14 Nov 2024 11:25:27 +0000 (12:25 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 14 Nov 2024 11:42:38 +0000 (12:42 +0100)
GCC8 (but apparently not later versions) complain about the use of
strncpy when not actually copying a string:

remote-utils.c:1140:14: warning: 'char* strncpy(char*, const char*, size_t)' output truncated before terminating nul copying 6 bytes from a string of the same length [-Wstringop-truncation]
          strncpy (buf, "watch:", 6);
          ~~~~~~~~^~~~~~~~~~~~~~~~~~

This is "harmless" because buf is large enough and we will add more
chars (including a zero terminator) later. But using strncpy here is a
bit odd because we don't really want to copy a string, but an array of
6 chars. So use memcpy here to do so, simplyfing the code.

coregrind/m_gdbserver/remote-utils.c

index b22dc4482bf006f985022533773997d1e04170f0..8dfc768d490d6ccb7f13d38166da31b92467e33e 100644 (file)
@@ -1137,7 +1137,7 @@ void prepare_resume_reply (char *buf, char status, unsigned char sig)
          CORE_ADDR addr;
          int i;
 
-         strncpy (buf, "watch:", 6);
+         VG_(memcpy) (buf, "watch:", 6);
          buf += 6;
 
          addr = valgrind_stopped_data_address ();