News for hackers. Stuff that matters.
Re:Stop using strncpy already (2013) by needlepont on Friday August 31, 2018 @10:48AM (#17885998)
Of course, but everyone wants to overdo the complexity of the time worn solution. OMG you need to null terminate the string after all the _other_ gymnastics..gee C sure does suck! Why don't we use rust|go|c++ ad-nauseam. bzero(buf,sz); /memset nazis here/ strncpy(buf,src,sz - 1);
Re:Stop using strncpy already (2013) by bitwize on Friday August 31, 2018 @12:20PM (#17886779)
It doesn't make sense to have to null-terminate the string by hand (maybe) after doing a "safe" STRING copy. Which means it's easy to forget to do and that's a dangerous wart in the design.

Really, stop using C. To quote Hayao Miyazaki, C was a mistake.

[dead]
Re:Stop using strncpy already (2013) by dang on Monday September 03, 2018 @08:47PM (#17905812)
Posting like this will get you banned here. Please review and follow the rules: https://news.ycombinator.com/newsguidelines.html.
Re:Stop using strncpy already (2013) by hzhou321 on Friday August 31, 2018 @01:55PM (#17887567)
What I meant is more like:

    #define BUFSIZE 100
    char buf[BUFSIZE+1]
    buf[BUFSIZE]=0 // for global var, it is already zeroed, right?
Then one can call strncpy(buf, BUFSIZE, ...) without worrying about null-termination.