Safe coding practices

Doug Gwyn gwyn at smoke.brl.mil
Fri Feb 1 04:45:48 AEST 1991


In article <1074 at mwtech.UUCP> martin at mwtech.UUCP (Martin Weitzel) writes:
>In article <14970 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>>In Standard C realloc() is required to be safe.  Of course it may return
>>NULL even if you're attempting to shrink the allocation, although it is
>      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>unlikely that an implementation would be so deficient.
>YES! An important point and I wouldn't even say that an implementation
>is necessarily "deficient" if this happens.

While I generally agree with your comments, the reason I would think
that such an implementation was unnecessarily deficient is that the
C standard requires that, in cases where realloc() reports failure,
the original data be left unchanged at the same, still validly
allocated, location.  (Not exact wording, but that's the meaning.)
Therefore realloc() COULD simply return the first argument pointer
in that case; nothing is actually gained by it returning NULL.



More information about the Comp.bugs.4bsd.ucb-fixes mailing list