diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-13 10:09:04 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-13 10:09:04 +0300 |
commit | 0325b4daf737414c3b811b05c70b897b807a436b (patch) | |
tree | 4facae80910096029530389c2832fa91dd60a8cc /regex_internal.h | |
parent | 89c079e54f1e3a49df1f2653ba5fe40d834cd8c3 (diff) | |
download | egawk-0325b4daf737414c3b811b05c70b897b807a436b.tar.gz egawk-0325b4daf737414c3b811b05c70b897b807a436b.tar.bz2 egawk-0325b4daf737414c3b811b05c70b897b807a436b.zip |
Fix regex code to avoid malloc(0).
Diffstat (limited to 'regex_internal.h')
-rw-r--r-- | regex_internal.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/regex_internal.h b/regex_internal.h index 9aab5e52..6a870f23 100644 --- a/regex_internal.h +++ b/regex_internal.h @@ -467,8 +467,38 @@ static unsigned int re_string_context_at (const re_string_t *input, int idx, # endif #endif +/* + * GAWK checks for zero-size allocations everywhere else, + * do it here too. + */ +#ifndef GAWK #define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t))) #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t))) +#else +static void * +test_malloc(size_t count, const char *file, size_t line) +{ + if (count == 0) { + fprintf(stderr, "%s:%d: allocation of zero bytes\n", + file, line); + exit(1); + } + return malloc(count); +} + +static void * +test_realloc(void *p, size_t count, const char *file, size_t line) +{ + if (count == 0) { + fprintf(stderr, "%s:%d: reallocation of zero bytes\n", + file, line); + exit(1); + } + return realloc(p, count); +} +#define re_malloc(t,n) ((t *) test_malloc (((n) * sizeof (t)), __FILE__, __LINE__)) +#define re_realloc(p,t,n) ((t *) test_realloc (p, (n) * sizeof (t), __FILE__, __LINE__)) +#endif #define re_free(p) free (p) struct bin_tree_t |