From 1fdd1a6c190e722d127c3d67b5d37faf9b45560b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 18 Aug 2005 14:58:31 +0000 Subject: [PATCH] Fix invalid read in setlocale() Fix suspicious warnings "Invalid read" of setlocale() detected by valgrind2. --- src/conf.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/conf.c b/src/conf.c index 73556cf7..da8bc458 100644 --- a/src/conf.c +++ b/src/conf.c @@ -499,16 +499,21 @@ static int safe_strtod(const char *str, double *val) char *end; double v; char *saved_locale; + char locstr[64]; /* enough? */ int err; if (!*str) return -EINVAL; saved_locale = setlocale(LC_NUMERIC, NULL); - setlocale(LC_NUMERIC, "C"); + if (saved_locale) { + snprintf(locstr, sizeof(locstr), "%s", saved_locale); + setlocale(LC_NUMERIC, "C"); + } errno = 0; v = strtod(str, &end); err = -errno; - setlocale(LC_NUMERIC, saved_locale); + if (saved_locale) + setlocale(LC_NUMERIC, locstr); if (err) return err; if (*end) @@ -993,7 +998,7 @@ static int parse_array_def(snd_config_t *father, input_t *input, int idx, int sk snd_config_t *n = NULL; if (!skip) { - char static_id[12]; + char static_id[12]; snprintf(static_id, sizeof(static_id), "%i", idx); id = strdup(static_id); if (id == NULL) -- 2.47.1