After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 720594 - gda_numeric_get_double()'s use of atof() is locale-dependent
gda_numeric_get_double()'s use of atof() is locale-dependent
Status: RESOLVED FIXED
Product: libgda
Classification: Other
Component: general
5.2.x
Other Linux
: Normal normal
: ---
Assigned To: malerba
gnome-db Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-12-17 09:24 UTC by Murray Cumming
Modified: 2014-04-27 14:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test_libgda_numeric.cc (1.11 KB, text/x-c++src)
2013-12-17 09:24 UTC, Murray Cumming
  Details
test_libgda_numeric.c (584 bytes, text/x-csrc)
2013-12-17 09:25 UTC, Murray Cumming
  Details
0001-GdaNumeric-Use-g_ascii_strtod-instead-of-atof.patch (1.34 KB, patch)
2013-12-17 09:26 UTC, Murray Cumming
none Details | Review
0001-GdaNumeric-Use-g_ascii_dtostr-instead-of-g_strdup_pr.patch (1.62 KB, patch)
2013-12-17 09:45 UTC, Murray Cumming
none Details | Review
0001-Replace-more-uses-of-atof-with-g_ascii_strtod.patch (4.95 KB, patch)
2013-12-18 09:48 UTC, Murray Cumming
none Details | Review

Description Murray Cumming 2013-12-17 09:24:53 UTC
Created attachment 264397 [details]
test_libgda_numeric.cc

This test case shows that gda_numeric_get_double() returns the incorrect value if we first call std::locale::global() (in C++).
Comment 1 Murray Cumming 2013-12-17 09:25:42 UTC
Created attachment 264398 [details]
test_libgda_numeric.c

It's interesting that, as in this test case, just calling setlocale() does not cause this problem.
Comment 2 Murray Cumming 2013-12-17 09:26:28 UTC
Created attachment 264399 [details] [review]
0001-GdaNumeric-Use-g_ascii_strtod-instead-of-atof.patch

This patch fixes the problem.
Comment 3 Murray Cumming 2013-12-17 09:45:40 UTC
Created attachment 264400 [details] [review]
0001-GdaNumeric-Use-g_ascii_dtostr-instead-of-g_strdup_pr.patch

And this patch avoids some more use of setlocale(), though they are not causing any known bugs, but g_ascii_dtostr() seems cleaner.
Comment 4 Murray Cumming 2013-12-17 18:24:43 UTC
(In reply to comment #0)
> Created an attachment (id=264397) [details]
> test_libgda_numeric.cc
> 
> This test case shows that gda_numeric_get_double() returns the incorrect value
> if we first call std::locale::global() (in C++).

Of course, this only fails if you are using a non-English locale, such as my German locale that uses , instead of . for decimal points.
Comment 5 Murray Cumming 2013-12-18 09:48:36 UTC
Created attachment 264468 [details] [review]
0001-Replace-more-uses-of-atof-with-g_ascii_strtod.patch

While I'm at it, here is another patch to avoid some more uses of atof() elsewhere in libgda. But you should check that each of these is really not meant to be locale-dependent.
Comment 6 malerba 2013-12-19 22:06:26 UTC
I though this was corrected with the gda_locale_changed() function... I'll have a look ASAP at your patches.
Comment 7 malerba 2013-12-20 18:34:28 UTC
I've corrected, for now without your patches the problem, see commit https://git.gnome.org/browse/libgda/commit/?id=b85faf3eacd4bf8ce182938fbfd0b89dab5ac6a8

I'll use you patches to avoid having to change the locale which is not thread safe.
Comment 8 Murray Cumming 2013-12-20 20:01:01 UTC
Thanks. When you are ready, it would be great to have a release to depend on for this fix.
Comment 9 Murray Cumming 2014-04-27 14:18:45 UTC
I think we forgot to mark this bug as fixed.