Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

unifdef: use memcpy instead of strncpy

New versions of gcc reasonably warn about the odd pattern of

strncpy(p, q, strlen(q));

which really doesn't make sense: the strncpy() ends up being just a slow
and odd way to write memcpy() in this case.

There was a comment about _why_ the code used strncpy - to avoid the
terminating NUL byte, but memcpy does the same and avoids the warning.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+2 -2
+2 -2
scripts/unifdef.c
··· 395 395 * When we have processed a group that starts off with a known-false 396 396 * #if/#elif sequence (which has therefore been deleted) followed by a 397 397 * #elif that we don't understand and therefore must keep, we edit the 398 - * latter into a #if to keep the nesting correct. We use strncpy() to 398 + * latter into a #if to keep the nesting correct. We use memcpy() to 399 399 * overwrite the 4 byte token "elif" with "if " without a '\0' byte. 400 400 * 401 401 * When we find a true #elif in a group, the following block will ··· 450 450 static void Itrue (void) { Ftrue(); ignoreon(); } 451 451 static void Ifalse(void) { Ffalse(); ignoreon(); } 452 452 /* modify this line */ 453 - static void Mpass (void) { strncpy(keyword, "if ", 4); Pelif(); } 453 + static void Mpass (void) { memcpy(keyword, "if ", 4); Pelif(); } 454 454 static void Mtrue (void) { keywordedit("else"); state(IS_TRUE_MIDDLE); } 455 455 static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); } 456 456 static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); }