Use xsize.
authorBruno Haible <bruno@clisp.org>
Tue, 4 Nov 2003 12:06:35 +0000 (12:06 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 4 Nov 2003 12:06:35 +0000 (12:06 +0000)
lib/linebreak.c
modules/linebreak

index 8623eb0333e7f61a58d0fed85a243fd77bbff4c9..78fb657e6215b329464f5f5d8651c9845e501073 100644 (file)
@@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include <stdlib.h>
 #include <string.h>
 #include "c-ctype.h"
+#include "xsize.h"
 
 #include "utf8-ucs4.h"
 
@@ -1519,7 +1520,9 @@ mbs_possible_linebreaks (const char *s, size_t n, const char *encoding,
             {
               /* 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 @@ mbs_width_linebreaks (const char *s, size_t n,
             {
               /* 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;
index 334b96535b1d3231657beaf2ea4ecea1cca28086..ecf9f59a335920c1dafd38865f27b47e7437d1ee 100644 (file)
@@ -13,6 +13,7 @@ c-ctype
 iconv
 utf8-ucs4
 utf16-ucs4
+xsize
 
 configure.ac:
 gl_LINEBREAK