]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/gshadow.c: build_list(): Allocate at once
authorAlejandro Colomar <alx@kernel.org>
Wed, 6 Nov 2024 00:20:17 +0000 (01:20 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 6 Dec 2024 03:20:59 +0000 (21:20 -0600)
commit512deecca5f63410943b99c48f32836808fb0c3c
tree2b9db61aad70d636643e78e2273a846d3884d1e9
parent2f4b5f5d809a541284de53a1245404d656bf932e
lib/gshadow.c: build_list(): Allocate at once

Instead of reallocating 1 more meber per iteration, calculate the total
amount that we want by counting the number of commas (delimiters) in the
string, plus one for the last element, plus one for the terminating
NULL.

This might result in overallocation of one element if the string is an
empty string, or if there's a trailing comma; however, that's not an
issue.  We can afford overallocating one element in certain cases, and
we get in exchange a much simpler function.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/gshadow.c