[MPlayer-dev-eng] Locale problems with parsing float options

Aleksander Adamowski olo at altkom.com.pl
Fri Oct 18 17:00:19 CEST 2002


Hi!
I've found and fixed a bug in MPlayer which would prevent proper parsing of 
some floating point options when the locale used has a decimal point
other than the dot character (".").

The symptoms are:
With the default input.conf file in ~/.mplayer, and with LC_NUMERIC=pl 
(polish locale has a comma, not dot for decimal point), the keys Z,X (sub 
delay) and +,- (audio delay) don't work properly - when pressed, they adjust 
sub delay and audio delay by increments of 0.0000 (that is, the current 
value is displayed on OSD, but doesn't change) - that's because a string 
"0.2000" becomes a float value of 0,0000 when parsed  with polish LC_NUMERIC.
After changing the locale to en, or C, or POSIX, they start working, because 
their values in input.conf are parsed properly.
Boy, was that bug irritating (and hard to track)!

My patch inserts calls to setlocale around float parsing functions strtod() 
and atof() in cfgparser.c and input/input.c.

My patch also undoes a change in recent CVS version of MPlayer in 
cfgparser.c - someone tried to implement portable float parsing by hand there.
I recommend using my patch, it temporarily switches to portable C locale for 
parsing floats. The CVS implementation only works for non-standard locales 
where comma is used for decimal point - there may be others (though I don't 
know - that's exactly what locales are for, I don't need to care for decimal 
points around the globe)...

I've found other calls to strtod() and atof() functions throughout the 
source tree, but I don't know much about the code, so I've decided to not 
touch them - they may need similar fixes too, but their maintainers need to 
decide.

My patch only handles reading the options' values - it doesn't touch the 
code involved in saving options to a file.
Notice however, that in apparently the only place where options are saved to 
a file, in Gui/cfg.c, temporary locale switching has already been 
implemented in cfg_read() and cfg_write() in exactly the same way as in my 
patch.


atof() function is currentl used in the following files (in pre8, I hadn't 
had the time to check in CVS):

./Gui/skin/cut.c
./TOOLS/subfont-c/subfont.c
./input/input.c         (already enclosed in setlocale() calls by me)
./libmpdemux/tv.c
./libmpdemux/demux_viv.c

strtod() function is used in the following files (pre8 too):

./libvo/video_out.c
./cfgparser.c           (already enclosed in setlocale() calls by me)
./libavcodec/eval.c


Patch attached.

Best Regards
-- 
     Aleksander (Olo) Adamowski
         GG#: 274614
         ICQ UIN: 19780575
         http://olo.office.altkom.com.pl
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: MPlayer-2002_10_18_C_locale_floats_parse.patch
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20021018/06de4033/attachment.txt>


More information about the MPlayer-dev-eng mailing list