]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/fs/readlink/: readlinknul(): Use ssize_t to simplify
authorAlejandro Colomar <alx@kernel.org>
Sun, 9 Feb 2025 11:23:46 +0000 (12:23 +0100)
committerAlejandro Colomar <alx@kernel.org>
Mon, 3 Mar 2025 23:08:15 +0000 (00:08 +0100)
commitdf4125ec677be3805758204a754a5b0f6b49dadd
tree45d30f5be55adce5da7c4322aeb710607f769b0d
parentd908e294115e35fad1c3f966c6eecdab9e09028d
lib/fs/readlink/: readlinknul(): Use ssize_t to simplify

Consistently using a signed type allows us to avoid sign-mismatch
diagnostics, while keeping the code simple.  It feels weird to
accept a ssize_t instead of a size_t, but it's a matter of getting
used to it.

Another way to achieve this with a single 'len' variable and no casts
would be to compare against SIZE_MAX, but that's less readable than -1.
Or one could write a SIZE_C() macro a la UINT64_C(), and compare the
size_t against SIZE_C(-1), but that's still suboptimal (regarding
readability) compared to consistently using signed size types.

Fixes: b9d00b64a19f (2024-12-09; "lib/fs/readlink/readlinknul.h: readlinknul(): Silence warning")
Acked-by: Serge Hallyn <serge@hallyn.com>
Cc: Martin Uecker <uecker@tugraz.at>
Cc: "Robert C. Seacord" <rcseacord@gmail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/fs/readlink/readlinknul.c
lib/fs/readlink/readlinknul.h