From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 104A53858D28; Mon, 17 Jul 2023 15:30:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 104A53858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689607807; bh=qldE8N7GkrMe9O26NFf+1RowLHYAwxeVBzaCG0KqeZM=; h=From:To:Subject:Date:From; b=lILcAa8Y4nd7PUhBFsrl+BZKNhuZ5Esuss26FP7jHaP47/5S+cmzWRHvtdaVQlbkA R/o/1m6aB5OuX7x4wxjLgvXMyyakhCKRZcehrejvMabrfIeVQtLnQLDy618sb4Vt7L HNi5MDIQhn20U2fpSbxp8NPzCFsAbtuzBae+3sqE= From: "vincent-srcware at vinc17 dot net" To: glibc-bugs@sourceware.org Subject: [Bug stdio/30647] New: scanf functions wrong on nan() Date: Mon, 17 Jul 2023 15:30:06 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: stdio X-Bugzilla-Version: 2.37 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-srcware at vinc17 dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30647 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 j= ust "nan". Note that strtod is correct, i.e. it takes the parentheses into acco= unt. Consider the following testcase: #include #include static void test_strtod (const char *s) { char *endptr; double d; printf ("strtod test on %s\n", s); d =3D strtod (s, &endptr); printf ("d =3D %g \"%s\"\n", d, endptr); } int main (void) { int r; double a, b, c; test_strtod ("nan*"); test_strtod ("nan()*"); r =3D sscanf ("nan nan() 1", "%lf%lf%lf", &a, &b, &c); printf ("sscanf return value: %d\n", r); if (r >=3D 1) printf ("a =3D %g\n", a); if (r >=3D 2) printf ("b =3D %g\n", b); if (r >=3D 3) printf ("c =3D %g\n", c); r =3D fscanf (stdin, "%lf%lf%lf", &a, &b, &c); printf ("fscanf return value: %d\n", r); if (r >=3D 1) printf ("a =3D %g\n", a); if (r >=3D 2) printf ("b =3D %g\n", b); if (r >=3D 3) printf ("c =3D %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 =3D nan "*" strtod test on nan()* d =3D nan "*" sscanf return value: 2 a =3D nan b =3D nan fscanf return value: 2 a =3D nan b =3D nan instead of strtod test on nan* d =3D nan "*" strtod test on nan()* d =3D nan "*" sscanf return value: 3 a =3D nan b =3D nan c =3D 1 fscanf return value: 3 a =3D nan b =3D nan c =3D 1 (as obtained with MacOS X 12.6 and Android 13). --=20 You are receiving this mail because: You are on the CC list for the bug.=