Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: malloc() does not set errno

From: Michael Marking <marking(at)tatanka.com>
Date: Wed Jul 09 2003 - 16:50:28 EDT

> > Todd.Miller> malloc() uses brk(2) to allocate memory which does set errno.
> >
> > If the invalid argument (e.g. negative) is passed, malloc() does
> > not use brk(2) and returns NULL. I'm not familiar with the
> > related standards, but shouldn't errno be set to ENOMEM in such case?
>
> EINVAL I'd hope.

according to the C99 standard:

	malloc() is passed a size_t, which is unsigned, so there
	can be no negative values (if you pass a signed value, it
	will cast to unsigned, so it will be a very large positive
	value on most architectures)

	the use of errno with malloc is not documented in the
	standard

	the standard says (in 7.5), "The value of errno may be set
	to nonzero by a library function call whether or not there
	is an error, provided the use of errno is not documented in
	the description of the function in this International
	Standard" (!)

it appears there are no issues of standards compliance, at least; the implementation is free to do with errno as it pleases Received on Wed Jul 9 17:10:57 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:48:42 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library