diff options
| author | Tyge Løvset <[email protected]> | 2023-02-06 18:25:18 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-06 18:25:18 +0100 |
| commit | 1c81deecc673a6619ccc25c5c763e979b0a54a1a (patch) | |
| tree | 240ac48ebba58e516c1e2d7534c0a40f6f6c2e7a /src | |
| parent | e17b2c89ec9d301be4d62ce8f96a21eb9e4d8dc6 (diff) | |
| download | STC-modified-1c81deecc673a6619ccc25c5c763e979b0a54a1a.tar.gz STC-modified-1c81deecc673a6619ccc25c5c763e979b0a54a1a.zip | |
Fixed error in cregex_test.c itself.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cregex.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cregex.c b/src/cregex.c index 7789ee6e..0688d9e1 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -347,6 +347,7 @@ typedef struct _Parser bool lastwasand; /* Last token was _operand */ short nbra; short nclass; + size_t instcap; _Rune yyrune; /* last lex'd rune */ _Reclass *yyclassp; /* last lex'd class */ _Reclass* classp; @@ -546,6 +547,9 @@ _optimize(_Parser *par, _Reprog *pp) * necessary. Reallocate to the actual space used * and then relocate the code. */ + if ((par->freep - pp->firstinst)*2 > (ptrdiff_t)par->instcap) + return pp; + intptr_t ipp = (intptr_t)pp; size_t size = sizeof(_Reprog) + (size_t)(par->freep - pp->firstinst)*sizeof(_Reinst); _Reprog *npp = (_Reprog *)c_realloc(pp, size); @@ -843,8 +847,8 @@ _regcomp1(_Reprog *progp, _Parser *par, const char *s, int cflags) _Token token; /* get memory for the program. estimated max usage */ - const size_t instcap = 5 + 6*strlen(s); - _Reprog* pp = (_Reprog *)c_realloc(progp, sizeof(_Reprog) + instcap*sizeof(_Reinst)); + par->instcap = 5U + 6*strlen(s); + _Reprog* pp = (_Reprog *)c_realloc(progp, sizeof(_Reprog) + par->instcap*sizeof(_Reinst)); if (pp == NULL) { par->error = CREG_OUTOFMEMORY; c_free(progp); |
