On Fri, Mar 14, 2014 at 10:35:11PM +0100, Matthias Andree wrote: > I figured that the practical result depends on the compiler. clang on > FreeBSD 9.2 amd64 silently fixes up the b0rked initialization, gcc does > not. Neither complains, though, because the initialization is legal, > and the strncmp() inconsistency shown might be intentional, too. This > is an artificial example anyways and not so useful.
I disagree; the example is, clearly, just an example, but it illustrates real mistakes that real programmers make in real code. A more likely method to make the initialization mistake is to dynamically allocate a buffer, and make an off-by-X error filling it. Or in sizing it in the first place. Happens all the time. I've found a few of those by compiling some code on a different architecture... in several cases it ran fine on 32-bit but crashed immediately on 64. And the second case is pretty obviously dumb, but it also happens to be a bug I fixed in production code in the past... ;-) When you're in a rush, or being careless (or just plain bad at writing code) it's not so hard to make bonehead mistakes. And "safe" functions don't universally safeguard you from that. The point is, using a "safe" function is a poor substitute for paying attention. A bug is a bug, and if you have one, you need to fix it. I dislike those warnings because any half-competent programmer is aware of the *n* versions of functions, and if you chose not to use one there was probably a reason. Please, Mr. Compiler, please stop complaining about something I know is perfectly valid and not broken. More specifically, -Wall should not enable these warnings, you should have to explicitly turn them on separately, IMO. -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02 -=-=-=-=- This message is posted from an invalid address. Replying to it will result in undeliverable mail due to spam prevention. Sorry for the inconvenience.
pgpe9X3as4E14.pgp
Description: PGP signature