From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 EF75B2E0916 for ; Sun, 1 Feb 2026 08:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769936189; cv=none; b=gwDgRNviEJaHOHNghfVGlJd1wCzTfy0+yYt5NQ4vyQCT9t2rx93xH1FHgroO6XNK2weV7JPjkQBUcQpxpjFOGQmKBguqL5L6iQuV2b8qIsbCgiAVddjwC/v9ZjVAowqsnpwTnLPcjUDnNj3O1BqXBzVA/00tqDGhd3lsvRwxJBM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769936189; c=relaxed/simple; bh=AEmOvN495b3D/+9kdexI5qjyESVQQf/puWFGbFt04Q4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tG1w/a/1a5NPnTROWfL6bSH3tVRPp6epxU9NRbYlpxUY6O4hFWY0MF5RMVfCUgSLhan0gSopaO6Pd2wVcmBva5EABQ6G4/lAh3NJW/BYf0iVEpUKXm5jFOp1GUdBHJiNmyK8uS4HtuQhLOUFyihYXA8S6VEudkLenTv379DofSg= 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=gVAfN/2c; arc=none smtp.client-ip=209.85.128.48 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="gVAfN/2c" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4806f3fc50bso35241975e9.0 for ; Sun, 01 Feb 2026 00:56:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769936186; x=1770540986; 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=rfWcl3qq2AvqI5ah7d9OMCB0IPH893V0i89HaPz6pvQ=; b=gVAfN/2cRK9rxByvkcGQxauWGM55z+lNKhnzfWKz2w6tEwyqK+T2oh42zZ18pnt0VZ 3kXs18M9pelvtGUes30A8WHRJMJCY7DdzlGi/ov+tll1u4K+DAasLFxV50dDU+QqB4f8 GFCb2gHQslLcgvVHDtzX+17MBj2n43kJfXVMK7ZI0m7jzbJxtVt4e59PX/gsX2Rdkb4i 6aeAVaTc1Lb+VAfejq5YqVuhgh7yEU2WndPip+xfp7R06sxNdV0x1n0NW+LDxUjkPsT2 tkCCkbgOLv+FEOQFcR+oKiv/y20pl3L+niKnmJ+qA0eJfcxwwjGvuYWh0bcFbYwY5+Mg pxTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769936186; x=1770540986; 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=rfWcl3qq2AvqI5ah7d9OMCB0IPH893V0i89HaPz6pvQ=; b=qrN99AEhkKquQaC7uaJwfbU7kMpn8NdKcBIDHIczi1s/bWxG3t9gZYygUB1UfOm9vX mHG96OR2gxgHD2qiSYS65T5ofy92tR66cr6JLvmJGM9la3tgsqdxymMvjAJke8mCUB3y KwgfTxVZF/+IbkHLtXX0gkpGp80LZvBNdF3G+i1xORdj7Qp9sDf9FzM91CGtTcOLLXq0 UOvRMcPUzvV38cToY7heuJQEc+Q52ee221z/jojlezjQDU8+CrDKbOgFt4GOsgskO1HQ 9UrEZNF0fP0WlFcdsl2hGkHqvX/2sse2BAU4d5Dubh4c4OkwE3nmDG1JpsE0L26LXsKx 3ygw== X-Forwarded-Encrypted: i=1; AJvYcCW+s21YN8qKR/PmIIEQSa/WOkV8W27R1+kfghj6X1uKWlPOIvBlt6ZZHq8dBdj3zFviaPenZiuT6SX7A+k=@vger.kernel.org X-Gm-Message-State: AOJu0YwOkq3JUDtg18X3JaMFoFVfwp2KDHU8hrJ4GBPuE88xODl5i6KJ p8PJkCE10gH259c2sqaS3EmYEnmNcdzPTnhvTxdgj+J21O6FykfE3DWv X-Gm-Gg: AZuq6aLG9auST7KfJ6brV4WJ2i8dRg5SCB7Xp78/cfg47x6K6RMxc8vS2Oy4GBacB4K 6vwa8KwJS0t1WER/XhnvW7ZzVNeNAVz4TGlGpjNUZyVrDKqi3X7hmmVjh+qJknB8h7lf8zsLyit dbg8Q8GxrXsVE6UcLxPk5gjhsXMU38qrxCCmkX23wtiGY+aIy9Pwm/+4BBtlfjQ1+YFPuOE4AYF Yma5CeiuakWE80Jbre5Q61Q4Se0JJ+L9cfkULkaxyUdX6MLd/+tyJVJnY7qxMZMcrjNeD+4gp/A o5QEfgpIQY1i3Y8xuVbVQCT63FlhxcwkroHv90jx6OL0Itnd2r6QNhng0fOHlGVtm0czWRo4o0w Dh68GrjB2BcZNuVp7L+ujoJYPg/kMNvJqiYEMNd3ENo3yf+Ci86dwXkm9rtHo5BPbqK0GAiKjng CQJd7PV48PhZvnAkIeiikeqgcykHuFgmqlGF2eCmkLDh2uC6Sb4pv7wzc8mWU75dU= X-Received: by 2002:a05:600c:6814:b0:46e:4b79:551 with SMTP id 5b1f17b1804b1-482db4abde0mr102712455e9.31.1769936186059; Sun, 01 Feb 2026 00:56:26 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-482dbd4a5b8sm77016845e9.5.2026.02.01.00.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Feb 2026 00:56:25 -0800 (PST) Date: Sun, 1 Feb 2026 08:56:24 +0000 From: David Laight To: Cheng Li Cc: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= , Willy Tarreau , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] tools/nolibc: add support zero pad (0) in printf Message-ID: <20260201085624.7fbc4c59@pumpkin> In-Reply-To: References: <20260130083737.1123-1-im.lechain@gmail.com> <222455c7-17a8-4b1f-a574-4e945467eb12@weissschuh.net> <20260131123209.1ed5df80@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 Sun, 1 Feb 2026 08:49:37 +0800 Cheng Li wrote: > David Laight =E4=BA=8E2026=E5=B9=B41=E6=9C= =8831=E6=97=A5=E5=91=A8=E5=85=AD 20:32=E5=86=99=E9=81=93=EF=BC=9A > > > > On Sat, 31 Jan 2026 11:18:49 +0100 > > Thomas Wei=C3=9Fschuh wrote: > > =20 > > > Hey Cheng, > > > > > > Jan 30, 2026 09:37:51 licheng.li : > > > =20 > > > > From: Cheng Li > > > > > > > > This patch correctly implements the '0' flag in __nolibc_printf() to > > > > allow zero-padding for numeric and pointer outputs. =20 > > > > > > Thanks for (all of) your patches. > > > I am not sure when exactly I can take a proper look at them. > > > As we are currently fairly late in the 6.20/7.0 development cycle I w= ould like move your patches into the next one. > > > We can still discuss the patches and you can send new revisions and p= atches, > > > but they won't be picked up until in a few weeks. =20 > > > > Gives me time to re-write them :-) > > > > There is still a bug in the 'align left' code as well. > > snprintf(buf, 21, "%-25s", "abcd") outputs 20 spaces not "abcd" followe= d by 16. > > Easiest fix is to move the truncation in the cb() function. =20 >=20 > Hi David, >=20 > I did a double-check on the `snprintf(buf, 21, "%-25s", "abcd")` case > with the v4 patch. >=20 > In my testing, the output content is actually correct ("abcd" followed > by 16 spaces), > and the return value is 25, which complies with the standard > (representing the length > if the buffer were infinite). I was probably checking a slightly different version where the '-' just caused the truncated "abcd" be output before the pad. >=20 > **However**, you are right to be concerned about the logic. Upon > closer inspection, > I realized there is a potential **buffer overflow risk**. >=20 ... >=20 > Therefore, I am perfectly happy to drop my current left-alignment > patch entirely and > wait for your refactor, as it provides a much safer architecture." I've got it 'mostly rewritten', I'll remove your patches for "%-2s" from the front before I submit them. I'll put that change in early. David