]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/addgrps.c: add_groups(): Reallocate at once
authorAlejandro Colomar <alx@kernel.org>
Thu, 14 Nov 2024 18:58:54 +0000 (19:58 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 24 Jan 2025 13:58:13 +0000 (07:58 -0600)
commitaaaa3d41a5379aae745d53fae5870ec8678a889e
tree494f6cc25508f070e6bccf621da97fcd5461a784
parent8d42b04c806bca1d997e8fd11c6dae5a067f7361
lib/addgrps.c: add_groups(): Reallocate at once

We can calculate an upper bound of the number of added groups by
counting the number of delimiters in the string (plus one for the
element after the last delimiter).  This avoids reallocating +1 in a
loop.

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/addgrps.c