Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: malloc setting errno even if fine



On Mar 21, 2011, at 10:27 39AM, Thomas Klausner wrote:

> Hi!
> 
> I've been debugging a program and found that malloc changes errno even
> when it's not reporting an error in the end. In my case, fseeko
> returned no error, but still errno was set.
> 
> ...
> 
> I think this is a bug. Should I file a bug report, or is this not a
> bug for some reason?
> Thomas
> 

That behavior is explicitly permitted; see errno(2):

     It should only be examined after an error
     has been reported, because otherwise a leftover value from some previous
     error may be found instead.  (Many library functions that are not system
     calls also set errno on return, in the same fashion.  In these cases a
     nonzero value may be left in errno even upon successful return if some
     internal action failed.)

                --Steve Bellovin, http://www.cs.columbia.edu/~smb







Home | Main Index | Thread Index | Old Index