[coreboot] [v2] r4307 - trunk/coreboot-v2/src/console

svn at coreboot.org svn at coreboot.org
Tue May 26 16:31:38 CEST 2009


Author: oxygene
Date: 2009-05-26 16:31:37 +0200 (Tue, 26 May 2009)
New Revision: 4307

Modified:
   trunk/coreboot-v2/src/console/vsprintf.c
Log:
Make vsprintf reentrant. More importantly, eliminate global variable.

Signed-off-by: Patrick Georgi <patrick.georgi at coresystems.de>
Acked-by: Myles Watson <mylesgw at gmail.com>


Modified: trunk/coreboot-v2/src/console/vsprintf.c
===================================================================
--- trunk/coreboot-v2/src/console/vsprintf.c	2009-05-26 14:07:44 UTC (rev 4306)
+++ trunk/coreboot-v2/src/console/vsprintf.c	2009-05-26 14:31:37 UTC (rev 4307)
@@ -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)
+int vsprintf(char * buf, const char *fmt, va_list args)
 {
-	*str_buf = byte;
-	str_buf++;
-}
+	char *str_buf;
 
-int vsprintf(char * buf, const char *fmt, va_list args)
-{
+	/* 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;
 }





More information about the coreboot mailing list