In comp.lang.c muister said:
Hi, I am getting an error (errno EOVERFLOW) from a rather small
malloc:
htbl->table = (List *)malloc(15 * sizeof(List))
where sizeof(List) = 20. htbl->table is a (List *). If I lowered the
'15' to '11', everything works. I am running in a cygwin environment
(with over 200 MB ram free).
First of all, malloc() isn't required to set errno as far as I can
see from C standard (and EOVERFLOW isn't even mentioned). On some
systems (POSIX comes to mind and it's probably save to assume that
cygwin falls under that category) errno gets set to ENOMEM, but not
to EOVERFLOW (that would indicate that you tried to assign a value
to a type that is not large enough to store it). It's also im-
portant to know that no function is allowed to set errno to zero,
so typically it only gets changed in case of failure.
Without more information I can only gues that one of the following
three alternatives leads to your problem:
- malloc() returned a non-NULL value but you don't check that and
only look at errno (but which in case of success doesn't tell
you anything because errno is still set to the value it had be-
fore the call)
- on your implementation malloc() does not set errno on failure
(since that doesn't convey additional information anyway)
- htbl->table isn't really a List pointer but something not wide
enough to store the return value of malloc() (which might ex-
plain the EOVERFLOW value of errno).
Regards, Jens