[sword-svn] r3590 - in trunk: include src/frontend src/utilfuns

scribe at crosswire.org scribe at crosswire.org
Sun Jun 17 09:33:36 MST 2018


Author: scribe
Date: 2018-06-17 09:33:36 -0700 (Sun, 17 Jun 2018)
New Revision: 3590

Modified:
   trunk/include/swbuf.h
   trunk/src/frontend/swlog.cpp
   trunk/src/utilfuns/swbuf.cpp
Log:
updated SWLog to use SWBuf instead of fixed length buffer

Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h	2018-06-17 16:33:13 UTC (rev 3589)
+++ trunk/include/swbuf.h	2018-06-17 16:33:36 UTC (rev 3590)
@@ -26,6 +26,7 @@
 #include <defs.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdarg.h>
 #ifdef __BORLANDC__
 #include <mem.h>
 #endif
@@ -228,6 +229,7 @@
 	* @param ... Add all arguments here.
 	*/
 	SWBuf &setFormatted(const char *format, ...);
+	SWBuf &setFormattedVA(const char *format, va_list argptr);
 
 	/**
 	* SWBuf::setSize - Size this buffer to a specific length.

Modified: trunk/src/frontend/swlog.cpp
===================================================================
--- trunk/src/frontend/swlog.cpp	2018-06-17 16:33:13 UTC (rev 3589)
+++ trunk/src/frontend/swlog.cpp	2018-06-17 16:33:36 UTC (rev 3590)
@@ -29,6 +29,7 @@
 #include <unicode/ustream.h>
 #endif
 #include "swlog.h"
+#include "swbuf.h"
 
 
 SWORD_NAMESPACE_START
@@ -64,12 +65,12 @@
 
 
 void SWLog::logWarning(const char *fmt, ...) const {
-	char msg[2048];
 	va_list argptr;
 
 	if (logLevel >= LOG_WARN) {
+		SWBuf msg;
 		va_start(argptr, fmt);
-		vsprintf(msg, fmt, argptr);
+		msg.setFormattedVA(fmt, argptr);
 		va_end(argptr);
 		logMessage(msg, LOG_WARN);
 	}
@@ -77,12 +78,12 @@
 
 
 void SWLog::logError(const char *fmt, ...) const {
-	char msg[2048];
 	va_list argptr;
 
 	if (logLevel) {
+		SWBuf msg;
 		va_start(argptr, fmt);
-		vsprintf(msg, fmt, argptr);
+		msg.setFormattedVA(fmt, argptr);
 		va_end(argptr);
 		logMessage(msg, LOG_ERROR);
 	}
@@ -90,12 +91,12 @@
 
 
 void SWLog::logInformation(const char *fmt, ...) const {
-	char msg[2048];
 	va_list argptr;
 
 	if (logLevel >= LOG_INFO) {
+		SWBuf msg;
 		va_start(argptr, fmt);
-		vsprintf(msg, fmt, argptr);
+		msg.setFormattedVA(fmt, argptr);
 		va_end(argptr);
 		logMessage(msg, LOG_INFO);
 	}
@@ -103,12 +104,12 @@
 
 
 void SWLog::logTimedInformation(const char *fmt, ...) const {
-	char msg[2048];
 	va_list argptr;
 
 	if (logLevel >= LOG_TIMEDINFO) {
+		SWBuf msg;
 		va_start(argptr, fmt);
-		vsprintf(msg, fmt, argptr);
+		msg.setFormattedVA(fmt, argptr);
 		va_end(argptr);
 		logMessage(msg, LOG_TIMEDINFO);
 	}
@@ -116,12 +117,12 @@
 
 
 void SWLog::logDebug(const char *fmt, ...) const {
-	char msg[2048];
 	va_list argptr;
 
 	if (logLevel >= LOG_DEBUG) {
+		SWBuf msg;
 		va_start(argptr, fmt);
-		vsprintf(msg, fmt, argptr);
+		msg.setFormattedVA(fmt, argptr);
 		va_end(argptr);
 		logMessage(msg, LOG_DEBUG);
 	}

Modified: trunk/src/utilfuns/swbuf.cpp
===================================================================
--- trunk/src/utilfuns/swbuf.cpp	2018-06-17 16:33:13 UTC (rev 3589)
+++ trunk/src/utilfuns/swbuf.cpp	2018-06-17 16:33:36 UTC (rev 3590)
@@ -50,17 +50,25 @@
 	va_list argptr;
 
 	va_start(argptr, format);
+
+	setFormattedVA(format, argptr);
+
+	va_end(argptr);
+	return *this;
+}
+
+SWBuf &SWBuf::setFormattedVA(const char *format, va_list argptr) {
+	va_list argptr2;
+	va_copy(argptr2, argptr);
 #ifdef NO_VSNPRINTF
 	static char junkBuf[JUNKBUFSIZE];
 	int len = vsprintf(junkBuf, format, argptr)+1;
 #else
 	int len = vsnprintf(0, 0, format, argptr)+1;
 #endif
-	va_end(argptr);
 	assureSize(len);
-	va_start(argptr, format);
-	end = vsprintf(buf, format, argptr) + buf;
-	va_end(argptr);
+	end = vsprintf(buf, format, argptr2) + buf;
+	va_end(argptr2);
 	return *this;
 }
 




More information about the sword-cvs mailing list