C
CBFalconer
pete said:CBFalconer wrote:
.... snip ...
Then why don't you make it
if (!n || ((size_t)-1) / n >= s)
instead?
I haven't thought it through, but I think there are cases involving
the truncation effects of the division where the == condition may
or may not be an error. The actual needs of malloc in terms of
alignment and tracking overhead are not generally known outside of
the malloc code proper. This is one more reason for putting calloc
in the malloc module. We can afford the extra overhead of a
thorough check there because there is all that overhead of doing
the memset anyhow, and the detailed needs of malloc are known.
When I thrash this out I will update my published nmalloc issue.
Meanwhile this constitutes a warning to users of the above code. I
think it is fine for the actual limits used in nmalloc on DJGPP,
but it affects the portability of that code. It is another hidden
assumption, to be either avoided or documented.