aboutsummaryrefslogtreecommitdiffstats
path: root/helpers/testdfa.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-04-27 14:09:25 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-04-27 14:09:25 +0300
commit7bab0e1ff31ebaf7716fe2716a630c92b8ca8a44 (patch)
treebac93ed98e429ea3ecd42885a8d087db3e69fb21 /helpers/testdfa.c
parenta435b8da2941d0b3c997420c71b1f4b7b79b52ff (diff)
parente78dfd4b04060ad3278a1b3505720893ec432617 (diff)
downloadegawk-7bab0e1ff31ebaf7716fe2716a630c92b8ca8a44.tar.gz
egawk-7bab0e1ff31ebaf7716fe2716a630c92b8ca8a44.tar.bz2
egawk-7bab0e1ff31ebaf7716fe2716a630c92b8ca8a44.zip
Merge branch 'master' into feature/cmake
Diffstat (limited to 'helpers/testdfa.c')
-rw-r--r--helpers/testdfa.c21
1 files changed, 6 insertions, 15 deletions
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) {