From: "(GalaxyMaster)" <galaxy@openwall.com.au>
To: musl@lists.openwall.com
Subject: [musl] strtoll() incompatibility
Date: Wed, 13 Oct 2021 14:06:27 +0000 [thread overview]
Message-ID: <0100017c79f9d219-86b8d3e7-358a-473c-9736-befc0678d7c7-000000@email.amazonses.com> (raw)
Hello,
I am not a true developer, so I don't have the POSIX standard handy, hence could
not quickly find whether the observed behaviour is correct or not. I have two
systems, one is musl-based and the other is Glibc-based, so every time I stumble
upon something I check against Glibc. I know that Glibc developers did quite a
few bespoke things, but this particular one made me wonder whether it is a bug
in musl.
Longs story short, it seems that musl's strto*() set errno when it is unable
to find a legitimate number at the begining of the string:
===
galaxy@musl:~/musl-tests $ cat strtoll.c
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <errno.h>
int main() {
char *endptr, *str=" .25g ";
long long val;
errno = 0;
val = strtoll(str, &endptr, 10);
if (errno != 0) {
perror("strtol");
return 1;
}
if (endptr == str) {
fprintf(stderr, "No digits were found\n");
return 1;
}
printf("strtoll() returned %lld\n", val);
if (*endptr != '\0') /* Not necessarily an error... */
printf("Further characters after number: \"%s\"\n", endptr);
return 0;
}
galaxy@musl:~/musl-tests $ gcc -o strtoll strtoll.c
galaxy@musl:~/musl-tests $ ./strtoll
strtol: Invalid argument
galaxy@musl:~/musl-tests $
===
The output was from perror(), which indicates that the parsing produced an
error. You can actually see how the parsing is done in src/stdlib/strtol.c.
At the same time the same code produces the following on a Glibc system:
===
[galaxy@archlinux musl-tests]$ ./strtoll
No digits were found
[galaxy@archlinux musl-tests]$
===
Which basically tells me that Glibc's strtoll() did not set errno.
I don't know what the standard prescribes for this family of functions (I just
registered an account at Open Group to download the standard), but from the
common sense point of view a string not containing a number for these functions
is a valid argument, so responding with EINVAL does not seems to be right.
--
(GM)
next reply other threads:[~2021-10-13 14:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 14:06 (GalaxyMaster) [this message]
2021-10-13 14:22 ` Shiz
2021-10-13 14:58 ` (GalaxyMaster)
2021-10-13 14:28 ` Jₑₙₛ Gustedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0100017c79f9d219-86b8d3e7-358a-473c-9736-befc0678d7c7-000000@email.amazonses.com \
--to=galaxy@openwall.com.au \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).