public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/30647] New: scanf functions wrong on nan()
@ 2023-07-17 15:30 vincent-srcware at vinc17 dot net
2023-07-18 11:55 ` [Bug stdio/30647] " vincent-srcware at vinc17 dot net
2024-04-30 16:42 ` carlos at redhat dot com
0 siblings, 2 replies; 3+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-07-17 15:30 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30647
Bug ID: 30647
Summary: scanf functions wrong on nan()
Product: glibc
Version: 2.37
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: stdio
Assignee: unassigned at sourceware dot org
Reporter: vincent-srcware at vinc17 dot net
Target Milestone: ---
On a string input containing "nan()" with parentheses (possibly with
n-char-sequence), the scanf functions assume that the subject sequence is just
"nan". Note that strtod is correct, i.e. it takes the parentheses into account.
Consider the following testcase:
#include <stdio.h>
#include <stdlib.h>
static void test_strtod (const char *s)
{
char *endptr;
double d;
printf ("strtod test on %s\n", s);
d = strtod (s, &endptr);
printf ("d = %g \"%s\"\n", d, endptr);
}
int main (void)
{
int r;
double a, b, c;
test_strtod ("nan*");
test_strtod ("nan()*");
r = sscanf ("nan nan() 1", "%lf%lf%lf", &a, &b, &c);
printf ("sscanf return value: %d\n", r);
if (r >= 1)
printf ("a = %g\n", a);
if (r >= 2)
printf ("b = %g\n", b);
if (r >= 3)
printf ("c = %g\n", c);
r = fscanf (stdin, "%lf%lf%lf", &a, &b, &c);
printf ("fscanf return value: %d\n", r);
if (r >= 1)
printf ("a = %g\n", a);
if (r >= 2)
printf ("b = %g\n", b);
if (r >= 3)
printf ("c = %g\n", c);
return 0;
}
I get the following output with GNU libc 2.31 and 2.37 on Debian:
$ printf "nan nan() 1" | ./naninput
strtod test on nan*
d = nan "*"
strtod test on nan()*
d = nan "*"
sscanf return value: 2
a = nan
b = nan
fscanf return value: 2
a = nan
b = nan
instead of
strtod test on nan*
d = nan "*"
strtod test on nan()*
d = nan "*"
sscanf return value: 3
a = nan
b = nan
c = 1
fscanf return value: 3
a = nan
b = nan
c = 1
(as obtained with MacOS X 12.6 and Android 13).
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug stdio/30647] scanf functions wrong on nan()
2023-07-17 15:30 [Bug stdio/30647] New: scanf functions wrong on nan() vincent-srcware at vinc17 dot net
@ 2023-07-18 11:55 ` vincent-srcware at vinc17 dot net
2024-04-30 16:42 ` carlos at redhat dot com
1 sibling, 0 replies; 3+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-07-18 11:55 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30647
--- Comment #1 from Vincent Lefèvre <vincent-srcware at vinc17 dot net> ---
Note that if the string starts with "nan(" but does not match
nan(n-char-sequence_opt), then scanf must reject the conversion (after reading
the longest prefix).
Examples:
* "nan(foo" (no closing parenthesis)
* "nan(a b)" (the space is not valid in n-char-sequence)
Currently it doesn't, because it stops at "nan" (it does not read the longest
prefix). These cases are similar to issues mentioned in bug 12701, but
currently this is not the same bug.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug stdio/30647] scanf functions wrong on nan()
2023-07-17 15:30 [Bug stdio/30647] New: scanf functions wrong on nan() vincent-srcware at vinc17 dot net
2023-07-18 11:55 ` [Bug stdio/30647] " vincent-srcware at vinc17 dot net
@ 2024-04-30 16:42 ` carlos at redhat dot com
1 sibling, 0 replies; 3+ messages in thread
From: carlos at redhat dot com @ 2024-04-30 16:42 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30647
Carlos O'Donell <carlos at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |carlos at redhat dot com
Ever confirmed|0 |1
Last reconfirmed| |2024-04-30
Status|UNCONFIRMED |NEW
--- Comment #2 from Carlos O'Donell <carlos at redhat dot com> ---
I agree this does look like a conformance issue with the scanf family of
functions using __vfscanf_internal() implemetnation.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-30 16:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-17 15:30 [Bug stdio/30647] New: scanf functions wrong on nan() vincent-srcware at vinc17 dot net
2023-07-18 11:55 ` [Bug stdio/30647] " vincent-srcware at vinc17 dot net
2024-04-30 16:42 ` carlos at redhat dot com
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 read-only IMAP folder(s) and NNTP newsgroup(s).