logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: d969449bce707083da2f0fecb9406d59428cbd91
parent 86a271f82710fa18baac3c7050c9542c4c015ffe
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 25 Jun 2025 02:12:53 +0200

cmd/expr.y: make sure malloc(0) doesn't happens

Diffstat:

Mcmd/expr.y4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cmd/expr.y b/cmd/expr.y @@ -206,10 +206,12 @@ to_string(struct val *vp) return; int ndigits = snprintf(NULL, 0, "%jd", vp->u.i); - if(ndigits < 0) + if(ndigits <= 0) utils_errx(ERR_EXIT, "failed to pre-format integer %jd as a string", vp->u.i); ndigits++; // NULL terminator + if(ndigits <= 0) + utils_errx(ERR_EXIT, "pre-format length overflow", ndigits); char *tmp = malloc(ndigits); if (tmp == NULL)