diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-28 16:46:05 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-04-28 16:46:05 +0300 |
commit | 6853b3e94c03194200c5a7c4450820a8eaa0920f (patch) | |
tree | 0e68baf9f5d687a0a3b6543f01522a56bf010279 /helpers | |
parent | 020be4cb81b519a597acbf85e683cfb95993c2b9 (diff) | |
parent | b4ef28f58688cf3c3a5878c595b6582144ee2cf1 (diff) | |
download | egawk-6853b3e94c03194200c5a7c4450820a8eaa0920f.tar.gz egawk-6853b3e94c03194200c5a7c4450820a8eaa0920f.tar.bz2 egawk-6853b3e94c03194200c5a7c4450820a8eaa0920f.zip |
Merge branch 'master' into feature/regex-type
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/ChangeLog | 8 | ||||
-rw-r--r-- | helpers/testdfa.c | 21 |
2 files changed, 14 insertions, 15 deletions
diff --git a/helpers/ChangeLog b/helpers/ChangeLog index a5bbafb1..5a3f2fe3 100644 --- a/helpers/ChangeLog +++ b/helpers/ChangeLog @@ -1,3 +1,11 @@ +2015-04-09 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * testdfa.c (setup_pattern): Rationalize buffer size computations. + +2014-12-18 Arnold D. Robbins <arnold@skeeve.com> + + * testdfa.c (setup_pattern): Do not waste a byte at the end of a string. + 2014-09-04 Arnold D. Robbins <arnold@skeeve.com> * chlistref.awk: New file. Finds @ref{} to non-chapters. diff --git a/helpers/testdfa.c b/helpers/testdfa.c index 25a229a2..2b773467 100644 --- a/helpers/testdfa.c +++ b/helpers/testdfa.c @@ -372,10 +372,10 @@ setup_pattern(const char *pattern, size_t *len) { size_t is_multibyte = 0; int c, c2; - size_t buflen = 0; + size_t buflen; mbstate_t mbs; bool has_anchor = false; - char *buf = NULL; + char *buf; char *dest; const char *src, *end; @@ -391,21 +391,12 @@ setup_pattern(const char *pattern, size_t *len) * escaped characters translated, and generate the regex * from that. */ + buf = (char *) malloc(*len + 1); if (buf == NULL) { - buf = (char *) malloc(*len + 2); - if (buf == NULL) { - fprintf(stderr, "%s: malloc failed\n", __func__); - exit(EXIT_FAILURE); - } - buflen = *len; - } else if (*len > buflen) { - buf = (char *) realloc(buf, *len + 2); - if (buf == NULL) { - fprintf(stderr, "%s: realloc failed\n", __func__); - exit(EXIT_FAILURE); - } - buflen = *len; + fprintf(stderr, "%s: malloc failed\n", __func__); + exit(EXIT_FAILURE); } + buflen = *len; dest = buf; while (src < end) { |