changeset 7:57b2cc9b87f7

Use memcpy instead of strncpy when we know the length anyway. Modern gcc seems to think it knows how to detect misuse of strncpy, but it's wrong (in fact: very, very wrong) and the path of least resistance is to not try to fight with it.
author David A. Holland
date Mon, 30 May 2022 23:47:52 -0400
parents 607e3be6bad8
children ec2b657edf13
files anagram/agcore/stacks.cpp anagram/support/agstring.cpp
diffstat 2 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/anagram/agcore/stacks.cpp	Mon May 30 23:46:22 2022 -0400
+++ b/anagram/agcore/stacks.cpp	Mon May 30 23:47:52 2022 -0400
@@ -172,7 +172,7 @@
   }
   lcx = nc;
   string_base = &cs[lcx];
-  strncpy(string_base,s,n);
+  memcpy(string_base,s,n);
   nc += is[ni++] = n;
   cs[nc] = 0;
 }
@@ -198,7 +198,7 @@
     cs = reallocate(cs,k,char);
     string_base = &cs[lcx];
   }
-  strncpy(&cs[nc], s, n);
+  memcpy(&cs[nc], s, n);
   nc += n;
   is[ni-1] += n;
   cs[nc] = 0;
--- a/anagram/support/agstring.cpp	Mon May 30 23:46:22 2022 -0400
+++ b/anagram/support/agstring.cpp	Mon May 30 23:47:52 2022 -0400
@@ -82,7 +82,7 @@
     assert(store != 0);
     ((short *)(void *) store)[-1] = 1;
     if (s) {
-      strncpy(store, s, k);
+      memcpy(store, s, k);
     }
     store[k] = 0;
   }