From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 D4E3C30E82B for ; Tue, 7 Apr 2026 10:46:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775558785; cv=none; b=Ww04JJ/ylaFchH0ubtrIRCJEt2hGq3QzzeUu9XsKIUUyWslryukvb66dP6pg0H+WqR8W5lE81Oxxi2YXzXmef/b80yHgP+7cCgOI2pWdnk/iaUuH05d2zfT3EgCbNljznDmEktn+Kk/vP7V97KxlNRrxIa2SrwUayH7hpfYc+LI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775558785; c=relaxed/simple; bh=jQb2FgSxTFkKKXB7bkzH8fpKIKBP9dpQgrj0EAhmOx0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FRhFei7Hh7jc7Bytesq2uTraYAuiUs1TGvUT7SBwElwQGMZAY7eaDAKwVBxixQX+ALGnvgRG92qmLAcwX+EI8yqTuSM3koJfIV4niSnKF2WJPfAbrNP7buvGfrVVJ3ZcZYSRvWnJZ9S4KKu64Q0m1usK9A3m3/wFlrTVFHWwZ74= 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=Kf9ClR7q; arc=none smtp.client-ip=209.85.128.50 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="Kf9ClR7q" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-488ab2db91aso29478415e9.3 for ; Tue, 07 Apr 2026 03:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775558782; x=1776163582; 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=jIbAzUacWNBjd6xVxdKOVFNbPOG2scaK9qxnSdd5zTE=; b=Kf9ClR7qV9P2C2tRaBsrS+iMAlSJfmJOdFycWXhR1Nkh3UPIgzBYPZMUh60ZYv8iuv r0zIfUN6c/HQS0Mjig81h8p1TyAFsgFMf3q5X6EDD49rBEaelhXok+41f5RxsPeR1TsV VRmAqYDRVkrDoCngp2d9hgGS/yQjOrHZxma5C6oYakkjnn+PTPMJIfpUecQVYSU0fvCs U3fUIO//H4UozvDhTU+gxAt5APUr8XzJea3HN+Jwq9hUAlVs3N9BoFbLr7utNBOnHu0p NSBiKvHW2/hOQzG4scBhJ/fSMdsuSn5QGUgnr7q0aEToBGmvciW948NOk4/OJsjGJirV DCnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775558782; x=1776163582; 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=jIbAzUacWNBjd6xVxdKOVFNbPOG2scaK9qxnSdd5zTE=; b=ILrceHFUCSqUCUDhRG3w3NRK29MJBXPFZHkIpo4W66wUgIojDdbxVQcRXYLegAPtTk Yob1Hatl2LyAfUIaUle69868axECdegEIzP2ajZ/l/xs5xSB5Gl8h/xrrAeW+InE23Qy Xc1QiLWkV2OHrrr4MQEjKEau2aWNmkrIox8KP7u7wofP7guThJTjyjX2tL6MtiIkgbl+ VQ+JiPOKpsXP6PipAWV9mlQBKOHpahzZzg8GpXnr/PvSf2ociABgzKMSwykiQ46e9kGa 8fZNo7BlqlD90y/orvCwgRBzP5dtMQyBfFoEGlpbbs32y1jB8J4rD3Ia0YK7fUvPtWWg EpxQ== X-Forwarded-Encrypted: i=1; AJvYcCUH7mhS0TrJn1R0vV3woEzA5h4frlMNssbVT8QtezefwUStyzSY27ZfOxB5d89tK+Msf5PJF/iLvwyIwOY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3TEen28BMhZN3jS1jhKxYIqUiamEoovvJZUZRS18LlZxWfBfr JcqSJSY6mbuji8ksVdvnR+SPz21J0I7dQs8w8pF3dx7Uzg8nG56+HhsA X-Gm-Gg: AeBDietQZtT8W6I0NTiFspKRF6lmLz1H0D+FZSZuWZCLr9PyF5bSitugrwHXha3Lxul eXa6eud/91fEAHri6oVCxTBRwXOFhiJNfBFu39//Ujc9lm+ag10kgk1kqV6bxjqzfarXghTRHYM LPKSZgY0pcOCdBBwTrSBCEmXMNpLFztBqwEtQ2r23dmi+43lvVjFy7zIaKFX4wASXCKlbU6eho8 hSINfpGGRPP9oxqb8rlRxnJfbZSIIMb+W+uqOZFVlHP4qkztZu7LGZ7GJW+P4GCuUQl2pXcBbJB 129iuST1enQxkJyNFr7+M/zecm1MNBdAbN+iyQaBCdPwEEXkYMKNP6ECNx3HFk4kHiKcCTrmi9z k+A3vupgBR2bZXWDYzEzRYScMtwplXxVHRwlxdMVQTerezJpjL4M8IohDt+ft7V3n7YqPYQFhB2 UBbnYVJ++GBUtp/u8YZ3Z1SZA/PkqdpOeU6w++nAQk6d2cJ9Pvbt9H4BGY6WHqXRjN X-Received: by 2002:a05:600c:4e86:b0:486:fba7:b150 with SMTP id 5b1f17b1804b1-488997c9b9bmr203160575e9.15.1775558781745; Tue, 07 Apr 2026 03:46:21 -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 5b1f17b1804b1-4888a65635fsm434305295e9.6.2026.04.07.03.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 03:46:21 -0700 (PDT) Date: Tue, 7 Apr 2026 11:46:20 +0100 From: David Laight To: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= Cc: Willy Tarreau , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] tools/nolibc: add support for asprintf() Message-ID: <20260407114620.40f02441@pumpkin> In-Reply-To: <4dba6ad1-b151-4234-98b1-9b7269768def@t-8ch.de> References: <20260401-nolibc-asprintf-v1-0-46292313439f@weissschuh.net> <20260401-nolibc-asprintf-v1-3-46292313439f@weissschuh.net> <20260404163459.7cbe9d24@pumpkin> <4dba6ad1-b151-4234-98b1-9b7269768def@t-8ch.de> 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, 5 Apr 2026 17:39:22 +0200 Thomas Wei=C3=9Fschuh wrote: > On 2026-04-04 16:34:59+0100, David Laight wrote: > > On Wed, 01 Apr 2026 17:07:29 +0200 > > Thomas Wei=C3=9Fschuh wrote: > > =20 > > > Add support for dynamically allocating formatted strings through > > > asprintf() and vasprintf(). > > >=20 > > > Signed-off-by: Thomas Wei=C3=9Fschuh > > > --- > > > tools/include/nolibc/stdio.h | 50 ++++++++++++++++++= ++++++++++ > > > tools/testing/selftests/nolibc/nolibc-test.c | 24 +++++++++++++ > > > 2 files changed, 74 insertions(+) > > >=20 > > > diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdi= o.h > > > index 8f7e1948a651..1c9287b558f0 100644 > > > --- a/tools/include/nolibc/stdio.h > > > +++ b/tools/include/nolibc/stdio.h > > > @@ -787,6 +787,56 @@ int sprintf(char *buf, const char *fmt, ...) > > > return ret; > > > } > > > =20 > > > +static __attribute__((unused, format(printf, 2, 0))) > > > +int __nolibc_vasprintf(char **strp, const char *fmt, va_list args1, = va_list args2) > > > +{ > > > + char *buf; > > > + int len; > > > + > > > + len =3D vsnprintf(NULL, 0, fmt, args1); > > > + if (len < 0) > > > + return -1; =20 > >=20 > > vsnprintf() can never fail. =20 >=20 > The one in nolibc not, according to the specification it could. > So to be on the safe side, also against future changes in nolibc > I'd like to keep the check. > The asnprintf()/malloc() implementation will make any performance > considerations moot anyways. While a -1 return value from vsnprintf() would indicate a failure, there are no conditions where that can happen. The man page (and I think posix/sus) has a common page with fprintf() and the only error is: If an output error is encountered, a negative value is returned. which can't happen for the 's' variants. In particular there is nothing at all about invalid formats. Perhaps just a comment that says it can't fail. David