[PATCH 2/2] fixup! stdio: stub out basprintf and friends when built for PBL
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Dec 2 03:37:29 PST 2024
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 at 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
More information about the barebox
mailing list