Bug 83676 - Problems with sscanf parsing hex-floats
Summary: Problems with sscanf parsing hex-floats
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 7.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-03 22:18 UTC by Moritz K.
Modified: 2018-01-04 10:07 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
example code, visualizing the behavior from above (157 bytes, text/plain)
2018-01-03 22:18 UTC, Moritz K.
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Moritz K. 2018-01-03 22:18:02 UTC
Created attachment 43023 [details]
example code, visualizing the behavior from above

Assume `d` as a normal double variable.
Executing
`sscanf ( "0x", "%lf", &d )`
returns `0` and `d` isn't modified, 'cause the string can't be parsed.
I think that 0x indicates in correspondence with `%lf`, that there seem to be a maybe slightly incomplete hex-float.

But wouldn't it be a better behavior if this statement is correctly parsed into the double `d` with the value `0`, 'cause ignoring the `x` and correctly parsing `0` as well as assuming that `0x` originally means `0x0` is a much more thought-out behavior than just saying "sry, but this can't be parsed, so it's better doing nothing"?
Even though `sscanf ( "0x", "%i", &i )` returns successfully `1` and the integer value `i` is going to have the value `0`. Furthermore e.g. BSD' versions of GCC correctly parses the 0x-lf case...

I'm using a x86_64-pc-linux-gnu 4.14.9-Linux to compile the code without any significant options (no compiler warnings present).
Thanks!
Comment 1 Andrew Pinski 2018-01-03 22:59:47 UTC
GCC does not provide the sscanf here, glibc does.  Please report it to them: http://sourceware.org/bugzilla/ if you think this is a bug.
Comment 2 Moritz K. 2018-01-04 10:07:43 UTC
Okay, I didn't know that.