--- 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

Reply via email to