Author: cazfi
Date: Wed Jun 24 22:32:38 2015
New Revision: 29186

URL: http://svn.gna.org/viewcvs/freeciv?rev=29186&view=rev
Log:
Make string comparison buffers big enough for using UChar based strings.

Reported by Jacob Nevins <jtn>

See bug #23616

Modified:
    trunk/utility/support.c

Modified: trunk/utility/support.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/support.c?rev=29186&r1=29185&r2=29186&view=diff
==============================================================================
--- trunk/utility/support.c     (original)
+++ trunk/utility/support.c     Wed Jun 24 22:32:38 2015
@@ -108,7 +108,7 @@
 
 #include "support.h"
 
-static int cmp_buffer_size = 0;
+static int cmp_buffer_uchars = 0;
 static UChar *cmp_buffer0 = NULL;
 static UChar *cmp_buffer1 = NULL;
 
@@ -118,13 +118,13 @@
 static void cmp_buffers_initial(void)
 {
   if (cmp_buffer0 == NULL) {
-    cmp_buffer_size = 255;
-    cmp_buffer0 = fc_malloc(cmp_buffer_size + 1);
-    cmp_buffer1 = fc_malloc(cmp_buffer_size + 1);
-
-    /* Make sure there's zero after the buffer published with cmp_buffer_size 
*/
-    cmp_buffer0[cmp_buffer_size] = '\0';
-    cmp_buffer1[cmp_buffer_size] = '\0';
+    cmp_buffer_uchars = 255;
+    cmp_buffer0 = fc_malloc((cmp_buffer_uchars + 1) * sizeof(UChar));
+    cmp_buffer1 = fc_malloc((cmp_buffer_uchars + 1) * sizeof(UChar));
+
+    /* Make sure there's zero after the buffer published with 
cmp_buffer_uchars */
+    memset(cmp_buffer0 + cmp_buffer_uchars * sizeof(UChar), 0, sizeof(UChar));
+    memset(cmp_buffer1 + cmp_buffer_uchars * sizeof(UChar), 0, sizeof(UChar));
   }
 }
 
@@ -133,13 +133,13 @@
 ***************************************************************/
 static void cmp_buffers_increase(void)
 {
-  cmp_buffer_size *= 1.5;
-  cmp_buffer0 = fc_realloc(cmp_buffer0, cmp_buffer_size + 1);
-  cmp_buffer1 = fc_realloc(cmp_buffer1, cmp_buffer_size + 1);
-
-  /* Make sure there's zero after the buffer published with cmp_buffer_size */
-  cmp_buffer0[cmp_buffer_size] = '\0';
-  cmp_buffer1[cmp_buffer_size] = '\0';
+  cmp_buffer_uchars *= 1.5;
+  cmp_buffer0 = fc_realloc(cmp_buffer0, (cmp_buffer_uchars + 1) * 
sizeof(UChar));
+  cmp_buffer1 = fc_realloc(cmp_buffer1, (cmp_buffer_uchars + 1) * 
sizeof(UChar));
+
+  /* Make sure there's zero after the buffer published with cmp_buffer_uchars 
*/
+  memset(cmp_buffer0 + cmp_buffer_uchars * sizeof(UChar), 0, sizeof(UChar));
+  memset(cmp_buffer1 + cmp_buffer_uchars * sizeof(UChar), 0, sizeof(UChar));
 }
 
 /***************************************************************
@@ -152,7 +152,7 @@
     cmp_buffer0 = NULL;
     free(cmp_buffer1);
     cmp_buffer1 = NULL;
-    cmp_buffer_size = 0;
+    cmp_buffer_uchars = 0;
   }
 }
 
@@ -179,8 +179,8 @@
     UErrorCode err_code0 = U_ZERO_ERROR;
     UErrorCode err_code1 = U_ZERO_ERROR;
 
-    u_strFromUTF8(cmp_buffer0, cmp_buffer_size, &len0, str0, -1, &err_code0);
-    u_strFromUTF8(cmp_buffer1, cmp_buffer_size, &len1, str1, -1, &err_code1);
+    u_strFromUTF8(cmp_buffer0, cmp_buffer_uchars, &len0, str0, -1, &err_code0);
+    u_strFromUTF8(cmp_buffer1, cmp_buffer_uchars, &len1, str1, -1, &err_code1);
 
     /* No need to handle U_STRING_NOT_TERMINATED_WARNING here as there's '0' 
after
      * the buffers we were using */
@@ -219,8 +219,8 @@
     UErrorCode err_code0 = U_ZERO_ERROR;
     UErrorCode err_code1 = U_ZERO_ERROR;
 
-    u_strFromUTF8(cmp_buffer0, cmp_buffer_size, &len0, str0, -1, &err_code0);
-    u_strFromUTF8(cmp_buffer1, cmp_buffer_size, &len1, str1, -1, &err_code1);
+    u_strFromUTF8(cmp_buffer0, cmp_buffer_uchars, &len0, str0, -1, &err_code0);
+    u_strFromUTF8(cmp_buffer1, cmp_buffer_uchars, &len1, str1, -1, &err_code1);
 
     /* No need to handle U_STRING_NOT_TERMINATED_WARNING here as there's '0' 
after
      * the buffers we were using */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to