diff options
author | Jim Kingdon <jkingdon@engr.sgi.com> | 1994-03-18 18:34:36 +0000 |
---|---|---|
committer | Jim Kingdon <jkingdon@engr.sgi.com> | 1994-03-18 18:34:36 +0000 |
commit | ee6d646a4b8240008e00442f13bf2de236f24573 (patch) | |
tree | 70627552adbafd80b8a5c18689c53acc201bea47 /gdb/regex.c | |
parent | 60e9faebc1c2d518ad2fc57d13ee99ca38f34451 (diff) | |
download | gdb-ee6d646a4b8240008e00442f13bf2de236f24573.zip gdb-ee6d646a4b8240008e00442f13bf2de236f24573.tar.gz gdb-ee6d646a4b8240008e00442f13bf2de236f24573.tar.bz2 |
* regex.c (EXTEND_BUFFER): Adjust pointers within buffer by
computing their offset from the start of the old buffer and adding
to the new buffer, rather than by assuming we can add the
difference between the old buffer and the new buffer (it might not
fit in an int). Merge in cosmetic differences from emacs regex.c
version of this macro.
Diffstat (limited to 'gdb/regex.c')
-rw-r--r-- | gdb/regex.c | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/gdb/regex.c b/gdb/regex.c index 78b1f47..9b6dc5b 100644 --- a/gdb/regex.c +++ b/gdb/regex.c @@ -146,23 +146,40 @@ re_set_syntax (syntax) #define PATUNFETCH p-- -#define EXTEND_BUFFER \ - { char *old_buffer = bufp->buffer; \ - if (bufp->allocated == (1<<16)) goto too_big; \ - bufp->allocated *= 2; \ - if (bufp->allocated > (1<<16)) bufp->allocated = (1<<16); \ - if (!(bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated))) \ - goto memory_exhausted; \ - c = bufp->buffer - old_buffer; \ - b += c; \ - if (fixup_jump) \ - fixup_jump += c; \ - if (laststart) \ - laststart += c; \ - begalt += c; \ - if (pending_exact) \ - pending_exact += c; \ - } +/* This is not an arbitrary limit: the arguments which represent offsets + into the pattern are two bytes long. So if 2^16 bytes turns out to + be too small, many things would have to change. */ +#define MAX_BUF_SIZE (1 << 16) + + +/* Extend the buffer by twice its current size via realloc and + reset the pointers that pointed into the old block to point to the + correct places in the new one. If extending the buffer results in it + being larger than MAX_BUF_SIZE, then flag memory exhausted. */ +#define EXTEND_BUFFER \ + do { \ + char *old_buffer = bufp->buffer; \ + if (bufp->allocated == MAX_BUF_SIZE) \ + goto too_big; \ + bufp->allocated <<= 1; \ + if (bufp->allocated > MAX_BUF_SIZE) \ + bufp->allocated = MAX_BUF_SIZE; \ + bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated);\ + if (bufp->buffer == NULL) \ + goto memory_exhausted; \ + /* If the buffer moved, move all the pointers into it. */ \ + if (old_buffer != bufp->buffer) \ + { \ + b = (b - old_buffer) + bufp->buffer; \ + begalt = (begalt - old_buffer) + bufp->buffer; \ + if (fixup_jump) \ + fixup_jump = (fixup_jump - old_buffer) + bufp->buffer;\ + if (laststart) \ + laststart = (laststart - old_buffer) + bufp->buffer; \ + if (pending_exact) \ + pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ + } \ + } while (0) static void store_jump (), insert_jump (); |