mirror of
https://github.com/git/git
synced 2024-08-24 18:26:02 +00:00
Merge branch 'rs/mem-pool-size-t-safety'
size_t arithmetic safety. * rs/mem-pool-size-t-safety: mem-pool: use st_add() in mem_pool_strvfmt()
This commit is contained in:
commit
aaf524cfb0
|
@ -115,6 +115,7 @@ static char *mem_pool_strvfmt(struct mem_pool *pool, const char *fmt,
|
|||
size_t available = block ? block->end - block->next_free : 0;
|
||||
va_list cp;
|
||||
int len, len2;
|
||||
size_t size;
|
||||
char *ret;
|
||||
|
||||
va_copy(cp, ap);
|
||||
|
@ -123,13 +124,14 @@ static char *mem_pool_strvfmt(struct mem_pool *pool, const char *fmt,
|
|||
if (len < 0)
|
||||
BUG("your vsnprintf is broken (returned %d)", len);
|
||||
|
||||
ret = mem_pool_alloc(pool, len + 1); /* 1 for NUL */
|
||||
size = st_add(len, 1); /* 1 for NUL */
|
||||
ret = mem_pool_alloc(pool, size);
|
||||
|
||||
/* Shortcut; relies on mem_pool_alloc() not touching buffer contents. */
|
||||
if (ret == next_free)
|
||||
return ret;
|
||||
|
||||
len2 = vsnprintf(ret, len + 1, fmt, ap);
|
||||
len2 = vsnprintf(ret, size, fmt, ap);
|
||||
if (len2 != len)
|
||||
BUG("your vsnprintf is broken (returns inconsistent lengths)");
|
||||
return ret;
|
||||
|
|
Loading…
Reference in a new issue