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
178 case S_HEX:178 case S_HEX:
179 done:179 done:
180 if (sym_string_valid(sym, p)) {180 if (sym_string_valid(sym, p)) {
181 sym->def[def].val = strdup(p);181 sym->def[def].val = xstrdup(p);
182 sym->flags |= def_flags;182 sym->flags |= def_flags;
183 } else {183 } else {
184 if (def != S_DEF_AUTO)184 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
101 if (self->files == NULL)101 if (self->files == NULL)
102 goto out_fail;102 goto out_fail;
103 103
104 self->msg = strdup(msg);104 self->msg = xstrdup(msg);
105 if (self->msg == NULL)105 if (self->msg == NULL)
106 goto out_fail_msg;106 goto out_fail_msg;
107 107
scripts/kconfig/lkc.h+1−0
@@ -115,6 +115,7 @@ int file_write_dep(const char *name); · 114 unmodified lines
115void *xmalloc(size_t size);115void *xmalloc(size_t size);
116void *xcalloc(size_t nmemb, size_t size);116void *xcalloc(size_t nmemb, size_t size);
117void *xrealloc(void *p, size_t size);117void *xrealloc(void *p, size_t size);
118char *xstrdup(const char *s);
118 119
119struct gstr {120struct gstr {
120 size_t len;121 size_t len;
scripts/kconfig/symbol.c+2−2
@@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym) · 182 unmodified lines
183 sprintf(str, "%lld", val2);183 sprintf(str, "%lld", val2);
184 else184 else
185 sprintf(str, "0x%llx", val2);185 sprintf(str, "0x%llx", val2);
186 sym->curr.val = strdup(str);186 sym->curr.val = xstrdup(str);
187}187}
188 188
189static void sym_set_changed(struct symbol *sym)189static void sym_set_changed(struct symbol *sym)
@@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags) · 659 unmodified lines
849 : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE))))849 : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE))))
850 return symbol;850 return symbol;
851 }851 }
852 new_name = strdup(name);852 new_name = xstrdup(name);
853 } else {853 } else {
854 new_name = NULL;854 new_name = NULL;
855 hash = 0;855 hash = 0;
scripts/kconfig/util.c+11−0
@@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size) · 153 unmodified lines
154 fprintf(stderr, "Out of memory.\n");154 fprintf(stderr, "Out of memory.\n");
155 exit(1);155 exit(1);
156}156}
157
158char *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
127 * later regardless of whether it comes from the 'prompt' in127 * later regardless of whether it comes from the 'prompt' in
128 * mainmenu_stmt or here128 * mainmenu_stmt or here
129 */129 */
130 menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL);130 menu_add_prompt(P_MENU, xstrdup("Linux Kernel Configuration"), NULL);
131};131};
132 132
133 133