diff anagram/agcore/stacks.cpp @ 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 13d2b8934445
children
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;