News for hackers. Stuff that matters.

dibbit

Re:Stop using strncpy already on Thursday April 04, 2013 @07:39AM (#5492061)
Maybe, but it will catch bugs like this if the test is written for it, and anyone writing C in the 21st century professionally, with safety in mind, is a) writing tests, and b) getting 100% coverage.
Re:Stop using strncpy already on Thursday April 04, 2013 @07:37AM (#5492051)
It made sense when portability from C to C++ was important, as in now and for as long as both languages have constancy.
Re:Stop using strncpy already on Thursday April 04, 2013 @07:36AM (#5492044)
Run the code and see for yourself, parent fixed it.
Re:Stop using strncpy already on Thursday April 04, 2013 @07:35AM (#5492042)
It does matter. sizeof is computed at compile time, it is not computed at runtime. something() is a runtime invocation .. sizeof() 'looks' like that, but isn't.
Re:Stop using strncpy already on Thursday April 04, 2013 @07:34AM (#5492035)
There actually is a good reason not to use parens with sizeof, and it is in fact a means of introducing subtle bugs to your code if you don't know the difference:

    sizeof some_struct; //computed at *compile* time
    sizeof(some_struct); // also computed at *compile* time, but looks like its a runtime call
Anything that looks like something but isn't actually that thing, in my opinion - especially with a language like C - is room for programmer enlightement ..