Page MenuHomePhabricator

ipPic is not locale independent
Closed, WontfixPublic

Description

In an effort to make mitk and by extension ipPic locale independent we have taken a look at the
following files:

Utilities/ipPic/picinfo.c
Utilities/ipPic/ipPicInfo.c

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]

Event Timeline

Daniel, are you working on this bug?

(In reply to comment #1)

Daniel, are you working on this bug?

No, I guess I was just default assignee or connected to that issue in someone's mind.

Marco, did you look through the code, in order to decide what we are going to do with this bug?

This is only relevant for the picinfo tool which we don't use anymore (or don't care for ',' and '.' in the output ...)

Merging "Utilities" component into "Other"

kislinsk added a project: Bulk Edit.
kislinsk removed a project: Bulk Edit.