logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 6857c6eb4de23c2ff611b7030aa2bb9cf6f67d21
parent 3b8a24e0fddbe3cc11e55917d2659542c2c0409e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 23 Sep 2024 05:38:39 +0200

lib/tr_str: make sure reallocarray isn't passed zero

Diffstat:

Mlib/tr_str.c16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/tr_str.c b/lib/tr_str.c @@ -185,19 +185,19 @@ genclass(STR *s) */ if(cp->set == NULL) { - cp->set = reallocarray(NULL, NCHARS + 1, sizeof(*cp->set)); + len = NCHARS + 1; + assert(len != 0); + cp->set = reallocarray(NULL, len, sizeof(*cp->set)); if(cp->set == NULL) err(1, NULL); + len = 0; for(i = 0; i < NCHARS; i++) { - if(cp->func(i)) - { - cp->set[len] = i; - len++; - } + if(cp->func(i)) cp->set[len++] = i; } - cp->set[len] = OOBCH; - len++; + cp->set[len++] = OOBCH; + + assert(len != 0); cp->set = reallocarray(cp->set, len, sizeof(*cp->set)); if(cp->set == NULL) err(1, NULL); }