diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-02-16 13:38:31 -0500 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-03-01 10:26:47 -0500 |
commit | cd81fc82b93fa408c30e08f59e5ef8caaa91d1d2 (patch) | |
tree | 5c6024076d70c2a392fb3207d6ba737ef7e5843b | |
parent | 6c49f359ca14f973970324afc9b20208fa0bbad5 (diff) |
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>
-rw-r--r-- | scripts/kconfig/confdata.c | 2 | ||||
-rw-r--r-- | scripts/kconfig/kxgettext.c | 2 | ||||
-rw-r--r-- | scripts/kconfig/lkc.h | 1 | ||||
-rw-r--r-- | scripts/kconfig/symbol.c | 4 | ||||
-rw-r--r-- | scripts/kconfig/util.c | 11 | ||||
-rw-r--r-- | scripts/kconfig/zconf.y | 2 |
6 files changed, 17 insertions, 5 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 5c12dc91ef34..df26c7b0fe13 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
@@ -178,7 +178,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) | |||
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) |
diff --git a/scripts/kconfig/kxgettext.c b/scripts/kconfig/kxgettext.c index 2858738b22d5..240880a89111 100644 --- a/scripts/kconfig/kxgettext.c +++ b/scripts/kconfig/kxgettext.c | |||
@@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option, | |||
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 | ||
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 4e23febbe4b2..2d5ec2d0e952 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h | |||
@@ -115,6 +115,7 @@ int file_write_dep(const char *name); | |||
115 | void *xmalloc(size_t size); | 115 | void *xmalloc(size_t size); |
116 | void *xcalloc(size_t nmemb, size_t size); | 116 | void *xcalloc(size_t nmemb, size_t size); |
117 | void *xrealloc(void *p, size_t size); | 117 | void *xrealloc(void *p, size_t size); |
118 | char *xstrdup(const char *s); | ||
118 | 119 | ||
119 | struct gstr { | 120 | struct gstr { |
120 | size_t len; | 121 | size_t len; |
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index cca9663be5dd..2220bc4b051b 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c | |||
@@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym) | |||
183 | sprintf(str, "%lld", val2); | 183 | sprintf(str, "%lld", val2); |
184 | else | 184 | 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 | ||
189 | static void sym_set_changed(struct symbol *sym) | 189 | static void sym_set_changed(struct symbol *sym) |
@@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags) | |||
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; |
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index b98a79e30e04..c6f6e21b809f 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c | |||
@@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size) | |||
154 | fprintf(stderr, "Out of memory.\n"); | 154 | fprintf(stderr, "Out of memory.\n"); |
155 | exit(1); | 155 | exit(1); |
156 | } | 156 | } |
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 | } | ||
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 4be98050b961..f5cb55f03ce5 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y | |||
@@ -127,7 +127,7 @@ no_mainmenu_stmt: /* empty */ | |||
127 | * later regardless of whether it comes from the 'prompt' in | 127 | * later regardless of whether it comes from the 'prompt' in |
128 | * mainmenu_stmt or here | 128 | * 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 | ||