# HG changeset patch # User Chong Yidong # Date 1206572080 0 # Node ID 6a347c1757025a594ba953fc600d433b49adabfe # Parent e0ebf2441a57c32cbe8a5144d268c2d0e2435ade (EXTEND_BUFFER): Change order of pointer addition operations, to avoid having the difference between pointers overflow. diff -r e0ebf2441a57 -r 6a347c175702 src/regex.c --- a/src/regex.c Wed Mar 26 22:53:47 2008 +0000 +++ b/src/regex.c Wed Mar 26 22:54:40 2008 +0000 @@ -1854,8 +1854,10 @@ being larger than MAX_BUF_SIZE, then flag memory exhausted. */ #if __BOUNDED_POINTERS__ # define SET_HIGH_BOUND(P) (__ptrhigh (P) = __ptrlow (P) + bufp->allocated) -# define MOVE_BUFFER_POINTER(P) \ - (__ptrlow (P) += incr, SET_HIGH_BOUND (P), __ptrvalue (P) += incr) +# define MOVE_BUFFER_POINTER(P) \ + (__ptrlow (P) = new_buffer + (__ptrlow (P) - old_buffer), \ + SET_HIGH_BOUND (P), \ + __ptrvalue (P) = new_buffer + (__ptrvalue (P) - old_buffer)) # define ELSE_EXTEND_BUFFER_HIGH_BOUND \ else \ { \ @@ -1869,12 +1871,12 @@ SET_HIGH_BOUND (pending_exact); \ } #else -# define MOVE_BUFFER_POINTER(P) (P) += incr +# define MOVE_BUFFER_POINTER(P) ((P) = new_buffer + ((P) - old_buffer)) # define ELSE_EXTEND_BUFFER_HIGH_BOUND #endif #define EXTEND_BUFFER() \ do { \ - re_char *old_buffer = bufp->buffer; \ + unsigned char *old_buffer = bufp->buffer; \ if (bufp->allocated == MAX_BUF_SIZE) \ return REG_ESIZE; \ bufp->allocated <<= 1; \ @@ -1886,7 +1888,7 @@ /* If the buffer moved, move all the pointers into it. */ \ if (old_buffer != bufp->buffer) \ { \ - int incr = bufp->buffer - old_buffer; \ + unsigned char *new_buffer = bufp->buffer; \ MOVE_BUFFER_POINTER (b); \ MOVE_BUFFER_POINTER (begalt); \ if (fixup_alt_jump) \