GNOME Bugzilla – Bug 138424
g_ascii_strtod confusion with trailing locale-separator
Last modified: 2011-02-18 16:07:24 UTC
This fails <g transform="matrix(0.05,0.0,0,-0.05,5,60)"> while this works well <g transform="matrix(0.05,0.0,0.0,-0.05,5.0,60.0)"> See attachment for full svg example.
Created attachment 26069 [details] Test case
It seems that i've found the reason. I am running in ru_RU locale, so "5,60"="5.60" For example, this line works fine: <g transform="matrix(0.05,0.0,0,-0.05,5,0,60)"> g_ascii_strtod seems to be locale-specific. It is strange, but appropriate place in glib documentation is pretty unclear. I still can't understand should you use g_ascii_dtostr or g_ascii_strtod.
gosh, this is likely a glib bug, and a big one to boot. we and other projects use g_ascii_strtod() and g_ascii_dtostr() everywhere in our code. g_ascii_strtod() should only work for numbers like "5.0", not "5,0". reassigning
reassigning
The way that g_ascii_strtod works is that it converts the . into the locale especific separator, and then does the conversion. It looks like the problem here is that for numbers without any decimal points, no copy is made, so that the trailing "junk" gets fed right to strtod and confuses it.
Created attachment 26578 [details] [review] Proposed patch
Created attachment 26579 [details] [review] Sorry, something strange with cvs. This is correct patch.
Isn't the documentation for g_ascii_strtod() backwards? Or is the implementation backwards? The doc comment says that it "behaves like the standard strtod() function does in the C locale". Doesn't that mean that it should accept only '.' as decimal separator?
Tor - it's just a bug in the implementation. It does only accept . as a decimal separator, but it gets confused when there is a trailing , in some cases.
Ah yes, now I see. Couldn't think clearly that early in the morning ;-)