Created SILC Runtime Toolkit git repository Part II.
[runtime.git] / lib / silcutil / silcstringprep.c
index aa2119e5208898971ff06ed821dbd20b1a5f47d6..96cc9cbd7245a73b44b493d8869ceb20f25b0d6b 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2004 - 2005 Pekka Riikonen
+  Copyright (C) 2004 - 2008 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
@@ -17,9 +17,8 @@
 
 */
 
-#include "silcincludes.h"
-#include "silcstringprep.h"
-#include <stringprep.h>
+#include "silcruntime.h"
+#include "stringprep.h"
 
 /* We use GNU Libidn which has stringprep to do the magic.  Only bad thing
    is that its interface is idiotic.  We have our own API here in case
@@ -186,7 +185,7 @@ silc_stringprep(const unsigned char *bin, SilcUInt32 bin_len,
     f |= STRINGPREP_NO_UNASSIGNED;
 
   /* Prepare */
-  ret = stringprep((char *)utf8s, utf8s_len + 1, f, profile);
+  ret = stringprep((char *)utf8s, utf8s_len, f, profile);
   SILC_LOG_DEBUG(("stringprep() return %d", ret));
 
   /* Since the stringprep() doesn't allocate returned buffer, and
@@ -194,10 +193,10 @@ silc_stringprep(const unsigned char *bin, SilcUInt32 bin_len,
      much space we must have for the conversion.  Allocate more if it
      fails, and try again. */
   if (ret == STRINGPREP_TOO_SMALL_BUFFER) {
-    utf8s = silc_realloc(utf8s, sizeof(*utf8s) * (utf8s_len * 2));
+    utf8s = silc_realloc(utf8s, sizeof(*utf8s) * ((utf8s_len * 2) + 1));
     if (!utf8s)
       return SILC_STRINGPREP_ERR_OUT_OF_MEMORY;
-    memset(utf8s + utf8s_len, 0, utf8s_len);
+    memset(utf8s + utf8s_len + 1, 0, utf8s_len);
     ret = stringprep((char *)utf8s, utf8s_len * 2, f, profile);
     SILC_LOG_DEBUG(("stringprep() return %d", ret));
   }