gutf8: use g_try_malloc_n
authorMarc-André Lureau <marcandre.lureau@gmail.com>
Tue, 26 Nov 2013 16:45:37 +0000 (17:45 +0100)
committerMarc-André Lureau <marcandre.lureau@gmail.com>
Tue, 3 Dec 2013 14:56:47 +0000 (15:56 +0100)
As recommended by Christian Persch.

https://bugzilla.gnome.org/show_bug.cgi?id=711546

glib/gutf8.c

index 149eeef..1f6e359 100644 (file)
@@ -777,9 +777,9 @@ g_utf8_to_ucs4_fast (const gchar *str,
 }
 
 static gpointer
-try_malloc (gsize n_bytes, GError **error)
+try_malloc_n (gsize n_blocks, gsize n_block_bytes, GError **error)
 {
-    gpointer ptr = g_try_malloc (n_bytes);
+    gpointer ptr = g_try_malloc_n (n_blocks, n_block_bytes);
     if (ptr == NULL)
       g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_MEMORY,
                            _("Failed to allocate memory"));
@@ -850,7 +850,7 @@ g_utf8_to_ucs4 (const gchar *str,
       in = g_utf8_next_char (in);
     }
 
-  result = try_malloc (sizeof (gunichar) * (n_chars + 1), error);
+  result = try_malloc_n (n_chars + 1, sizeof (gunichar), error);
   if (result == NULL)
       goto err_out;
 
@@ -923,7 +923,7 @@ g_ucs4_to_utf8 (const gunichar *str,
       result_length += UTF8_LENGTH (str[i]);
     }
 
-  result = try_malloc (result_length + 1, error);
+  result = try_malloc_n (result_length + 1, 1, error);
   if (result == NULL)
       goto err_out;
 
@@ -1058,7 +1058,7 @@ g_utf16_to_utf8 (const gunichar2  *str,
   /* At this point, everything is valid, and we just need to convert
    */
   /********** DIFFERENT for UTF8/UCS4 **********/
-  result = try_malloc (n_bytes + 1, error);
+  result = try_malloc_n (n_bytes + 1, 1, error);
   if (result == NULL)
       goto err_out;
 
@@ -1197,7 +1197,7 @@ g_utf16_to_ucs4 (const gunichar2  *str,
   /* At this point, everything is valid, and we just need to convert
    */
   /********** DIFFERENT for UTF8/UCS4 **********/
-  result = try_malloc (n_bytes + 4, error);
+  result = try_malloc_n (n_bytes + 4, 1, error);
   if (result == NULL)
       goto err_out;
 
@@ -1329,7 +1329,7 @@ g_utf8_to_utf16 (const gchar *str,
       in = g_utf8_next_char (in);
     }
 
-  result = try_malloc (sizeof (gunichar2) * (n16 + 1), error);
+  result = try_malloc_n (n16 + 1, sizeof (gunichar2), error);
   if (result == NULL)
       goto err_out;
 
@@ -1427,7 +1427,7 @@ g_ucs4_to_utf16 (const gunichar  *str,
       i++;
     }
 
-  result = try_malloc (sizeof (gunichar2) * (n16 + 1), error);
+  result = try_malloc_n (n16 + 1, sizeof (gunichar2), error);
   if (result == NULL)
       goto err_out;