#include <stdlib.h>
#include <string.h>
#include "c-ctype.h"
+#include "xsize.h"
#include "utf8-ucs4.h"
{
/* 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;
{
/* 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;