diff options
author | Russell Belfer <arrbee@arrbee.com> | 2011-11-30 11:45:17 +0400 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2011-11-30 11:45:17 +0400 |
commit | 309113c984c1f3157659dc1174e5d4218f610ae4 (patch) | |
tree | 63fb56773ea31214c1107dfa33dbecceec2b4c1c /src/buffer.h | |
parent | 7df41387f5d09308acda0d4b54eccc1431c71610 (diff) |
Make initial value of git_buf ptr always be a valid empty string.
Taking a page from core git's strbuf, this introduces git_buf_initbuf
which is an empty string that is used to initialize the git_buf ptr
value even for new buffers. Now the git_buf ptr will always point to
a valid NUL-terminated string.
This change required jumping through a few hoops for git_buf_grow
and git_buf_free to distinguish between a actual allocated buffer
and the global initial value. Also, this moves the allocation
related functions to be next to each other near the top of buffer.c.
Diffstat (limited to 'src/buffer.h')
-rw-r--r-- | src/buffer.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/buffer.h b/src/buffer.h index 9e8ebd058..fa0c7f0b8 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -14,8 +14,11 @@ typedef struct { ssize_t asize, size; } git_buf; -#define GIT_BUF_INIT {NULL, 0, 0} +extern char git_buf_initbuf[]; +#define GIT_BUF_INIT { git_buf_initbuf, 0, 0 } + +void git_buf_init(git_buf *buf, size_t initial_size); int git_buf_grow(git_buf *buf, size_t target_size); void git_buf_free(git_buf *buf); void git_buf_swap(git_buf *buf_a, git_buf *buf_b); |