From a1d462a378bebcdb57d628c501fa2c008c7f05a9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 4 Nov 2003 12:06:35 +0000 Subject: [PATCH] Use xsize. --- lib/linebreak.c | 11 +++++++++-- modules/linebreak | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/linebreak.c b/lib/linebreak.c index 8623eb0333..78fb657e62 100644 --- a/lib/linebreak.c +++ b/lib/linebreak.c @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #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; diff --git a/modules/linebreak b/modules/linebreak index 334b96535b..ecf9f59a33 100644 --- a/modules/linebreak +++ b/modules/linebreak @@ -13,6 +13,7 @@ c-ctype iconv utf8-ucs4 utf16-ucs4 +xsize configure.ac: gl_LINEBREAK -- 2.30.2