* [PATCH 1/2] fixup! stdio: stub out basprintf and friends when built for PBL
@ 2024-12-02 11:37 Ahmad Fatoum
2024-12-02 11:37 ` [PATCH 2/2] " Ahmad Fatoum
2024-12-02 12:37 ` [PATCH 1/2] " Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-12-02 11:37 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
asprintf and vasprintf return only -1 as error code, so have the stub
follow suit for symmetry.
No functional change expected.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/stdio.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/stdio.h b/include/stdio.h
index 03cd3d281890..883b06529fdc 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -32,7 +32,7 @@ static inline char *basprintf(const char *fmt, ...)
}
static inline int asprintf(char **strp, const char *fmt, ...)
{
- return -ENOMEM;
+ return -1;
}
static inline char *bvasprintf(const char *fmt, va_list ap)
{
@@ -40,7 +40,7 @@ static inline char *bvasprintf(const char *fmt, va_list ap)
}
static inline int vasprintf(char **strp, const char *fmt, va_list ap)
{
- return -ENOMEM;
+ return -1;
}
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] fixup! stdio: stub out basprintf and friends when built for PBL
2024-12-02 11:37 [PATCH 1/2] fixup! stdio: stub out basprintf and friends when built for PBL Ahmad Fatoum
@ 2024-12-02 11:37 ` Ahmad Fatoum
2024-12-02 12:37 ` [PATCH 1/2] " Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-12-02 11:37 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] fixup! stdio: stub out basprintf and friends when built for PBL
2024-12-02 11:37 [PATCH 1/2] fixup! stdio: stub out basprintf and friends when built for PBL Ahmad Fatoum
2024-12-02 11:37 ` [PATCH 2/2] " Ahmad Fatoum
@ 2024-12-02 12:37 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-12-02 12:37 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Dec 02, 2024 at 12:37:28PM +0100, Ahmad Fatoum wrote:
> asprintf and vasprintf return only -1 as error code, so have the stub
> follow suit for symmetry.
>
> No functional change expected.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> include/stdio.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/include/stdio.h b/include/stdio.h
> index 03cd3d281890..883b06529fdc 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -32,7 +32,7 @@ static inline char *basprintf(const char *fmt, ...)
> }
> static inline int asprintf(char **strp, const char *fmt, ...)
> {
> - return -ENOMEM;
> + return -1;
> }
> static inline char *bvasprintf(const char *fmt, va_list ap)
> {
> @@ -40,7 +40,7 @@ static inline char *bvasprintf(const char *fmt, va_list ap)
> }
> static inline int vasprintf(char **strp, const char *fmt, va_list ap)
> {
> - return -ENOMEM;
> + return -1;
> }
> #endif
>
> --
> 2.39.5
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-02 12:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-02 11:37 [PATCH 1/2] fixup! stdio: stub out basprintf and friends when built for PBL Ahmad Fatoum
2024-12-02 11:37 ` [PATCH 2/2] " Ahmad Fatoum
2024-12-02 12:37 ` [PATCH 1/2] " Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox