1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

Use C locale when parsing UseDelta floating point values

We should save the current locale, use the 'C' locale during parsing,
then restore the original locale. Config files should always parse
regardless of the current user's locale setting. Fixes FS#34253.

Signed-off-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Dan McGee 2013-03-10 22:51:11 -05:00 committed by Allan McRae
parent d35a7fb6f3
commit 62f828014f

View File

@ -21,6 +21,7 @@
#include <errno.h> #include <errno.h>
#include <glob.h> #include <glob.h>
#include <limits.h> #include <limits.h>
#include <locale.h> /* setlocale */
#include <fcntl.h> /* open */ #include <fcntl.h> /* open */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -514,7 +515,15 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "UseDelta") == 0) { } else if(strcmp(key, "UseDelta") == 0) {
double ratio; double ratio;
char *endptr; char *endptr;
const char *oldlocale;
/* set the locale to 'C' for consistant decimal parsing (0.7 and never
* 0,7) from config files, then restore old setting when we are done */
oldlocale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C");
ratio = strtod(value, &endptr); ratio = strtod(value, &endptr);
setlocale(LC_NUMERIC, oldlocale);
if(*endptr != '\0' || ratio < 0.0 || ratio > 2.0) { if(*endptr != '\0' || ratio < 0.0 || ratio > 2.0) {
pm_printf(ALPM_LOG_ERROR, pm_printf(ALPM_LOG_ERROR,
_("config file %s, line %d: invalid value for '%s' : '%s'\n"), _("config file %s, line %d: invalid value for '%s' : '%s'\n"),