News for hackers. Stuff that matters.
Re:Improvements to static analysis in GCC 14 by spacechild1 on Wednesday April 03, 2024 @01:28PM (#39920378)
As others have already pointed out it, it doesn't guarantee that the result is null-terminated. But that's not the only problem! In addition, it always pads the remaining space with zeros:

    char buf[1000];
    strncpy(buf, "foo", sizeof(buf));
This writes 3 characters and 9997 zeros. It's probably not what you want 99% of the time.

There are no comments on this comment yet.