diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2015-02-10 23:55:07 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-02-12 22:54:47 -0500 |
| commit | 4aa664ae3953d99c2ae4cd769f02818bc122eebc (patch) | |
| tree | 7316e3d7febcbcde19dd4844af9503f4c6d57d69 /src/buf_text.c | |
| parent | 3603cb0978b7ef21ff9cd63693ebd6d27bc2bc53 (diff) | |
| download | libgit2-4aa664ae3953d99c2ae4cd769f02818bc122eebc.tar.gz | |
git_buf_grow_by: increase buf asize incrementally
Introduce `git_buf_grow_by` to incrementally increase the size of a
`git_buf`, performing an overflow calculation on the growth.
Diffstat (limited to 'src/buf_text.c')
| -rw-r--r-- | src/buf_text.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/buf_text.c b/src/buf_text.c index ace54d725..08b86f4cc 100644 --- a/src/buf_text.c +++ b/src/buf_text.c @@ -29,9 +29,8 @@ int git_buf_text_puts_escaped( scan += count; } - GITERR_CHECK_ALLOC_ADD(buf->size, total); - GITERR_CHECK_ALLOC_ADD(buf->size + total, 1); - if (git_buf_grow(buf, buf->size + total + 1) < 0) + GITERR_CHECK_ALLOC_ADD(total, 1); + if (git_buf_grow_by(buf, total + 1) < 0) return -1; for (scan = string; *scan; ) { @@ -129,7 +128,6 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src) for (; next; scan = next + 1, next = memchr(scan, '\n', end - scan)) { size_t copylen = next - scan; - size_t needsize; /* if we find mixed line endings, bail */ if (next > start && next[-1] == '\r') { @@ -137,11 +135,8 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src) return GIT_PASSTHROUGH; } - GITERR_CHECK_ALLOC_ADD(tgt->size, copylen); - GITERR_CHECK_ALLOC_ADD(tgt->size + copylen, 3); - needsize = tgt->size + copylen + 3; - - if (tgt->asize < needsize && git_buf_grow(tgt, needsize) < 0) + GITERR_CHECK_ALLOC_ADD(copylen, 3); + if (git_buf_grow_by(tgt, copylen + 3) < 0) return -1; if (next > scan) { |
