[PATCH v5 22/23] lib/bootconfig: fix sign-compare in xbc_node_compose_key_after()
From: Josh Law
Date: Sat Mar 14 2026 - 19:38:36 EST
lib/bootconfig.c:322:25: warning: comparison of integer expressions
of different signedness: 'int' and 'size_t' [-Wsign-compare]
lib/bootconfig.c:325:30: warning: conversion to 'size_t' from 'int'
may change the sign of the result [-Wsign-conversion]
snprintf() returns int but size is size_t, so comparing ret >= size
and subtracting size -= ret involve mixed-sign operations. Cast ret
at the comparison and subtraction sites; ret is known non-negative at
this point because the ret < 0 early return has already been taken.
Signed-off-by: Josh Law <objecting@xxxxxxxxxxxxx>
---
lib/bootconfig.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index e318b236e728..68a72dbc38fa 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -319,10 +319,10 @@ int __init xbc_node_compose_key_after(struct xbc_node *root,
depth ? "." : "");
if (ret < 0)
return ret;
- if (ret >= size) {
+ if (ret >= (int)size) {
size = 0;
} else {
- size -= ret;
+ size -= (size_t)ret;
buf += ret;
}
total += ret;
--
2.34.1