Mercurial > ~dholland > hg > ag > index.cgi
comparison 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 |
comparison
equal
deleted
inserted
replaced
6:607e3be6bad8 | 7:57b2cc9b87f7 |
---|---|
170 assert(lcs >= nc + n); | 170 assert(lcs >= nc + n); |
171 cs = reallocate(cs,k,char); | 171 cs = reallocate(cs,k,char); |
172 } | 172 } |
173 lcx = nc; | 173 lcx = nc; |
174 string_base = &cs[lcx]; | 174 string_base = &cs[lcx]; |
175 strncpy(string_base,s,n); | 175 memcpy(string_base,s,n); |
176 nc += is[ni++] = n; | 176 nc += is[ni++] = n; |
177 cs[nc] = 0; | 177 cs[nc] = 0; |
178 } | 178 } |
179 | 179 |
180 void ass(const char *s) { | 180 void ass(const char *s) { |
196 LOGV(lcs) LCV(nc+n); | 196 LOGV(lcs) LCV(nc+n); |
197 assert(lcs >= nc + n); | 197 assert(lcs >= nc + n); |
198 cs = reallocate(cs,k,char); | 198 cs = reallocate(cs,k,char); |
199 string_base = &cs[lcx]; | 199 string_base = &cs[lcx]; |
200 } | 200 } |
201 strncpy(&cs[nc], s, n); | 201 memcpy(&cs[nc], s, n); |
202 nc += n; | 202 nc += n; |
203 is[ni-1] += n; | 203 is[ni-1] += n; |
204 cs[nc] = 0; | 204 cs[nc] = 0; |
205 } | 205 } |
206 | 206 |