From: David Laight <david.laight.linux@gmail.com>
To: Rosalie Fang <rosaliefang@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Kuan-Wei Chiu <visitorckw@gmail.com>,
Guan-Chun Wu <409411716@gms.tku.edu.tw>,
Nathan Chancellor <nathan@kernel.org>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Greg Thelen <gthelen@google.com>, Yi Zhu <chuyee@google.com>,
llvm@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/base64: fix -Wconstant-conversion warning in INIT_1()
Date: Tue, 3 Nov 2026 22:44:58 +0000 [thread overview]
Message-ID: <20261103224458.7fdaecd0@pumpkin> (raw)
In-Reply-To: <20261103163404.159582-1-rosaliefang@google.com>
On Tue, 3 Nov 2026 16:34:04 +0000
Rosalie Fang <rosaliefang@google.com> wrote:
> When expanding BASE64_REV_INIT() for v in 0x7c..0x7f (124..127), the
> unselected ternary branch (v) - '0' + 52 evaluates to 128..131, which
> exceeds SCHAR_MAX (127). Recent Clang versions diagnose implicit integer
> constant conversions in unevaluated ternary arms when initializing the
> s8 lookup tables:
Has that been reported as a compiler bug?
>
> lib/base64.c:58:18: error: implicit conversion from 'int' to 's8'
> (aka 'signed char') changes value from 131 to -125
> [-Werror,-Wconstant-conversion]
> 58 | [BASE64_IMAP] = BASE64_REV_INIT('+', ',')
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> lib/base64.c:34:42: note: expanded from macro 'INIT_1'
> 34 | : (v) >= '0' && (v) <= '9' ? (v) - '0' + 52 \
> | ~~~~~~~~~~^~~~
>
> Explicitly cast the digit-branch expression to s8 to silence the
> warning.
>
> Fixes: c4eb7ad32eab ("lib/base64: optimize base64_decode() with reverse lookup tables")
> Assisted-by: LLM
> Signed-off-by: Rosalie Fang <rosaliefang@google.com>
> ---
> lib/base64.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/base64.c b/lib/base64.c
> index 325c7332b049..1489c048b1fd 100644
> --- a/lib/base64.c
> +++ b/lib/base64.c
> @@ -31,7 +31,7 @@ static const char base64_tables[][65] = {
> #define INIT_1(v, ch_62, ch_63) \
> [v] = (v) >= 'A' && (v) <= 'Z' ? (v) - 'A' \
> : (v) >= 'a' && (v) <= 'z' ? (v) - 'a' + 26 \
> - : (v) >= '0' && (v) <= '9' ? (v) - '0' + 52 \
> + : (v) >= '0' && (v) <= '9' ? (s8)((v) - '0' + 52) \
> : (v) == (ch_62) ? 62 : (v) == (ch_63) ? 63 : -1
It might save further trouble to put the (s8) cast on the entire RHS
expression.
David
>
> /*
prev parent reply other threads:[~2026-11-03 22:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 16:34 Rosalie Fang
2026-11-03 19:00 ` Nathan Chancellor
2026-11-03 22:16 ` Rosalie Fang
2026-11-03 23:03 ` David Laight
2026-11-03 22:44 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261103224458.7fdaecd0@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=409411716@gms.tku.edu.tw \
--cc=akpm@linux-foundation.org \
--cc=chuyee@google.com \
--cc=gthelen@google.com \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=rosaliefang@google.com \
--cc=visitorckw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®