changeset 4853:5d25a00a8502

Use xsize.
author Bruno Haible <bruno@clisp.org>
date Tue, 04 Nov 2003 12:06:35 +0000
parents 7f909e1de364
children 99f086003300
files lib/linebreak.c modules/linebreak
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lib/linebreak.c
+++ b/lib/linebreak.c
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "c-ctype.h"
+#include "xsize.h"
 
 #include "utf8-ucs4.h"
 
@@ -1519,7 +1520,9 @@
             {
               /* Convert the string to UTF-8 and build a translation table
                  from offsets into s to offsets into the translated string.  */
-              char *memory = malloc (n * sizeof (size_t) + m + m);
+	      size_t memory_size = xsum3 (xtimes (n, sizeof (size_t)), m, m);
+              char *memory =
+		(size_in_bounds_p (memory_size) ? malloc (memory_size) : NULL);
               if (memory != NULL)
                 {
                   size_t *offtable = (size_t *) memory;
@@ -1612,7 +1615,11 @@
             {
               /* Convert the string to UTF-8 and build a translation table
                  from offsets into s to offsets into the translated string.  */
-              char *memory = malloc (n * sizeof (size_t) + m + m + (o != NULL ? m : 0));
+	      size_t memory_size =
+		xsum4 (xtimes (n, sizeof (size_t)), m, m,
+		       (o != NULL ? m : 0));
+	      char *memory =
+		(size_in_bounds_p (memory_size) ? malloc (memory_size) : NULL);
               if (memory != NULL)
                 {
                   size_t *offtable = (size_t *) memory;
--- a/modules/linebreak
+++ b/modules/linebreak
@@ -13,6 +13,7 @@
 iconv
 utf8-ucs4
 utf16-ucs4
+xsize
 
 configure.ac:
 gl_LINEBREAK