version 1.25, 2012/11/07 14:18:41 |
version 1.26, 2015/04/25 15:33:47 |
|
|
*/ |
*/ |
|
|
#include <ctype.h> |
#include <ctype.h> |
|
#include <limits.h> |
#include <stddef.h> |
#include <stddef.h> |
|
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdarg.h> |
|
|
#define DO_STAT_BUF(a, b) |
#define DO_STAT_BUF(a, b) |
#endif |
#endif |
|
|
|
static void |
|
fatal_overflow() |
|
{ |
|
fprintf(stderr, "buffer size overflow\n"); |
|
exit(2); |
|
} |
|
|
/* BufExpand(bp, nb) |
/* BufExpand(bp, nb) |
* Expand buffer bp to hold upto nb additional |
* Expand buffer bp to hold upto nb additional |
* chars. Makes sure there's room for an extra '\0' char at |
* chars. Makes sure there's room for an extra '\0' char at |
|
|
DO_STAT_BUF(bp, nb); \ |
DO_STAT_BUF(bp, nb); \ |
\ |
\ |
do { \ |
do { \ |
size *= 2 ; \ |
if (size <= SIZE_MAX/2) { \ |
|
size *= 2 ; \ |
|
} else { \ |
|
fatal_overflow(); \ |
|
} \ |
} while (size - occupied < (nb)+1+BUF_MARGIN); \ |
} while (size - occupied < (nb)+1+BUF_MARGIN); \ |
(bp)->buffer = (bp)->inPtr = (bp)->endPtr = \ |
(bp)->buffer = (bp)->inPtr = (bp)->endPtr = \ |
erealloc((bp)->buffer, size); \ |
erealloc((bp)->buffer, size); \ |