svn commit: r235266 - head/lib/libc/stdlib

Andrey Chernov ache at FreeBSD.ORG
Fri May 11 17:56:26 UTC 2012


On Fri, May 11, 2012 at 08:04:12PM +0300, Konstantin Belousov wrote:
> On Fri, May 11, 2012 at 06:54:32PM +0400, Andrey Chernov wrote:
> > Thanks, but in this two places old errno value should be saved across
> > free() because free() may damage it:
> I do not agree. free() cannot change errno.

Perhaps I forget something, so please refer to standard stating that.

IEEE Std 1003.1-2008 says that "No errors are defined." in the ERRORS 
section, but states that beforehand:

"if the argument does not match a pointer earlier returned by a function 
in POSIX.1-2008 that allocates memory as if by malloc(), or if the space has 
been deallocated by a call to free() or realloc(), the behavior is 
undefined.

Any use of a pointer that refers to freed space results in undefined 
behavior.

...

The DESCRIPTION is updated to clarify that if the pointer returned is not 
by a function that allocates memory as if by malloc(), then the behavior 
is undefined."

So that "undefined behavior" case still can modify errno.

(Some internal syscalls (like munmap etc) could produce errno. In any 
case it is very implemetation defined.)

-- 
http://ache.vniz.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20120511/66f23c26/attachment.pgp


More information about the svn-src-head mailing list