ALL: sscanf("%f"), atof() etc. not portable due to Locale
|Reported by:||eriktorbjorn||Owned by:||criezy|
I noticed yesterday that Zork Nemesis fails to render properly. Fair enough, it's not yet a supported game, but the reason is worth bringing up: It uses sscanf() to parse floating-point values. This fails because the strings it parses use a period as decimal separator, while in my locale it's a comma. The result comes out looking less than the Great Underground Empire and more like the rings of Saturn.
Which raises the question, do these problems occur in any other parts of ScummVM, and how should we deal with them? A quick search suggests that the Wintermute engine may be affected, since it uses sscanf() and %f in base_persistence_manager.cpp, but there are several other format strings that are also used for floating-point values and I haven't looked for them. I assume atof() could also be problematic.
I'm not sure what the appropriate fix for this would be. Do we explicitly set the locale for ScummVM to use, or do we introduce or own locale-independent family of functions? Are there tools to scan for this kind of potential problems? (I'm actually a bit surprised that I haven't seen anything about it in our Coverity issues.)
Ticket imported from: #3615148. Ticket imported from: bugs/6434.
Change History (16)
comment:2 by , 10 years ago
|Summary:||General: Locale-related problems → ALL: sscanf("%f"), atof() etc. not portable due to Locale|