mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-11 20:05:07 -05: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:
parent
d35a7fb6f3
commit
62f828014f
@ -21,6 +21,7 @@
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h> /* setlocale */
|
||||
#include <fcntl.h> /* open */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -514,7 +515,15 @@ static int _parse_options(const char *key, char *value,
|
||||
} else if(strcmp(key, "UseDelta") == 0) {
|
||||
double ratio;
|
||||
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);
|
||||
setlocale(LC_NUMERIC, oldlocale);
|
||||
|
||||
if(*endptr != '\0' || ratio < 0.0 || ratio > 2.0) {
|
||||
pm_printf(ALPM_LOG_ERROR,
|
||||
_("config file %s, line %d: invalid value for '%s' : '%s'\n"),
|
||||
|
Loading…
Reference in New Issue
Block a user