mailing list of musl libc
 help / color / mirror / code / Atom feed
* strftime sets errno to 22
@ 2016-07-24  1:17 Alba Pompeo
  2016-07-24  1:47 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Alba Pompeo @ 2016-07-24  1:17 UTC (permalink / raw)
  To: musl

Hello musl people.

I was reading some commits messages from a project and ended up seeing
something that might be interesting to you.

https://github.com/izabera/inutility/commit/1db3ba948ad1d4cbfa8c0164fa475439c99c06bc

I don't think it's been reported yet.

Ciao,
Alba Pompeo


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

* Re: strftime sets errno to 22
  2016-07-24  1:17 strftime sets errno to 22 Alba Pompeo
@ 2016-07-24  1:47 ` Rich Felker
  2016-07-24  6:59   ` Alexander Monakov
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Felker @ 2016-07-24  1:47 UTC (permalink / raw)
  To: musl

On Sat, Jul 23, 2016 at 10:17:30PM -0300, Alba Pompeo wrote:
> Hello musl people.
> 
> I was reading some commits messages from a project and ended up seeing
> something that might be interesting to you.
> 
> https://github.com/izabera/inutility/commit/1db3ba948ad1d4cbfa8c0164fa475439c99c06bc
> 
> I don't think it's been reported yet.

Except for a few special functions with more restrictive
specification, you can only expect errno to contain something
meaningful immediately after a function returns with a return value
indicating an error. The code above was assuming that errno being set
indicated an error even when strftime succeeded.

With that said, at the time this was reported on IRC I looked for the
cause of errno being set to EINVAL and didn't see it. It might be nice
to know why it's happening, just in case some unintended code paths
with nontrivial cost are getting pulled in.

Rich


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

* Re: strftime sets errno to 22
  2016-07-24  1:47 ` Rich Felker
@ 2016-07-24  6:59   ` Alexander Monakov
  2016-07-24 15:34     ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Monakov @ 2016-07-24  6:59 UTC (permalink / raw)
  To: musl

On Sat, 23 Jul 2016, Rich Felker wrote:
> With that said, at the time this was reported on IRC I looked for the
> cause of errno being set to EINVAL and didn't see it. It might be nice
> to know why it's happening, just in case some unintended code paths
> with nontrivial cost are getting pulled in.

nsz mentioned on irc it's from strtoul call (when no digits are seen).

Alexander


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

* Re: strftime sets errno to 22
  2016-07-24  6:59   ` Alexander Monakov
@ 2016-07-24 15:34     ` Rich Felker
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2016-07-24 15:34 UTC (permalink / raw)
  To: musl

On Sun, Jul 24, 2016 at 09:59:26AM +0300, Alexander Monakov wrote:
> On Sat, 23 Jul 2016, Rich Felker wrote:
> > With that said, at the time this was reported on IRC I looked for the
> > cause of errno being set to EINVAL and didn't see it. It might be nice
> > to know why it's happening, just in case some unintended code paths
> > with nontrivial cost are getting pulled in.
> 
> nsz mentioned on irc it's from strtoul call (when no digits are seen).

It looks like this is something that should be fixed, just because
calling strtoul without checking isdigit allows invalid formats to be
accepted (strtoul consumes leading whitespace and signs, both of which
are unwatned). Probably we want:

-		width = strtoul(f, &p, 10);
+		width = isdigit(*f) ? strtoul(f, &p, 10) : 0;

Thoughts?

Rich


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

end of thread, other threads:[~2016-07-24 15:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-24  1:17 strftime sets errno to 22 Alba Pompeo
2016-07-24  1:47 ` Rich Felker
2016-07-24  6:59   ` Alexander Monakov
2016-07-24 15:34     ` 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).