Skip to content

Commit cd81fc8

Browse files
committed
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 <yamada.masahiro@socionext.com>
1 parent 6c49f35 commit cd81fc8

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

scripts/kconfig/confdata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
178178
case S_HEX:
179179
done:
180180
if (sym_string_valid(sym, p)) {
181-
sym->def[def].val = strdup(p);
181+
sym->def[def].val = xstrdup(p);
182182
sym->flags |= def_flags;
183183
} else {
184184
if (def != S_DEF_AUTO)

scripts/kconfig/kxgettext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option,
101101
if (self->files == NULL)
102102
goto out_fail;
103103

104-
self->msg = strdup(msg);
104+
self->msg = xstrdup(msg);
105105
if (self->msg == NULL)
106106
goto out_fail_msg;
107107

scripts/kconfig/lkc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ int file_write_dep(const char *name);
115115
void *xmalloc(size_t size);
116116
void *xcalloc(size_t nmemb, size_t size);
117117
void *xrealloc(void *p, size_t size);
118+
char *xstrdup(const char *s);
118119

119120
struct gstr {
120121
size_t len;

scripts/kconfig/symbol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym)
183183
sprintf(str, "%lld", val2);
184184
else
185185
sprintf(str, "0x%llx", val2);
186-
sym->curr.val = strdup(str);
186+
sym->curr.val = xstrdup(str);
187187
}
188188

189189
static void sym_set_changed(struct symbol *sym)
@@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags)
849849
: !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE))))
850850
return symbol;
851851
}
852-
new_name = strdup(name);
852+
new_name = xstrdup(name);
853853
} else {
854854
new_name = NULL;
855855
hash = 0;

scripts/kconfig/util.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size)
154154
fprintf(stderr, "Out of memory.\n");
155155
exit(1);
156156
}
157+
158+
char *xstrdup(const char *s)
159+
{
160+
char *p;
161+
162+
p = strdup(s);
163+
if (p)
164+
return p;
165+
fprintf(stderr, "Out of memory.\n");
166+
exit(1);
167+
}

scripts/kconfig/zconf.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ no_mainmenu_stmt: /* empty */
127127
* later regardless of whether it comes from the 'prompt' in
128128
* mainmenu_stmt or here
129129
*/
130-
menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL);
130+
menu_add_prompt(P_MENU, xstrdup("Linux Kernel Configuration"), NULL);
131131
};
132132

133133

0 commit comments

Comments
 (0)