Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cs2cs_emulation_setup: fix issue with non C-locale #1136

Merged

Conversation

rouault
Copy link
Member

@rouault rouault commented Sep 27, 2018

in +towgs84 case, we use sprintf() with floating-point formatter to output
the ellipsoid parameters. For a locale with decimal separtor != dot, the
resulting string will not be parsed correctly by proj_atof(), leading to
wrong numeric result.

The fix is similar to the one done in pj_latlong_from_proj()

Note for later: if using C++, we could use a locale-independent formatting
solution to avoid such issue.

@@ -519,6 +519,19 @@ Returns 1 on success, 0 on failure
if (P->is_geocent || P->helmert || do_cart) {
char def[150];
sprintf (def, "break_cs2cs_recursion proj=cart a=%40.20g es=%40.20g", P->a_orig, P->es_orig);
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is stylistically quite different from its surroundings. I would prefer something like this (untested):

if (P->is_geocent || P->helmert || do_cart) {
    char def[150];
    char *next_pos = def;

    sprintf (def, "break_cs2cs_recursion     proj=cart   a=%40.20g  es=%40.20g", P->a_orig, P->es_orig);

    /* In case the current locale does not use dot but comma as decimal */
    /* separator, replace it with dot, so that proj_atof() behaves */
    /* correctly. */
    /* TODO later: use C++ ostringstream with imbue(std::locale::classic()) */
    /* to be locale unaware */
    while ( (next_pos =  strchr (next_pos, ',')))
        *next_pos++ = '.';

    ...

or even a for rather than while:

for (next_pos = def; next_pos = strchr (next_pos, ','); next_pos++)
    *next_pos = '.'

Alternatively, we could build comma-dot agnosticism into the alternative proj_strtod in proj_strtod.c

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, taken into account

in +towgs84 case, we use sprintf() with floating-point formatter to output
the ellipsoid parameters. For a locale with decimal separtor != dot, the
resulting string will not be parsed correctly by proj_atof(), leading to
wrong numeric result.

The fix is similar to the one done in pj_latlong_from_proj()

Note for later: if using C++, we could use a locale-independent formatting
solution to avoid such issue.
@rouault rouault force-pushed the fix_locale_issue_cs2cs_emulation_setup branch from 6cc0350 to b65cc5d Compare September 27, 2018 18:24
@rouault rouault merged commit da0e7f9 into OSGeo:master Sep 28, 2018
@kbevers kbevers added this to the 6.0.0 milestone Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants