From: Masahiro Yamada Date: Fri, 16 Feb 2018 18:38:31 +0000 (+0900) Subject: kconfig: add xstrdup() helper X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=bf909cc9605bfd77ab60b9dfead00c92af2852d2;p=carl9170fw.git kconfig: add xstrdup() helper We already have xmalloc(), xcalloc(), and xrealloc((). Add xstrdup() as well to save tedious error handling. Signed-off-by: Masahiro Yamada Signed-off-by: Christian Lamparter --- diff --git a/config/confdata.c b/config/confdata.c index 3a0fb60..21efc14 100644 --- a/config/confdata.c +++ b/config/confdata.c @@ -178,7 +178,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) diff --git a/config/lkc.h b/config/lkc.h index 4e23feb..2d5ec2d 100644 --- a/config/lkc.h +++ b/config/lkc.h @@ -115,6 +115,7 @@ int file_write_dep(const char *name); void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); void *xrealloc(void *p, size_t size); +char *xstrdup(const char *s); struct gstr { size_t len; diff --git a/config/symbol.c b/config/symbol.c index cca9663..2220bc4 100644 --- a/config/symbol.c +++ b/config/symbol.c @@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym) sprintf(str, "%lld", val2); else sprintf(str, "0x%llx", val2); - sym->curr.val = strdup(str); + sym->curr.val = xstrdup(str); } static void sym_set_changed(struct symbol *sym) @@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags) : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) return symbol; } - new_name = strdup(name); + new_name = xstrdup(name); } else { new_name = NULL; hash = 0; diff --git a/config/util.c b/config/util.c index b98a79e..c6f6e21 100644 --- a/config/util.c +++ b/config/util.c @@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size) fprintf(stderr, "Out of memory.\n"); exit(1); } + +char *xstrdup(const char *s) +{ + char *p; + + p = strdup(s); + if (p) + return p; + fprintf(stderr, "Out of memory.\n"); + exit(1); +} diff --git a/config/zconf.y b/config/zconf.y index 02c8550..250d58e 100644 --- a/config/zconf.y +++ b/config/zconf.y @@ -127,7 +127,7 @@ no_mainmenu_stmt: /* empty */ * later regardless of whether it comes from the 'prompt' in * mainmenu_stmt or here */ - menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL); + menu_add_prompt(P_MENU, xstrdup("Linux Kernel Configuration"), NULL); };