Merged silc_1_1_branch to trunk.
[silc.git] / lib / silcutil / silcbuffmt.c
index 562af7d86501524808c3c596e11645fa77b412cc..bbb923e84a77a8e436cfe9a725db83cd872dc560 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2006 Pekka Riikonen
+  Copyright (C) 1997 - 2007 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
@@ -116,10 +116,12 @@ int silc_buffer_sformat_vp(SilcStack stack, SilcBuffer dst, va_list ap)
     case SILC_PARAM_UI32_STRING_ALLOC:
       {
        unsigned char *x = va_arg(ap, unsigned char *);
-       SilcUInt32 tmp_len = strlen(x);
-       FORMAT_HAS_SPACE(stack, dst, tmp_len);
-       silc_buffer_put(dst, x, tmp_len);
-       silc_buffer_pull(dst, tmp_len);
+       SilcUInt32 tmp_len = x ? strlen(x) : 0;
+       if (x && tmp_len) {
+         FORMAT_HAS_SPACE(stack, dst, tmp_len);
+         silc_buffer_put(dst, x, tmp_len);
+         silc_buffer_pull(dst, tmp_len);
+       }
        break;
       }
     case SILC_PARAM_UI8_NSTRING:
@@ -745,8 +747,8 @@ int silc_buffer_sstrformat(SilcStack stack, SilcBuffer dst, ...)
       goto ok;
 
     slen = strlen(string);
-    d = silc_srealloc_ua(stack, len + 1, dst->head,
-                        sizeof(*dst->head) * (slen + len + 1));
+    d = silc_srealloc(stack, len + 1, dst->head,
+                     sizeof(*dst->head) * (slen + len + 1));
     if (silc_unlikely(!d))
       return -1;
     dst->head = d;