mirror of
https://github.com/mpv-player/mpv
synced 2025-01-16 20:14:57 +00:00
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 ("."). My patch inserts calls to setlocale around float parsing functions strtod() and atof() in cfgparser.c and input/input.c. patch by Aleksander Adamowski <olo@altkom.com.pl> git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7871 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
57f9f8fa14
commit
4aeac332f6
24
cfgparser.c
24
cfgparser.c
@ -16,6 +16,11 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef USE_SETLOCALE
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "mp_msg.h"
|
||||
@ -550,25 +555,22 @@ static int config_read_option(m_config_t *config,config_t** conf_list, char *opt
|
||||
case CONF_TYPE_FLOAT:
|
||||
if (param == NULL)
|
||||
goto err_missing_param;
|
||||
|
||||
/* <olo@altkom.com.pl> Use portable C locale for parsing floats: */
|
||||
#ifdef USE_SETLOCALE
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
#endif
|
||||
tmp_float = strtod(param, &endptr);
|
||||
|
||||
switch(*endptr) {
|
||||
case ':':
|
||||
case '/':
|
||||
tmp_float /= strtod(endptr+1, &endptr);
|
||||
break;
|
||||
case '.':
|
||||
case ',':
|
||||
/* we also handle floats specified with
|
||||
* non-locale decimal point ::atmos
|
||||
*/
|
||||
if(tmp_float<0)
|
||||
tmp_float -= 1.0/pow(10,strlen(endptr+1)) * strtod(endptr+1, &endptr);
|
||||
else
|
||||
tmp_float += 1.0/pow(10,strlen(endptr+1)) * strtod(endptr+1, &endptr);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#ifdef USE_SETLOCALE
|
||||
setlocale(LC_NUMERIC, "");
|
||||
#endif
|
||||
|
||||
if (*endptr) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be a floating point number"
|
||||
|
@ -12,6 +12,10 @@
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef USE_SETLOCALE
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#include "input.h"
|
||||
#include "mouse.h"
|
||||
#ifdef MP_DEBUG
|
||||
@ -470,7 +474,14 @@ mp_input_parse_cmd(char* str) {
|
||||
break;
|
||||
case MP_CMD_ARG_FLOAT:
|
||||
errno = 0;
|
||||
/* <olo@altkom.com.pl> Use portable C locale for parsing floats: */
|
||||
#ifdef USE_SETLOCALE
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
#endif
|
||||
cmd->args[i].v.f = atof(ptr);
|
||||
#ifdef USE_SETLOCALE
|
||||
setlocale(LC_NUMERIC, "");
|
||||
#endif
|
||||
if(errno != 0) {
|
||||
mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s : argument %d isn't a float\n",cmd_def->name,i+1);
|
||||
ptr = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user