News for hackers. Stuff that matters.
Re:Why Does Software Rot? by kd5bjo on Saturday June 25, 2016 @06:10AM (#11975854)
You're correct about the problems, and I would always recommend strncpy over strcpy for safety, but it's not quite as limited as you portray: You only need to ensure an upper bound on the string length that will fit into your destination buffer. In addition to literals, this can also be guaranteed by copying a string that's already stored in a container that's smaller than the target, such as a fixed-size buffer or database field.
Re:Why Does Software Rot? by kazinator on Saturday June 25, 2016 @01:32PM (#11977130)
strncpy is strcpy's daft cousin that wastefully writes extra null characters---except when there is no room; then it neglects to null-terminate at all.

strncpy was not needed even in C90, because of sprintf, which is less clumsy to use, doing everything in one step:

  char array[64];
  sprintf(array, "%.63s", some_string);
If we replace the 63 with * , we can pass a dynamic size:

  sprintf(array, "%.*s", (int) sizeof array - 1, some_string);