Floating point numbers in german locale have a different usage of "." and ",", compared to US or other locales. scanf and the c++ stream operators use the locale when parsing decimal numbers, this can lead to critical errors. See T2473.
Description
Status | Assigned | Task | ||
---|---|---|---|---|
Resolved | None | T2474 Check and test all decimal number parsing and output code for locale issues | ||
Duplicate | None | T3673 Check NrrdDiffusionImageReader for locale handling | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Resolved | None | T3672 Check ParRecFileReader handling of German locale | ||
Resolved | None | T3674 Check GEDicomDiffusionImageHeaderReader for locale handling | ||
Resolved | None | T2439 Pointset loading localization problem | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Resolved | None | T3675 Check SiemensDicomDiffusionImageHeaderReader for locale handling | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Resolved | None | T6682 Make mitk/Core locale independent | ||
Duplicate | None | T6681 Make mitk/Core/Code/Algorithms/ locale independent | ||
Resolved | None | T6683 Tiny xml is not locale independent | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Wontfix | None | T6821 Poco is not locale independent | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Wontfix | None | T6836 qwt is not locale independent | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Wontfix | None | T6841 ipPic is not locale independent | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Resolved | None | T6677 Make mitkCalculateGrayValueStatisticsTool locale independent | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Resolved | None | T6831 Make BlueBerry locale independent | ||
Wontfix | None | T6840 Make ipFunc locale independent | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Resolved | None | T6661 Make tbssview locale independent | ||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Restricted Maniphest Task | ||||
Resolved | None | T6664 Make Diffusionimaging locale independent | ||
Restricted Maniphest Task | ||||
Resolved | None | T6686 Make mbilog locale independent |
Event Timeline
A possible default bug note, providing a suggestion how to implement it, could be along the lines of:
In an effort to make mitk locale independent we have taken a look at the following files:
It seems, that floats are written to a stream or gotten from a stream without specifying the used locale. This can lead to problems if a file is written on a system with e.g. german locale and read on a system with an english locale or vice versa. To prevent this kind of problematic behaviour it is suggested to specify the locale used.
This can be done similar to the following code snippet:
// ... create stream here
// define standard locale
std::locale C("C");
get previous locale of the stream and save it
(especially important in case of cout and cin)
std::locale originalLocale = stream.getloc();
// switch the stream to standard locale
stream.imbue(C);
// ... write your data to file here
// switch back to the previous locale
stream.imbue( originalLocale )
Remember to take care of possible exceptions, by switching back to the original locale [ stream.imbue( originalLocale ) ] within the exception handling.
Expanded default message to encompass hints how to do this using printf and sprintf
In an effort to make mitk locale independent we have taken a look at the
following files:
It seems, that floats are written to a stream or gotten from a stream without
specifying the used locale. This can lead to problems if a file is written on a
system with e.g. german locale and read on a system with an english locale or
vice versa. To prevent this kind of problematic behaviour it is suggested to
specify the locale used.
This can be done similar to the following code snippet:
[code - streams]
// ... create stream here
// define standard locale
std::locale C("C");
get previous locale of the stream and save it
(especially important in case of cout and cin)
std::locale originalLocale = stream.getloc();
// switch the stream to standard locale
stream.imbue(C);
// ... write your data to file here
// switch back to the previous locale
stream.imbue( originalLocale );
[/code - streams]
Remember to take care of possible exceptions, by switching back to the original
locale [ stream.imbue( originalLocale ) ] within the exception handling.
[code - printf]
#include <stdio.h>
#include <locale.h>
int main( void )
{
//... other code //save old locale char * oldLocale; oldLocale = setlocale( LC_ALL, 0 ); //set new locale setlocale( LC_ALL, "C" ); //... other code using printf or sprintf to print //restore locale setlocale( LC_ALL, oldLocale ); //... other code
}
[/code - printf]