mailing list of musl libc
 help / color / mirror / code / Atom feed
* behavior errata
@ 2017-02-11 23:28 lists
  2017-02-12  0:02 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: lists @ 2017-02-11 23:28 UTC (permalink / raw)
  To: musl

While debugging an issue where a child process’s errno was getting clobbered, discovered that musl was doing the clobbering in a call to strftime (that did NOT fail).

I understand the contract of libc calls is that errno can be clobbered at any time. However, it’s a behavior difference between musl and other libc’s that I have tested against. 

Here’s the repro code. 

https://gist.github.com/chuckremes/698b0ee5d1279374cb1ef3add82a6f18

I had a nice chat with some folks on IRC about this. They indicated that it might get “fixed” just to be nice but there is no requirement to do so. Someone even made the (evil but funny) suggestion that musl should clobber errno between every non-failing call just to see how much code in the wild would explode. Please don’t. :)

Thanks for your attention.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: behavior errata
  2017-02-11 23:28 behavior errata lists
@ 2017-02-12  0:02 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2017-02-12  0:02 UTC (permalink / raw)
  To: musl

On Sat, Feb 11, 2017 at 05:28:37PM -0600, lists@chuckremes.com wrote:
> While debugging an issue where a child process’s errno was getting
> clobbered, discovered that musl was doing the clobbering in a call
> to strftime (that did NOT fail).
> 
> I understand the contract of libc calls is that errno can be
> clobbered at any time. However, it’s a behavior difference between
> musl and other libc’s that I have tested against.
> 
> Here’s the repro code. 
> 
> https://gist.github.com/chuckremes/698b0ee5d1279374cb1ef3add82a6f18
> 
> I had a nice chat with some folks on IRC about this. They indicated
> that it might get “fixed” just to be nice but there is no
> requirement to do so. Someone even made the (evil but funny)
> suggestion that musl should clobber errno between every non-failing
> call just to see how much code in the wild would explode. Please
> don’t. :)
> 
> Thanks for your attention.

Hi. Indeed, errno is only meaningful after a function that returns an
error and sets it. Most other functions, except a few explicitly
specified not to, can clobber errno with any nonzero value.

While the above behavior might change (especially if it's found that
we're doing a wasteful operation that's causing errno to be set), musl
will never guarantee non-clobbering of errno in cases where it's
allowed to be clobbered, so programs that wrongly depend on that might
break again in the future if something changes again. You really just
need to fix the code that's wrongly relying on errno being preserved
on success. Only check errno when an error is returned.

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-12  0:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-11 23:28 behavior errata lists
2017-02-12  0:02 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).