Re: errno in debug vs. release
Re: errno in debug vs. release
- Subject: Re: errno in debug vs. release
- From: "Justin C. Walker" <email@hidden>
- Date: Tue, 7 Feb 2006 17:38:22 -0800
On Feb 7, 2006, at 14:10 , John W Noerenberg II wrote:
At 12:52 PM -0800 2/7/06, Eric Albert wrote:
free(3) is not documented to set errno, so there's no guarantee
that errno is actually set at this point in your code. Given
that, you're probably getting a random value for errno. I'd
suggest changing your code to only read errno after making
function calls that are documented as setting it.
You're right about free. But malloc *is* supposed to set errno* if
the size argument equals zero. Also note that even though errno is
set for the debug version, malloc still returns the address of the
heap. So this is a definitely a problem.
*From the malloc man page:
The malloc() function allocates size bytes of memory and
returns a
pointer to the allocated memory. malloc() returns a NULL
pointer if
there is an error.
This snippet does not say that malloc() will set errno on an error,
and there is no mention of errno in the man page. Errno is generally
set by system calls (which malloc isn't). The man pages will
indicate errno values for specific errors, and what indicates that
you should check errno.
To check errno in other situations gives undefined results
(generally, nothing in the system will clear errno; it's only (re)set
on specified errors).
Regards,
Justin
--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Enhancement of the Director's Income
--------
Experience is what you get
when you don't get what you want.
--------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden