Skip to content

Commit d717f24

Browse files
committed
kconfig: add xrealloc() helper
We already have xmalloc(), xcalloc(). Add xrealloc() as well to save tedious error handling. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 9e3e10c commit d717f24

6 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎scripts/kconfig/confdata.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
201201
if (new_size > *n) {
202202
new_size += LINE_GROWTH - 1;
203203
new_size *= 2;
204-
nline = realloc(*lineptr, new_size);
204+
nline = xrealloc(*lineptr, new_size);
205205
if (!nline)
206206
return -1;
207207

‎scripts/kconfig/lkc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct file *file_lookup(const char *name);
114114
int file_write_dep(const char *name);
115115
void *xmalloc(size_t size);
116116
void *xcalloc(size_t nmemb, size_t size);
117+
void *xrealloc(void *p, size_t size);
117118

118119
struct gstr {
119120
size_t len;

‎scripts/kconfig/nconf.gui.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
*/
88
#include "nconf.h"
9+
#include "lkc.h"
910

1011
/* a list of all the different widgets we use */
1112
attributes_t attributes[ATTR_MAX+1] = {0};
@@ -374,7 +375,7 @@ int dialog_inputbox(WINDOW *main_window,
374375

375376
if (strlen(init)+1 > *result_len) {
376377
*result_len = strlen(init)+1;
377-
*resultp = result = realloc(result, *result_len);
378+
*resultp = result = xrealloc(result, *result_len);
378379
}
379380

380381
/* find the widest line of msg: */

‎scripts/kconfig/symbol.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ const char *sym_expand_string_value(const char *in)
936936
newlen = strlen(res) + strlen(symval) + strlen(src) + 1;
937937
if (newlen > reslen) {
938938
reslen = newlen;
939-
res = realloc(res, reslen);
939+
res = xrealloc(res, reslen);
940940
}
941941

942942
strcat(res, symval);

‎scripts/kconfig/util.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void str_append(struct gstr *gs, const char *s)
104104
if (s) {
105105
l = strlen(gs->s) + strlen(s) + 1;
106106
if (l > gs->len) {
107-
gs->s = realloc(gs->s, l);
107+
gs->s = xrealloc(gs->s, l);
108108
gs->len = l;
109109
}
110110
strcat(gs->s, s);
@@ -145,3 +145,12 @@ void *xcalloc(size_t nmemb, size_t size)
145145
fprintf(stderr, "Out of memory.\n");
146146
exit(1);
147147
}
148+
149+
void *xrealloc(void *p, size_t size)
150+
{
151+
p = realloc(p, size);
152+
if (p)
153+
return p;
154+
fprintf(stderr, "Out of memory.\n");
155+
exit(1);
156+
}

‎scripts/kconfig/zconf.l‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void append_string(const char *str, int size)
5252
if (new_size > text_asize) {
5353
new_size += START_STRSIZE - 1;
5454
new_size &= -START_STRSIZE;
55-
text = realloc(text, new_size);
55+
text = xrealloc(text, new_size);
5656
text_asize = new_size;
5757
}
5858
memcpy(text + text_size, str, size);

0 commit comments

Comments
 (0)