From 736221f1b2c37cdcd5073d269484b4f1cf7a4e36 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Tue, 26 May 2009 14:31:37 +0000 Subject: Make vsprintf reentrant. More importantly, eliminate global variable. Signed-off-by: Patrick Georgi Acked-by: Myles Watson git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4307 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- src/console/vsprintf.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/console') diff --git a/src/console/vsprintf.c b/src/console/vsprintf.c index 1ce6bd1e88..1cfb91f02c 100644 --- a/src/console/vsprintf.c +++ b/src/console/vsprintf.c @@ -13,22 +13,22 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args); -/* FIXME this global makes vsprintf non-reentrant */ - -static char *str_buf; -static void str_tx_byte(unsigned char byte) -{ - *str_buf = byte; - str_buf++; -} - int vsprintf(char * buf, const char *fmt, va_list args) { + char *str_buf; + + /* this function is only used by vsprint. + To keep str_buf local (for reentrancy + and to avoid .bss use, nest it */ + void str_tx_byte(unsigned char byte) + { + *str_buf = byte; + str_buf++; + } + int i; str_buf = buf; i = vtxprintf(str_tx_byte, fmt, args); - /* maeder/Ispiri -- The null termination was missing a deference */ - /* and was just zeroing out the pointer instead */ *str_buf = '\0'; return i; } -- cgit v1.2.3