summaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-04-09 18:04:18 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-04-09 18:04:18 +0300
commit24ddf2742b0034089bce38e5f4ebd99b93c6e161 (patch)
treef1bebfcf20d78673b656122b0258c5054a999562 /helpers
parent9091a155190093c3d2dbbed4bd29b0feec50c8ce (diff)
downloadgawk-24ddf2742b0034089bce38e5f4ebd99b93c6e161.tar.gz
Further fixes from Andrew Schorr.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/ChangeLog4
-rw-r--r--helpers/testdfa.c21
2 files changed, 10 insertions, 15 deletions
diff --git a/helpers/ChangeLog b/helpers/ChangeLog
index 2cb3be44..5a3f2fe3 100644
--- a/helpers/ChangeLog
+++ b/helpers/ChangeLog
@@ -1,3 +1,7 @@
+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.
diff --git a/helpers/testdfa.c b/helpers/testdfa.c
index 092a13d8..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 + 1);
- if (buf == NULL) {
- fprintf(stderr, "%s: malloc failed\n", __func__);
- exit(EXIT_FAILURE);
- }
- buflen = *len;
- } else if (*len > buflen) {
- buf = (char *) realloc(buf, *len + 1);
- 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) {