mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] fixup! stdio: stub out basprintf and friends when built for PBL
Date: Mon,  2 Dec 2024 12:37:29 +0100	[thread overview]
Message-ID: <20241202113729.599540-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241202113729.599540-1-a.fatoum@pengutronix.de>

vsprintf: fix false positive about use of uninitialized variable

barebox vasprintf only writes to its strp argument, when a buffer could
be allocated. If out of memory (or in PBL without malloc), -1 is
returned after vsnprintf determines the length.

GCC 13.1.1 seems not able to track use of strp across vsnprintf
correctly though resulting in a bogus warning:

  ./lib/vsprintf.c: In function 'bvasprintf':
  ./lib/vsprintf.c:961:16: warning: 'p' may be used uninitialized
                           [-Wmaybe-uninitialized]
    961 |         return p;
        |                ^

Fix this by adding an explicit early exit for the PBL case.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/vsprintf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index e421a4352a12..edc3f4aa4fe0 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -933,6 +933,10 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
 	va_list aq;
 	char *p;
 
+	/* Silence -Wmaybe-uninitialized false positive */
+	if (IN_PBL)
+		return -1;
+
 	va_copy(aq, ap);
 	len = vsnprintf(NULL, 0, fmt, aq);
 	va_end(aq);
-- 
2.39.5




  reply	other threads:[~2024-12-02 11:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-02 11:37 [PATCH 1/2] " Ahmad Fatoum
2024-12-02 11:37 ` Ahmad Fatoum [this message]
2024-12-02 12:37 ` Sascha Hauer

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=20241202113729.599540-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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