Merged silc_1_0_branch to trunk.
[silc.git] / lib / silcutil / silcbuffmt.c
index 4fffb7c34d87b7144f9007c921453c97b9e2dfe0..23653c4b0614c77128cea7cdb8e5744f000f9fb3 100644 (file)
@@ -4,12 +4,11 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2002 Pekka Riikonen
+  Copyright (C) 1997 - 2005 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
+  the Free Software Foundation; version 2 of the License.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -524,7 +523,7 @@ int silc_buffer_strformat(SilcBuffer dst, ...)
 
   /* Parse the arguments by formatting type. */
   while(1) {
-    char *string = va_arg(va, char *);
+    char *string = (char *)va_arg(va, void *);
 
     if (!string)
       continue;
@@ -532,9 +531,12 @@ int silc_buffer_strformat(SilcBuffer dst, ...)
       goto ok;
 
     dst->head = silc_realloc(dst->head, sizeof(*dst->head) *
-                            (strlen(string) + len));
+                            (strlen(string) + len + 1));
+    if (!dst->head)
+      return -1;
     memcpy(dst->head + len, string, strlen(string));
     len += strlen(string);
+    dst->head[len] = '\0';
   }
 
   SILC_LOG_DEBUG(("Error occured while formatting buffer"));
@@ -543,9 +545,9 @@ int silc_buffer_strformat(SilcBuffer dst, ...)
 
  ok:
   dst->end = dst->head + len;
-  dst->tail = dst->data = dst->end;
-  dst->len = 0;
-  dst->truelen = len;
+  dst->data = dst->head;
+  dst->tail = dst->end;
+  dst->len = dst->truelen = len;
 
   va_end(va);
   return len;