In practice (not perfection) cranking the warning level of the compiler up as high as it will go will catch most things that lint will. Hence the habit of initializing all variables. As to catching typos.... well, I can understand your point.
The only reason I initialized the buffer in the original post was to use strcat repeatedly in a loop. For Sale: Nice Parachute, Used Once, Never Opened, Slightly Stained Michael Comperchio [email protected] On Mar 6, 2009, at 8:23 AM, John Matthews wrote: > --- In [email protected], Michael Comperchio <mcmp...@...> wrote: > > > > anyway, 'tis better to be zeroed and sure, than to never > > have zeroed at all..... > > Michael- I agree that defensive programming is A Good Idea, but in > general I don't think initialising things 'just in case' is the best > approach. In fact, it can be a hindrance to real bug detection by > tools such as PC-lint eg. a simple case: > > int *p = NULL, *q = NULL; /* safety (redundant) initialisation */ > > p = getPtr(); > > if (q) /* bug - should be testing p */ > doSomething(); > > Lint won't detect that the test of q is a bug because it has been > initialised, whereas if it wasn't, it would correctly report use of an > uninitialised variable. > > In the OP's code, what is it that clearing the buffer achieves? I > think you have to spend a bit of time analysing what might go wrong, > and then take precautions. For example, there is no check for writing > beyond the end of the buffer - that's an obvious logic bug that should > be fixed first. > > John > >
