Use NULL/'\0' instead of 0; explicitly test for them
This also fixes 2 dereferences after NULL.
MFC after: 3 days
Reported by: Coverity
CID: 1018898, 1018899
Sponsored by: EMC / Isilon Storage Division
Differential D6142
Use NULL/'\0' instead of 0; explicitly test for them ngie on Apr 28 2016, 6:59 PM. Authored by Tags None Referenced Files
Details
Use NULL/'\0' instead of 0; explicitly test for them This also fixes 2 dereferences after NULL. MFC after: 3 days
Diff Detail
Event TimelineComment Actions I'm for NULL instead of 0 as a pointer value, but I don't really understand the need to spell (char)0 as the longer '\0'. Char is just an integer type like short, int, long โ we spell the zero constant for those other integers as just 0. Is that a style(9) suggestion? Looking at style(9), I do see 3 references to using '\0' as a constant. Comment Actions References to '\0' date to r14966, FWIW, as a suggestion to do that instead of treating a char NUL value as an implicit bool false. Comment Actions It's spelled out here implicitly as these aren't boolean types: Do not use ! for tests unless it is a boolean, e.g. use: if (*p == '\0') not: if (!*p) I think style(9) should say "thou shalt always initialize (char)0 as '\0'" (sic). Comment Actions Right, that's the blurb that was added in r14966 I mentioned earlier. I'm not sure the intent is to suggest '\0', though. It's not like libcam is assigning false to a char variable. The value '\0' literally is just a zero with some extra boilerplate. I don't see a big advantage over just using ordinary, unambiguous 0. Comment Actions Yeah... I do '\0' for explicitness so I don't have to go back and figure out what the type is. A lot of the older code (e.g. hexdump) uses 0 instead of '\0'. |