Skip to content

Commit 229d0cf

Browse files
committed
kconfig: remove 'const' from the return type of sym_escape_string_value()
sym_escape_string_value() returns a malloc'ed memory, but as (const char *). So, it must be casted to (void *) when it is free'd. This is odd. The return type of sym_escape_string_value() should be (char *). I exploited that free(NULL) has no effect. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 6988f70 commit 229d0cf

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

scripts/kconfig/conf.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,16 @@ static void check_conf(struct menu *menu)
647647
switch (input_mode) {
648648
case listnewconfig:
649649
if (sym->name) {
650-
const char *str;
650+
const char *val = sym_get_string_value(sym);
651+
char *escaped = NULL;
651652

652653
if (sym->type == S_STRING) {
653-
str = sym_get_string_value(sym);
654-
str = sym_escape_string_value(str);
655-
printf("%s%s=%s\n", CONFIG_, sym->name, str);
656-
free((void *)str);
657-
} else {
658-
str = sym_get_string_value(sym);
659-
printf("%s%s=%s\n", CONFIG_, sym->name, str);
654+
escaped = sym_escape_string_value(val);
655+
val = escaped;
660656
}
657+
658+
printf("%s%s=%s\n", CONFIG_, sym->name, val);
659+
free(escaped);
661660
}
662661
break;
663662
case helpnewconfig:

scripts/kconfig/confdata.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -728,21 +728,22 @@ static struct conf_printer header_printer_cb =
728728
static void conf_write_symbol(FILE *fp, struct symbol *sym,
729729
struct conf_printer *printer, void *printer_arg)
730730
{
731-
const char *str;
731+
const char *val;
732+
char *escaped = NULL;
732733

733-
switch (sym->type) {
734-
case S_UNKNOWN:
735-
break;
736-
case S_STRING:
737-
str = sym_get_string_value(sym);
738-
str = sym_escape_string_value(str);
739-
printer->print_symbol(fp, sym, str, printer_arg);
740-
free((void *)str);
741-
break;
742-
default:
743-
str = sym_get_string_value(sym);
744-
printer->print_symbol(fp, sym, str, printer_arg);
734+
if (sym->type == S_UNKNOWN)
735+
return;
736+
737+
val = sym_get_string_value(sym);
738+
739+
if (sym->type == S_STRING) {
740+
escaped = sym_escape_string_value(val);
741+
val = escaped;
745742
}
743+
744+
printer->print_symbol(fp, sym, val, printer_arg);
745+
746+
free(escaped);
746747
}
747748

748749
static void

scripts/kconfig/lkc_proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE];
1818

1919
struct symbol * sym_lookup(const char *name, int flags);
2020
struct symbol * sym_find(const char *name);
21-
const char * sym_escape_string_value(const char *in);
21+
char *sym_escape_string_value(const char *in);
2222
struct symbol ** sym_re_search(const char *pattern);
2323
const char * sym_type_name(enum symbol_type type);
2424
void sym_calc_value(struct symbol *sym);

scripts/kconfig/symbol.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ struct symbol *sym_find(const char *name)
871871
return symbol;
872872
}
873873

874-
const char *sym_escape_string_value(const char *in)
874+
/* The returned pointer must be freed on the caller side */
875+
char *sym_escape_string_value(const char *in)
875876
{
876877
const char *p;
877878
size_t reslen;

0 commit comments

Comments
 (0)