History

kconfig: add xstrdup() helper

We already have xmalloc(), xcalloc(), and xrealloc((). Add xstrdup() as well to save tedious error handling.

Masahiro Yamada committed 8 years ago

Commit cd81fc81 parent 6c49f356 files · +17 −5Browse files

Unified · Split

6 files
  1. scripts/kconfig/confdata.c +1 −1
  2. scripts/kconfig/kxgettext.c +1 −1
  3. scripts/kconfig/lkc.h +1 −0
  4. scripts/kconfig/symbol.c +2 −2
  5. scripts/kconfig/util.c +11 −0
  6. scripts/kconfig/zconf.y +1 −1
scripts/kconfig/confdata.c+1−1
@@ -178,7 +178,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) · 177 unmodified lines
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+1−1
@@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option, · 100 unmodified lines
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+1−0
@@ -115,6 +115,7 @@ int file_write_dep(const char *name); · 114 unmodified lines
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+2−2
@@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym) · 182 unmodified lines
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) · 659 unmodified lines
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+11−0
@@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size) · 153 unmodified lines
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+1−1
@@ -127,7 +127,7 @@ no_mainmenu_stmt: /* empty */ · 126 unmodified lines
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