Opened 7 years ago
Closed 7 years ago
#13949 closed bug (fixed)
strtod() should only advance *endptr one byte given "0x"
Reported by: | i80and | Owned by: | nobody |
---|---|---|---|
Priority: | low | Milestone: | Unscheduled |
Component: | System | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
#include <stdio.h> #include <stdlib.h> int main(void) { const char* str = "0x"; char* endp; strtod(str, &endp); printf("%ld\n", endp - str); }
On other platforms, this will print 1
. On Haiku, it prints 2
.
From http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtod.html:
The expected form of the subject sequence is an optional '+' or '-' sign, then one of the following: ...
- A 0x or 0X, then a non-empty sequence of hexadecimal digits...
Other platforms do not advance *endptr
to indicate that the 'x' was consumed, which seems like preferable behavior because it lets the caller know that the input string was odd.
Attachments (1)
Change History (6)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Also, is this how upstream glibc solved the problem? If so, could you link to their fix commit?
comment:3 by , 7 years ago
This is not even close to how upstream glibc works. Unfortunately, they've diverged significantly from what exists in the haiku tree.
Would it be better to try and sync the implementation with upstream?
by , 7 years ago
Attachment: | 0001-strtod-Do-not-consume-x-in-incomplete-hex-input.patch added |
---|
comment:4 by , 7 years ago
Made a new patch, using the following two diffs from upstream glibc:
- https://sourceware.org/git/?p=glibc.git;a=commit;h=405698e9
- https://sourceware.org/git/?p=glibc.git;a=commit;h=43b9d65
I'll try to figure out Gerrit
comment:5 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Merged patch from Gerrit. Thanks!
We haven't updated the Contributing guide just yet, but we have a Gerrit instance live at https://review.haiku-os.org -- so if you could submit your patch there, that would be best.