Less than 12% of all our basprintf callsites actually bother to check for allocation failure. It's highly unlikely that barebox will be able to function when the heap is so full that the usually small basprintf requests fail. Therefore, make basprintf an alias for xasprintf, so barebox panics on OOM instead of possibly triggering undefined behavior. Users doing big allocations with basprintf and wishing to handle their failure should switch over to asprintf instead. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- include/stdio.h | 8 +++----- lib/vsprintf.c | 17 ----------------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index c02d383d6bad..0e01a0e63a46 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -5,6 +5,7 @@ #include <stdarg.h> #include <console.h> #include <printf.h> +#include <xfuncs.h> /* * STDIO based functions (can always be used) @@ -21,15 +22,10 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); #if IN_PROPER || defined(CONFIG_PBL_CONSOLE) -char *basprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); int asprintf(char **strp, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); char *bvasprintf(const char *fmt, va_list ap); int vasprintf(char **strp, const char *fmt, va_list ap); #else -static inline char *basprintf(const char *fmt, ...) -{ - return NULL; -} static inline int asprintf(char **strp, const char *fmt, ...) { return -1; @@ -44,6 +40,8 @@ static inline int vasprintf(char **strp, const char *fmt, va_list ap) } #endif +#define basprintf xasprintf + #ifdef CONFIG_ARCH_HAS_CTRLC int arch_ctrlc(void); #endif diff --git a/lib/vsprintf.c b/lib/vsprintf.c index cb42caebca16..9d3c7e09f08a 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -978,20 +978,3 @@ int asprintf(char **strp, const char *fmt, ...) return len; } EXPORT_SYMBOL(asprintf); - -char *basprintf(const char *fmt, ...) -{ - va_list ap; - char *p; - int len; - - va_start(ap, fmt); - len = vasprintf(&p, fmt, ap); - va_end(ap); - - if (len < 0) - return NULL; - - return p; -} -EXPORT_SYMBOL(basprintf); -- 2.39.5