Re: [PATCH v6 16/17] lib/bootconfig: fix sign-compare in xbc_node_compose_key_after()
From: Google
Date: Tue Mar 17 2026 - 03:58:30 EST
On Sun, 15 Mar 2026 12:20:14 +0000
Josh Law <objecting@xxxxxxxxxxxxx> wrote:
> 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) {
nit:
if ((size_t)ret >= size) {
because sizeof(size_t) > sizeof(int).
Thanks,
> size = 0;
> } else {
> - size -= ret;
> + size -= (size_t)ret;
> buf += ret;
> }
> total += ret;
> --
> 2.34.1
>
>
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>