]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Fix invalid read in setlocale()
authorTakashi Iwai <tiwai@suse.de>
Thu, 18 Aug 2005 14:58:31 +0000 (14:58 +0000)
committerTakashi Iwai <tiwai@suse.de>
Thu, 18 Aug 2005 14:58:31 +0000 (14:58 +0000)
Fix suspicious warnings "Invalid read" of setlocale() detected by valgrind2.

src/conf.c

index 73556cf72e02f81480ea210beb4e2815e5dc87cf..da8bc458b11b2655f47f6cd03ea4984678915430 100644 (file)
@@ -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)