From f4981f97bcd1c28fcc64f002ac89e5011870582f Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Tue, 8 May 2018 17:05:46 +0300 Subject: [PATCH] Replace strncpy call with memcpy when result is not NUL-terminated This fixes a new warning from GCC 8.1, -Wstringop-truncation: https://gcc.gnu.org/gcc-8/changes.html https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Warning-Options.html#index-Wstringop-truncation Replacing with memcpy is what gcc suggests: > As another example, the following call to strncpy results in copying > to d just the characters preceding the terminating NUL, without > appending the NUL to the end. Assuming the result of strncpy is > necessarily a NUL-terminated string is a common mistake, and so the > call is diagnosed. To avoid the warning when the result is not > expected to be NUL-terminated, call memcpy instead. > void copy (char *d, const char *s) > { > strncpy (d, s, strlen (s)); > } --- i3bar/src/ipc.c | 2 +- i3bar/src/xcb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/i3bar/src/ipc.c b/i3bar/src/ipc.c index 7a657338..56fe2798 100644 --- a/i3bar/src/ipc.c +++ b/i3bar/src/ipc.c @@ -309,7 +309,7 @@ int i3_send_msg(uint32_t type, const char *payload) { char *buffer = smalloc(to_write); char *walk = buffer; - strncpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)); + memcpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)); walk += strlen(I3_IPC_MAGIC); memcpy(walk, &len, sizeof(uint32_t)); walk += sizeof(uint32_t); diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 800c05d4..ae6c0abc 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -604,7 +604,7 @@ void handle_button(xcb_button_press_event_t *event) { const size_t len = namelen + strlen("workspace \"\"") + 1; char *buffer = scalloc(len + num_quotes, 1); - strncpy(buffer, "workspace \"", strlen("workspace \"")); + memcpy(buffer, "workspace \"", strlen("workspace \"")); size_t inpos, outpos; for (inpos = 0, outpos = strlen("workspace \""); inpos < namelen; -- 2.39.5