]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/: Use NITEMS() instead of SIZEOF_ARRAY() where number of elements is meant
authorAlejandro Colomar <alx@kernel.org>
Thu, 23 Nov 2023 00:06:52 +0000 (01:06 +0100)
committerSerge Hallyn <serge@hallyn.com>
Mon, 27 Nov 2023 03:01:05 +0000 (21:01 -0600)
commit721b9096ebeab58ba4da512cd8e5536de60f03dd
tree6a654ac6883ae5cbd3635bd3288a90bc28b0ab72
parenta5cddf243acab50c4c62e21e0b9f37ca70acea74
lib/: Use NITEMS() instead of SIZEOF_ARRAY() where number of elements is meant

For arrays of char, both NITEMS() and SIZEOF_ARRAY() return the same
value.  However, NITEMS() is more appropriate.  Think of wide-character
equivalents of the same code; with NITEMS(), they would continue to be
valid, while with SIZEOF_ARRAY(), they would be wrong.

In the implementation of ZUSTR2STP(), we want SIZEOF_ARRAY() within the
static assert, because we're just comparing the sizes of the source and
destination buffers, and we don't care if we compare sizes or numbers of
elements, and using sizes is just simpler.  But we want NITEMS() in the
zustr2stp() call, where we want to copy a specific number of characters.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/strtcpy.h
lib/utmp.c
lib/zustr2stp.h