kconfig: Avoid format overflow warning from GCC 8.1
[carl9170fw.git] / config / confdata.c
index 204e751f4204f88763ab894188c0b8e934269091..4af0fbb1774c4d7bafea6794d9b772cb9c2b75fe 100644 (file)
@@ -28,7 +28,7 @@ static void conf_message(const char *fmt, ...)
        __attribute__ ((format (printf, 1, 2)));
 
 static const char *conf_filename;
-static int conf_lineno, conf_warnings, conf_unsaved;
+static int conf_lineno, conf_warnings;
 
 const char conf_defname[] = "include/generated/defconfig";
 
@@ -81,39 +81,13 @@ const char *conf_get_autoconfig_name(void)
        return name ? name : "include/generated/auto.conf";
 }
 
-static char *conf_expand_value(const char *in)
-{
-       struct symbol *sym;
-       const char *src;
-       static char res_value[SYMBOL_MAXLENGTH];
-       char *dst, name[SYMBOL_MAXLENGTH];
-
-       res_value[0] = 0;
-       dst = name;
-       while ((src = strchr(in, '$'))) {
-               strncat(res_value, in, src - in);
-               src++;
-               dst = name;
-               while (isalnum(*src) || *src == '_')
-                       *dst++ = *src++;
-               *dst = 0;
-               sym = sym_lookup(name, 0);
-               sym_calc_value(sym);
-               strcat(res_value, sym_get_string_value(sym));
-               in = src;
-       }
-       strcat(res_value, in);
-
-       return res_value;
-}
-
 char *conf_get_default_confname(void)
 {
        struct stat buf;
        static char fullname[PATH_MAX+1];
        char *env, *name;
 
-       name = conf_expand_value(conf_defname);
+       name = expand_string(conf_defname);
        env = getenv(SRCTREE);
        if (env) {
                sprintf(fullname, "%s/%s", env, name);
@@ -178,7 +152,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
        case S_HEX:
        done:
                if (sym_string_valid(sym, p)) {
-                       sym->def[def].val = strdup(p);
+                       sym->def[def].val = xstrdup(p);
                        sym->flags |= def_flags;
                } else {
                        if (def != S_DEF_AUTO)
@@ -201,7 +175,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
        if (new_size > *n) {
                new_size += LINE_GROWTH - 1;
                new_size *= 2;
-               nline = realloc(*lineptr, new_size);
+               nline = xrealloc(*lineptr, new_size);
                if (!nline)
                        return -1;
 
@@ -274,10 +248,11 @@ int conf_read_simple(const char *name, int def)
                        if (expr_calc_value(prop->visible.expr) == no ||
                            prop->expr->type != E_SYMBOL)
                                continue;
-                       name = conf_expand_value(prop->expr->left.sym->name);
+                       sym_calc_value(prop->expr->left.sym);
+                       name = sym_get_string_value(prop->expr->left.sym);
                        in = zconf_fopen(name);
                        if (in) {
-                               conf_message(_("using defaults found in %s"),
+                               conf_message("using defaults found in %s",
                                         name);
                                goto load;
                        }
@@ -290,7 +265,6 @@ load:
        conf_filename = name;
        conf_lineno = 0;
        conf_warnings = 0;
-       conf_unsaved = 0;
 
        def_flags = SYMBOL_DEF << def;
        for_all_symbols(i, sym) {
@@ -409,6 +383,7 @@ setsym:
 int conf_read(const char *name)
 {
        struct symbol *sym;
+       int conf_unsaved = 0;
        int i;
 
        sym_set_change_count(0);
@@ -791,7 +766,7 @@ int conf_write(const char *name)
        struct menu *menu;
        const char *basename;
        const char *str;
-       char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
+       char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8];
        char *env;
 
        dirname[0] = 0;
@@ -877,7 +852,7 @@ next:
                        return 1;
        }
 
-       conf_message(_("configuration written to %s"), newname);
+       conf_message("configuration written to %s", newname);
 
        sym_set_change_count(0);