From 1078c4ae93562934a8625a6d314d17a7af370910 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 23 Jul 2023 22:05:48 +0200 Subject: [PATCH] enosys: avoid warnings when no aliases are found MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Weißschuh --- misc-utils/enosys.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/misc-utils/enosys.c b/misc-utils/enosys.c index 8415c63b5c..81e9323637 100644 --- a/misc-utils/enosys.c +++ b/misc-utils/enosys.c @@ -58,6 +58,13 @@ struct syscall { long number; }; +/* When the alias arrays are empty the compiler emits -Wtype-limits warnings. + * Avoid those by going through this function. */ +static inline bool lt(size_t a, size_t b) +{ + return a < b; +} + static const struct syscall syscalls[] = { #define UL_SYSCALL(name, nr) { name, nr }, #include "syscalls.h" @@ -124,7 +131,7 @@ int main(int argc, char **argv) switch (c) { case 's': found = 0; - for (i = 0; i < ARRAY_SIZE(syscalls); i++) { + for (i = 0; lt(i, ARRAY_SIZE(syscalls)); i++) { if (strcmp(optarg, syscalls[i].name) == 0) { blocked_number = syscalls[i].number; found = 1; @@ -142,7 +149,7 @@ int main(int argc, char **argv) break; case 'i': found = 0; - for (i = 0; i < ARRAY_SIZE(ioctls); i++) { + for (i = 0; lt(i, ARRAY_SIZE(ioctls)); i++) { if (strcmp(optarg, ioctls[i].name) == 0) { blocked_number = ioctls[i].number; found = 1; @@ -159,11 +166,11 @@ int main(int argc, char **argv) break; case 'l': - for (i = 0; i < ARRAY_SIZE(syscalls); i++) + for (i = 0; lt(i, ARRAY_SIZE(syscalls)); i++) printf("%5ld %s\n", syscalls[i].number, syscalls[i].name); return EXIT_SUCCESS; case 'm': - for (i = 0; i < ARRAY_SIZE(ioctls); i++) + for (i = 0; lt(i, ARRAY_SIZE(ioctls)); i++) printf("%5ld %s\n", ioctls[i].number, ioctls[i].name); return EXIT_SUCCESS; case 'V': -- 2.47.3