diff options
| author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-02-08 11:19:07 -0500 |
|---|---|---|
| committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-02-09 21:26:04 -0500 |
| commit | d717f24d8c68081caae2374cf5ea6c4e62c490fc (patch) | |
| tree | 325008cf6d2fea2dfa15e4d49ae4d4d79fb1ff2b /scripts | |
| parent | 9e3e10c725360b9d07018cfcd5b7b6b7d325fae5 (diff) | |
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>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/kconfig/confdata.c | 2 | ||||
| -rw-r--r-- | scripts/kconfig/lkc.h | 1 | ||||
| -rw-r--r-- | scripts/kconfig/nconf.gui.c | 3 | ||||
| -rw-r--r-- | scripts/kconfig/symbol.c | 2 | ||||
| -rw-r--r-- | scripts/kconfig/util.c | 11 | ||||
| -rw-r--r-- | scripts/kconfig/zconf.l | 2 |
6 files changed, 16 insertions, 5 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f7927391de30..5c12dc91ef34 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
| @@ -201,7 +201,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n) | |||
| 201 | if (new_size > *n) { | 201 | if (new_size > *n) { |
| 202 | new_size += LINE_GROWTH - 1; | 202 | new_size += LINE_GROWTH - 1; |
| 203 | new_size *= 2; | 203 | new_size *= 2; |
| 204 | nline = realloc(*lineptr, new_size); | 204 | nline = xrealloc(*lineptr, new_size); |
| 205 | if (!nline) | 205 | if (!nline) |
| 206 | return -1; | 206 | return -1; |
| 207 | 207 | ||
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 16cb62b92650..4e23febbe4b2 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h | |||
| @@ -114,6 +114,7 @@ struct file *file_lookup(const char *name); | |||
| 114 | int file_write_dep(const char *name); | 114 | 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 | 118 | ||
| 118 | struct gstr { | 119 | struct gstr { |
| 119 | size_t len; | 120 | size_t len; |
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index a64b1c31253e..88874acfda36 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | * | 6 | * |
| 7 | */ | 7 | */ |
| 8 | #include "nconf.h" | 8 | #include "nconf.h" |
| 9 | #include "lkc.h" | ||
| 9 | 10 | ||
| 10 | /* a list of all the different widgets we use */ | 11 | /* a list of all the different widgets we use */ |
| 11 | attributes_t attributes[ATTR_MAX+1] = {0}; | 12 | attributes_t attributes[ATTR_MAX+1] = {0}; |
| @@ -374,7 +375,7 @@ int dialog_inputbox(WINDOW *main_window, | |||
| 374 | 375 | ||
| 375 | if (strlen(init)+1 > *result_len) { | 376 | if (strlen(init)+1 > *result_len) { |
| 376 | *result_len = strlen(init)+1; | 377 | *result_len = strlen(init)+1; |
| 377 | *resultp = result = realloc(result, *result_len); | 378 | *resultp = result = xrealloc(result, *result_len); |
| 378 | } | 379 | } |
| 379 | 380 | ||
| 380 | /* find the widest line of msg: */ | 381 | /* find the widest line of msg: */ |
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index c4409ee7fee2..60a76f958f33 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c | |||
| @@ -936,7 +936,7 @@ const char *sym_expand_string_value(const char *in) | |||
| 936 | newlen = strlen(res) + strlen(symval) + strlen(src) + 1; | 936 | newlen = strlen(res) + strlen(symval) + strlen(src) + 1; |
| 937 | if (newlen > reslen) { | 937 | if (newlen > reslen) { |
| 938 | reslen = newlen; | 938 | reslen = newlen; |
| 939 | res = realloc(res, reslen); | 939 | res = xrealloc(res, reslen); |
| 940 | } | 940 | } |
| 941 | 941 | ||
| 942 | strcat(res, symval); | 942 | strcat(res, symval); |
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 0e76042473cc..138894ef49ea 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c | |||
| @@ -104,7 +104,7 @@ void str_append(struct gstr *gs, const char *s) | |||
| 104 | if (s) { | 104 | if (s) { |
| 105 | l = strlen(gs->s) + strlen(s) + 1; | 105 | l = strlen(gs->s) + strlen(s) + 1; |
| 106 | if (l > gs->len) { | 106 | if (l > gs->len) { |
| 107 | gs->s = realloc(gs->s, l); | 107 | gs->s = xrealloc(gs->s, l); |
| 108 | gs->len = l; | 108 | gs->len = l; |
| 109 | } | 109 | } |
| 110 | strcat(gs->s, s); | 110 | strcat(gs->s, s); |
| @@ -145,3 +145,12 @@ void *xcalloc(size_t nmemb, size_t size) | |||
| 145 | fprintf(stderr, "Out of memory.\n"); | 145 | fprintf(stderr, "Out of memory.\n"); |
| 146 | exit(1); | 146 | exit(1); |
| 147 | } | 147 | } |
| 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 | } | ||
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 0ba4900050c1..02de6fe302a9 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l | |||
| @@ -52,7 +52,7 @@ static void append_string(const char *str, int size) | |||
| 52 | if (new_size > text_asize) { | 52 | if (new_size > text_asize) { |
| 53 | new_size += START_STRSIZE - 1; | 53 | new_size += START_STRSIZE - 1; |
| 54 | new_size &= -START_STRSIZE; | 54 | new_size &= -START_STRSIZE; |
| 55 | text = realloc(text, new_size); | 55 | text = xrealloc(text, new_size); |
| 56 | text_asize = new_size; | 56 | text_asize = new_size; |
| 57 | } | 57 | } |
| 58 | memcpy(text + text_size, str, size); | 58 | memcpy(text + text_size, str, size); |
