Skip to content

Commit

Permalink
kconfig: add xstrdup() helper
Browse files Browse the repository at this point in the history
We already have xmalloc(), xcalloc(), and xrealloc(().  Add xstrdup()
as well to save tedious error handling.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
  • Loading branch information
Masahiro Yamada committed Mar 1, 2018
1 parent 6c49f35 commit cd81fc8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/kconfig/confdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scripts/kconfig/kxgettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option,
if (self->files == NULL)
goto out_fail;

self->msg = strdup(msg);
self->msg = xstrdup(msg);
if (self->msg == NULL)
goto out_fail_msg;

Expand Down
1 change: 1 addition & 0 deletions scripts/kconfig/lkc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions scripts/kconfig/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions scripts/kconfig/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion scripts/kconfig/zconf.y
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};


Expand Down

0 comments on commit cd81fc8

Please sign in to comment.