[EMAIL PROTECTED] on 05/03/2000 03:08:30 AM
>If code were written perfectly, we wouldn't have wild-pointer bugs and
>these techniques would be unnecessary, but in the real world, we all see
>wild-pointer errors and these ideas (adapted from Robert Ward's old (out of
>print, alas!) book, "Debugging C") have served me quite well for many years.

Hopefully, many eyes will tend to spot wild-pointer errors.

>As to non-portability, this code compiles without errors or warnings with
>strict ANSI compiler switches.

I think the term portability meant that the software should act the same on all
platforms.  In this respect, your solution (of writing specified garbage (ie
sentinels)) would be more portable than zeroing out the memory.  But then again,
due to the differences in padding and address size and such, it could, in fact,
be less portable.

>As to the question of requests to allocate zero bytes, I would consider
>those to be domain errors. A well-written program should not ask for
>allocations of zero bytes. Following this line, I would write xmalloc to
>consider such a request erroneous, and to generate a run-time error.
>
>However, comments in the xmalloc code in CVS note that some places allocate
>zero-byte blocks and free them. I grepped the code for "alloc *( *0" and
>turned up nothing, so could someone clue me in on:
>* Where zero-byte requests are made,
>* Whether this represents good coding or sloppy coding,
>* and Whether such requests should be considered bugs to be fixed?

The occasion I've had for requesting zero-byte allocations have been when
writing generic array structures that allows for zero elements.  Much of the
algorithms were very much simplified if zero-byte allocations were allowed (and
returned NULL).  Our existing malloc() wrapper spits out warnings upon requests
of zero bytes.  Our solution was to write a new wrapper.  Those that knew
zero-byte allocations were "bad" called the original wrapper, otherwise, they'd
call the new one.

I haven't run into any zero-byte allocation requests in CVS, but a simple grep
will not turn them up if the zero happened to be a value of a variable (like in
my situation).

Noel




This communication is for informational purposes only.  It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction, unless specifically agreed
otherwise. All market prices, data and other information are not warranted as
to completeness or accuracy and is subject to change without notice. Any
comments or statements made herein do not necessarily reflect those of
J.P. Morgan & Co. Incorporated, its subsidiaries and affiliates.

Reply via email to