changeset 100:ed4067c10a8a

Remove useless buffer usage from error reporting function.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 17 Nov 2009 23:09:10 +0200
parents 0313fabd8049
children 7eaf065f7a65
files nnchat.c
diffstat 1 files changed, 18 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Tue Nov 17 23:08:15 2009 +0200
+++ b/nnchat.c	Tue Nov 17 23:09:10 2009 +0200
@@ -282,10 +282,9 @@
 }
 
 
-void printMsg(char *fmt, ...)
+void printMsgV(const char *fmt, va_list ap)
 {
     char tmpStr[128] = "", buf[8192];
-    va_list ap;
     time_t timeStamp;
     struct tm *tmpTime;;
     
@@ -294,9 +293,7 @@
         strftime(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ ", tmpTime);
     }
     
-    va_start(ap, fmt);
     vsnprintf(buf, sizeof(buf), fmt, ap);
-    va_end(ap);
     
     if (optLogFile) {
         printFile(optLogFile, tmpStr);
@@ -311,18 +308,27 @@
     }
 }
 
+void printMsg(const char *fmt, ...)
+{
+    va_list ap;
+    
+    va_start(ap, fmt);
+    printMsgV(fmt, ap);
+    va_end(ap);
+}
+
 
 void errorMsg(char *fmt, ...)
 {
-    char buf[8192];
-    va_list ap;
+    va_list ap1, ap2;
 
-    va_start(ap, fmt);
-    vsnprintf(buf, sizeof(buf), fmt, ap);
-    va_end(ap);
+    va_start(ap1, fmt);
+    va_copy(ap2, ap1);
+    printMsgV(fmt, ap1);
+    va_end(ap1);
 
-    printMsg(buf);
-    THERR(buf);
+    THERR_V(fmt, ap2);
+    va_end(ap2);
 }
 
 
@@ -645,7 +651,6 @@
     }
     THMSG(2, "True hostname: %s\n", tmpHost->h_name);
 
-
 #if 1
     /* To emulate the official client, we first make a request for
      * policy file, even though we don't use it for anything...
@@ -724,7 +729,7 @@
         printEditBuf("", editBuf);
         updateStatus(insertMode);
     }
-    
+
     /* Enter mainloop */
     prevTime = time(NULL);
     FD_ZERO(&sockfds);