about summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-11-13 20:53:32 -0800
committerKartik Agaram <vc@akkartik.com>2020-11-13 20:53:32 -0800
commit236cf88a3e88c9585ce887462bcde5b70418535b (patch)
treea9326dfd2468e2ddbfcf02d7cb82d1a66040ebc0 /tools
parentea8a64cfb0f431f92846242332c51714cbaf5909 (diff)
downloadmu-236cf88a3e88c9585ce887462bcde5b70418535b.tar.gz
7233 - fix some warnings from gcc 9
Make strncpy a little less error-prone.
Just use memcpy where that suffices:
  https://stackoverflow.com/questions/56782248/gcc-specified-bound-depends-on-the-length-of-the-source-argument/56782476#56782476
Diffstat (limited to 'tools')
-rw-r--r--tools/termbox/output.inl6
1 files changed, 3 insertions, 3 deletions
diff --git a/tools/termbox/output.inl b/tools/termbox/output.inl
index d87049ef..490346f8 100644
--- a/tools/termbox/output.inl
+++ b/tools/termbox/output.inl
@@ -179,7 +179,7 @@ static char *terminfo_try_path(const char *path, const char *term) {
 }
 
 void string_copy(char* dest, const char* src, int dest_capacity) {
-  strncpy(dest, src, dest_capacity);
+  strncpy(dest, src, dest_capacity-1);
   dest[dest_capacity-1] = '\0';
 }
 
@@ -218,7 +218,7 @@ static char *load_terminfo(void) {
   if (dirs) {
     // snprintf guarantee for older compilers
     assert(sizeof(tmp) > sizeof(dirs));
-    strncpy(tmp, dirs, sizeof(tmp));
+    string_copy(tmp, dirs, sizeof(tmp));
     char *dir = strtok(tmp, ":");
     while (dir) {
       const char *cdir = dir;
@@ -245,7 +245,7 @@ static const char *terminfo_copy_string(char *data, int str, int table) {
   const char *src = data + table + off;
   int len = strlen(src);
   char *dst = malloc(len+1);
-  string_copy(dst, src, len+1);
+  memcpy(dst, src, len+1);
   return dst;
 }