~vcs-imports/gawk/master

« back to all changes in this revision

Viewing changes to regex.c

  • Committer: Arnold D. Robbins
  • Date: 2010-07-16 09:27:41 UTC
  • Revision ID: git-v1:61bb57af53ebe916d2db6e3585d4fc7ac1d99b92
Tags: gawk-2.15.3
Move to gawk-2.15.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
334
334
    *b++ = (char) (ch);                                                 \
335
335
  }
336
336
  
337
 
/* Extend the buffer by twice its current size via reallociation and
 
337
/* Extend the buffer by twice its current size via reallocation and
338
338
   reset the pointers that pointed into the old allocation to point to
339
339
   the correct places in the new allocation.  If extending the buffer
340
 
   results in it being larger than 1 << 16, then flag memory exhausted.  */
 
340
   results in it being larger than EXTEND_BUFFER_MAX, then flag memory 
 
341
   exhausted.  */
 
342
#ifdef _MSC_VER
 
343
/* Microsoft C 16-bit versions limit malloc to approx 65512 bytes.
 
344
   The REALLOC define eliminates a flurry of conversion warnings,
 
345
   but is not required. */
 
346
#define EXTEND_BUFFER_MAX 65500L
 
347
#define REALLOC(p,s) realloc(p, (size_t) (s))
 
348
#else
 
349
#define EXTEND_BUFFER_MAX (1L << 16)
 
350
#define REALLOC realloc
 
351
#endif
341
352
#define EXTEND_BUFFER                                                   \
342
353
  { char *old_buffer = bufp->buffer;                                    \
343
 
    if (bufp->allocated == (1L<<16)) goto too_big;                      \
 
354
    if (bufp->allocated == EXTEND_BUFFER_MAX) goto too_big;             \
344
355
    bufp->allocated *= 2;                                               \
345
 
    if (bufp->allocated > (1L<<16)) bufp->allocated = (1L<<16);         \
346
 
    bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated);    \
 
356
    if (bufp->allocated > EXTEND_BUFFER_MAX)                            \
 
357
      bufp->allocated = EXTEND_BUFFER_MAX;                              \
 
358
    bufp->buffer = (char *) REALLOC (bufp->buffer, bufp->allocated);    \
347
359
    if (bufp->buffer == 0)                                              \
348
360
      goto memory_exhausted;                                            \
349
361
    b = (b - old_buffer) + bufp->buffer;                                \