]> git.ipfire.org Git - thirdparty/git.git/commit - mem-pool.c
mem-pool: use st_add() in mem_pool_strvfmt()
authorRené Scharfe <l.s.r@web.de>
Sun, 31 Mar 2024 18:53:07 +0000 (20:53 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 31 Mar 2024 23:00:36 +0000 (16:00 -0700)
commitffeaf2f76ab422428d6190d0cfbca2f34f06602a
tree15729fa77bc7df1789cbf94c630187bb7409df82
parentf39addd0d9d75a073847ed4311079a499dd33f35
mem-pool: use st_add() in mem_pool_strvfmt()

If len is INT_MAX in mem_pool_strvfmt(), then len + 1 overflows.
Casting it to size_t would prevent that.  Use st_add() to go a step
further and make the addition *obviously* safe.  The compiler can
optimize the check away on platforms where SIZE_MAX > INT_MAX, i.e.
basically everywhere.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mem-pool.c