diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-01-03 22:08:38 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-01-03 22:08:38 -0800 |
commit | 60b6962db0b0488667180e11cc6cfb1cec1b41ea (patch) | |
tree | 9f3d399e48b781b5e363b47a2aa04e2b758e331c /src/buffer.c | |
parent | cc50a3aba3e34dc58ca819a65b907871e2ea6fd9 (diff) |
Revert "Change types for source map offsets (#174)"
This reverts commit 4fbe344df43ed7f60a3d3a53981088334cb709fc.
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/buffer.c b/src/buffer.c index 9a9e9ad..a6754b6 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -33,11 +33,6 @@ void cmark_strbuf_init(cmark_mem *mem, cmark_strbuf *buf, } static CMARK_INLINE void S_strbuf_grow_by(cmark_strbuf *buf, bufsize_t add) { - // Safety check for overflow. - if (add > BUFSIZE_MAX - buf->size) { - fprintf(stderr, "Internal cmark_strbuf overflow"); - abort(); - } cmark_strbuf_grow(buf, buf->size + add); } @@ -47,25 +42,18 @@ void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size) { if (target_size < buf->asize) return; - // Oversize the buffer by 50% to guarantee amortized linear time - // complexity on append operations. - bufsize_t add = target_size / 2; - // Account for terminating NUL byte. - add += 1; - // Round up to multiple of eight. - add = (add + 7) & ~7; - - // Check for overflow but allow an additional NUL byte. - if (target_size + add > BUFSIZE_MAX + 1) { - target_size = BUFSIZE_MAX + 1; - } - else { - target_size += add; - } + if (target_size > (bufsize_t)(INT32_MAX / 2)) + abort(); + + /* Oversize the buffer by 50% to guarantee amortized linear time + * complexity on append operations. */ + bufsize_t new_size = target_size + target_size / 2; + new_size += 1; + new_size = (new_size + 7) & ~7; buf->ptr = (unsigned char *)buf->mem->realloc(buf->asize ? buf->ptr : NULL, - target_size); - buf->asize = target_size; + new_size); + buf->asize = new_size; } bufsize_t cmark_strbuf_len(const cmark_strbuf *buf) { return buf->size; } |