about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2018-07-06 11:30:02 +0200
committerMichael Vetter <jubalh@iodoru.org>2018-07-06 11:31:20 +0200
commit64d5f938fd4d8e9913d10a1639160d6fcdbe8159 (patch)
tree5da4dda2422606deefdca366f0d7f54c861c1419
parent34aa7a717cf3f19b77cd5556f2bda91cdbfb2a30 (diff)
downloadprofani-tty-64d5f938fd4d8e9913d10a1639160d6fcdbe8159.tar.gz
Fix gcc8 error about strncpy
With gcc8 we get the following error when stringop-truncation is on:

```
In function ‘_rotate_log_file’,
    inlined from ‘log_msg.part.2’ at src/log.c:201:17:
src/log.c:231:5: error: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
     strncpy(log_file_new, log_file, len);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/log.c: In function ‘log_msg.part.2’:
src/log.c:228:18: note: length computed here
     size_t len = strlen(log_file);
                  ^~~~~~~~~~~~~~~~
```

Using memcpy instead of strncpy.
-rw-r--r--src/log.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/log.c b/src/log.c
index 78306c3c..886e6aac 100644
--- a/src/log.c
+++ b/src/log.c
@@ -228,7 +228,7 @@ _rotate_log_file(void)
     size_t len = strlen(log_file);
     char *log_file_new = malloc(len + 3);
 
-    strncpy(log_file_new, log_file, len);
+    memcpy(log_file_new, log_file, len);
     log_file_new[len] = '.';
     log_file_new[len+1] = '1';
     log_file_new[len+2] = 0;