From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBF20378800 for ; Mon, 9 Mar 2026 09:20:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773048040; cv=none; b=Vj79sihniG9gjRSvFvKU5zOUVlPe4ltDZjbc+k6GgVvTuBYfEFOxd2e43z79/2tLwILG/FblcGGSEgRafy+emW41mbeS8bswjUeZvpTSUJZ/jTdJbYRa7r+9f8NbH42oay8DHFfaMVFKvjRciTkLn+xuMW3ArkOKQFWGfmGBUeI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773048040; c=relaxed/simple; bh=+/+oa8/xwLiYAoSi7cqzcZ78p43gAMJ7N/Uxk2gvSV4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ECqmM4peqivAvuYP5+nxWltsp7Ef7/EB0wUCHTrBkFI4+CC4iMtiyw2d2L7pvn+ANZDSVeRNf00VS5MLvAugdC+UEt+Xk1D9MxexBSilFC8Q4Lrb1YTT+zqHdHBM42NG3/oYU0OTr6HW16KF90Ydv6yb9jvhAH6Rom/VFOxD/RA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HQ6D8mem; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HQ6D8mem" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-439c4a93841so3890165f8f.1 for ; Mon, 09 Mar 2026 02:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773048037; x=1773652837; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=RWye1tyanH7k6Iwtu7NXPPkodWyzvinip2BOwwoGccc=; b=HQ6D8memQKJ7GiMAT+txpbgQwreeznSZKvK2FqYD1V0N+dA+UQmu3SeQ+JFGZOEavZ 62pYZqiBnwy80nq2PdgnFlwANRAlO6NpgVlok+GJcK31HIU+pPiA2lfrUFm7PdtZYOzE ZFAHm4aD/7ala7TTqjnGhy7AwiCUbdXnFwFC95yPsyS+omQZGyVfI7gwEb1qvUmAyBDe hFd/jL6iX+L7cyL0M6hd11HwkkT6tcDCB6S8NwNe/vgiC7SdHfcV46B3Ot4+/iIF2CWo dEY7I0ykFw5+EVyGplfMFnZqMdZRRxYa73BQQdeyyZ56A0EQi0DA8QM68d/byAgVxGvn +eYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773048037; x=1773652837; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RWye1tyanH7k6Iwtu7NXPPkodWyzvinip2BOwwoGccc=; b=g79XdhZst841ur4hLcpn9ZdF4G1t+837zNaRK7SBt/sMtc4UyMGgDnx7lERgILZdeV UYzttJ1VwBJeNjP/336/yrUeKtTKJq8/kw9Ns/KRnbs0uM+Ves0iqzxdIW/Y6Ewfhnur WL5/9c3oq0JWJOP5XKhurDsub7SIaPI/Fs563q6pJE1b4+KoOEgopXO1il1ZKI+sWRAk a1rz/4mAEl/RIN9bQrY3EMpD4i9ue1Z0P/LcVVQWkrjHJRf1+JQ3jqp6NvMV/V4ko97U RLaKcTYL/9Vz4+B5e7uvns8olNdtST+W9RETfbMEetbVAhLJmpD30+RVwR2uZhOx2Qeu 7a/g== X-Forwarded-Encrypted: i=1; AJvYcCVRY9Kue9jU0rorEzjk79iMNono2H1/tVF3b80xm1/fMojSRQoxMNEGRkH0qEO6ukElGgzK0gLBycMVxKw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1zP+ZtyYIh5Xj5HozAXRPQ/iqFtaMji5xDEHGf91qxFdHa6Ck f1B7dqkmFMx7RTkgDQUnuK3dA5CVzcHRsm5k2fI5X9Z79We7+8ZMnIHr X-Gm-Gg: ATEYQzwzP4C84vqknVJ0TACtbEb4dBH5sWXg8v45XyJ5UuCFzKZwFh+Ji0CatoxVPWg oSo1Brperd0ijpx5qr1iuY5IASJJkVgqVqDhbsR/saF5to/4wBUxCn5DIBflYOjLEA325MDDcHs YcrYKgKw+84JRtaWp7OHEnBVAAMf1XA45UK1sN9fDSSP1OuAexRSmHFC3pDsk83d9ruhhY2gGvP zsOAr9BhCjDMuOF6yiMFM38G/0yHvkG2o1BYZIp2506SttGLJPaM8MV8UceYM8vFaIDzhy1MIBY LAG2l2M4gOBQbP7f+8/EL1i2AdKEf5EJS9oB1AE/qej+Z6nbIsI8dZ0eB865RyqQbVFiDk6LDn0 rw1nws6+MoTgbbWoi4VXT8kqX2iYV4mhUkeDR6p0T2T+mw9hzwPpRSbrrjhAzYbOwH+SFZXXWgU RT/+41RtR1nrOVbiuRRhaWFMBMMu/XJLFFgHmZYulVvD96Cw3IkGga2CE5uFfaHEps/d/y8MnuL Cw= X-Received: by 2002:a5d:5d06:0:b0:439:bdd7:425d with SMTP id ffacd0b85a97d-439da35cb53mr18030276f8f.23.1773048036897; Mon, 09 Mar 2026 02:20:36 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439dae2b9d8sm26153805f8f.21.2026.03.09.02.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 02:20:36 -0700 (PDT) Date: Mon, 9 Mar 2026 09:20:35 +0000 From: David Laight To: Willy Tarreau Cc: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= , linux-kernel@vger.kernel.org, Cheng Li Subject: Re: [PATCH v5 next 00/17] Enhance printf() Message-ID: <20260309092035.5df6a0d2@pumpkin> In-Reply-To: References: <20260308113742.12649-1-david.laight.linux@gmail.com> <20260308224121.56affbf7@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, 9 Mar 2026 07:55:30 +0100 Willy Tarreau wrote: > Hi David, >=20 > On Sun, Mar 08, 2026 at 10:41:21PM +0000, David Laight wrote: > > On Sun, 8 Mar 2026 22:01:19 +0100 > > Thomas Wei=C3=9Fschuh wrote: > > =20 > > > Hi David, > > >=20 > > > thanks again for your patches! > > >=20 > > > On 2026-03-08 11:37:25+0000, david.laight.linux@gmail.com wrote: =20 > > > > From: David Laight > > > > David Laight (17): > > > > tools/nolibc: Add _NOLIBC_OPTIMIZER_HIDE_VAR() to compiler.h > > > > selftests/nolibc: Rename w to written in expect_vfprintf() > > > > tools/nolibc: Implement strerror() in terms of strerror_r() > > > > tools/nolibc: Rename the 'errnum' parameter to strerror() > > > > tools/nolibc/printf: Output pad characters in 16 byte chunks > > > > tools/nolibc/printf: Simplify __nolibc_printf() > > > > tools/nolibc/printf: Use goto and reduce indentation > > > > tools/nolibc/printf: Use bit-masks to hold requested flag, length= and > > > > conversion chars > > > > tools/nolibc/printf: Add support for length modifiers tzqL and fo= rmats > > > > iX > > > > tools/nolibc/printf: Handle "%s" with the numeric formats > > > > tools/nolibc/printf: Prepend sign to converted number > > > > tools/nolibc/printf: Add support for conversion flags space and p= lus > > > > tools/nolibc/printf: Special case 0 and add support for %#x > > > > tools/nolibc/printf: Add support for left aligning fields > > > > tools/nolibc/printf: Add support for zero padding and field preci= sion > > > > tools/nolibc/printf: Add support for octal output =20 > > >=20 > > > Beginning from here we have another sign-compare warning: > > >=20 > > > /home/t-8ch/.cache/crosstools/gcc-13.2.0-nolibc/i386-linux/bin/i386-l= inux-gcc -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 -W -Wall= -Wextra -fno-stack-protector -Wmissing-prototypes -fstack-protector-all -= mstack-protector-guard=3Dglobal -fsanitize=3Dundefined -fsanitize-trap=3Dal= l -m32 -Werror -Wl,--fatal-warnings -o nolibc-test \ > > > -nostdlib -nostdinc -static -Isysroot/i386/include nolibc-test.c no= libc-test-linkage.c -lgcc > > > In file included from sysroot/i386/include/nolibc.h:123, > > > from sysroot/i386/include/stdio.h:8, > > > from nolibc-test.c:12: > > > sysroot/i386/include/stdio.h: In function '__nolibc_printf': > > > sysroot/i386/include/stdio.h:569:41: error: comparison of integer exp= ressions of different signedness: 'unsigned int' and 'char' [-Werror=3Dsign= -compare] > > > 569 | if (sign_prefix !=3D *out) { > > > | ^~ > > > cc1: all warnings being treated as errors > > >=20 > > > I have applied all of the patches *before* > > > "tools/nolibc/printf: Prepend sign to converted number", which > > > introduced the sign_prefix variable. > > >=20 > > > Could you fix this up and repost the remaining patches? =20 > >=20 > > I hate 'sign compare' ... > > I dislike using casts to 'fix' it - random 'integer' casts have caused = me > > grief in the past. =20 >=20 > The cast here is unavoidable. One is a signed char, the other is an unsig= ned > int, so the comparison can be done in 3 methods depending on the develope= r's > original intent: > - 8 bits of the char against 8 lower bits of the unsigned int > - signed comparison where char is sign-extended and both are compared > as a 32-bit signed int > - unsigned comparison where char is zero-extended and both are compared > as a 32-bit unsigned int >=20 > > I don't want to make 'sign_prefix' signed - stops you adding 4 characte= rs > > (should you so desire); not to mention >> being either UB or implementa= tion > > defined on signed values (or maybe just negative ones). > >=20 > > The two obvious fixes are: > > if (sign_prefix - *out) > > or: > > if (sign_prefix !=3D *out + 0u)=20 > >=20 > > Your pick :-) > >=20 > > At least it is only the last couple of patches. =20 >=20 > It will not change much or will just even more hide the problem. There is nothing to change, the 'problem' just need hiding so the compiler doesn't complain. > My understanding of that code is that it's neither of these cases. Based > on the comment you apparently want in this test to only check for the > first byte of sign_prefix against *out, right ? So that should be: >=20 > if ((char)sign_prefix !=3D *out) >=20 > Did I get it right ? Not really, the check can only succeed when both values are '0' (which is the real condition being tested - as in the comment). If you add that (char) cast you'll get an unnecessary '& 0xff' on everything except x86 (where you might get a byte compare to memory instead of a sign/zero extending memory read and register compare). An alternative way of stopping the compiler complaining would be: if (sign_prefix !=3D *(unsigned char *)out) I'm waiting for the 'security' people to stop worrying about string truncation and turn their attention to casts of integers :-) David >=20 > Willy