emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master ad2c81082a6 4/4: Prefer C23 ckd_* to Gnulib *_WRAPV and *_OK macr


From: Paul Eggert
Subject: master ad2c81082a6 4/4: Prefer C23 ckd_* to Gnulib *_WRAPV and *_OK macros
Date: Sun, 28 Jan 2024 03:27:01 -0500 (EST)

branch: master
commit ad2c81082a62f9f781e4f5771fc223520d91cefd
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    Prefer C23 ckd_* to Gnulib *_WRAPV and *_OK macros
    
    * src/alloc.c (android_make_lisp_symbol) [HAVE_ANDROID && !__clang__]:
    * src/android.c (android_blit_copy, android_blit_xor)
    (android_get_image):
    * src/androidmenu.c (android_menu_show):
    * src/androidselect.c (Fandroid_get_clipboard_data)
    (android_notifications_notify_1):
    * src/androidterm.c (android_decode_utf16)
    (android_text_to_string):
    * src/haiku_select.cc (be_display_notification):
    * src/sfnt.c (sfnt_read_cmap_format_8, sfnt_read_cmap_format_12)
    (sfnt_read_cmap_format_14, sfnt_read_cmap_table_1)
    (sfnt_expand_compound_glyph_context, sfnt_poly_edges_exact)
    (sfnt_read_meta_table, sfnt_read_ttc_header)
    (sfnt_read_cvt_table, sfnt_read_fpgm_table)
    (sfnt_read_prep_table, sfnt_make_interpreter)
    (sfnt_interpret_simple_glyph, sfnt_interpret_compound_glyph_2)
    (sfnt_interpret_compound_glyph, sfnt_read_default_uvs_table)
    (sfnt_read_nondefault_uvs_table, sfnt_create_uvs_context)
    (sfnt_read_fvar_table, sfnt_read_gvar_table)
    (sfnt_read_avar_table, sfnt_read_cvar_table):
    * src/sfntfont-android.c (GET_SCANLINE_BUFFER):
    * src/textconv.c (really_commit_text, really_set_composing_text)
    (really_replace_text, get_surrounding_text):
    Prefer C2x stdckdint.h macros to intprops.h macros.
---
 src/alloc.c            |   3 +-
 src/android.c          |  22 ++---
 src/androidmenu.c      |   2 +-
 src/androidselect.c    |   4 +-
 src/androidterm.c      |   6 +-
 src/haiku_select.cc    |   3 +-
 src/sfnt.c             | 256 ++++++++++++++++++++-----------------------------
 src/sfntfont-android.c |   4 +-
 src/textconv.c         |  28 ++----
 9 files changed, 135 insertions(+), 193 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index b144396948e..15bb65cf74f 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6291,8 +6291,7 @@ android_make_lisp_symbol (struct Lisp_Symbol *sym)
   intptr_t symoffset;
 
   symoffset = (intptr_t) sym;
-  INT_SUBTRACT_WRAPV (symoffset, (intptr_t) &lispsym,
-                     &symoffset);
+  ckd_sub (&symoffset, symoffset, (intptr_t) &lispsym);
 
   {
     Lisp_Object a = TAG_PTR_INITIALLY (Lisp_Symbol, symoffset);
diff --git a/src/android.c b/src/android.c
index 51eb85a97e8..4a74f5b2af4 100644
--- a/src/android.c
+++ b/src/android.c
@@ -3963,10 +3963,10 @@ android_blit_copy (int src_x, int src_y, int width, int 
height,
 
          /* Turn both into offsets.  */
 
-         if (INT_MULTIPLY_WRAPV (temp, pixel, &offset)
-             || INT_MULTIPLY_WRAPV (i, mask_info->stride, &offset1)
-             || INT_ADD_WRAPV (offset, offset1, &offset)
-             || INT_ADD_WRAPV ((uintptr_t) mask, offset, &start))
+         if (ckd_mul (&offset, temp, pixel)
+             || ckd_mul (&offset1, i, mask_info->stride)
+             || ckd_add (&offset, offset, offset1)
+             || ckd_add (&start, (uintptr_t) mask, offset))
            return;
 
          if (height <= 0)
@@ -4271,10 +4271,10 @@ android_blit_xor (int src_x, int src_y, int width, int 
height,
 
          /* Turn both into offsets.  */
 
-         if (INT_MULTIPLY_WRAPV (temp, pixel, &offset)
-             || INT_MULTIPLY_WRAPV (i, mask_info->stride, &offset1)
-             || INT_ADD_WRAPV (offset, offset1, &offset)
-             || INT_ADD_WRAPV ((uintptr_t) mask, offset, &start))
+         if (ckd_mul (&offset, temp, pixel)
+             || ckd_mul (&offset1, i, mask_info->stride)
+             || ckd_add (&offset, offset, offset1)
+             || ckd_add (&start, (uintptr_t) mask, offset))
            return;
 
          mask = mask_current = (unsigned char *) start;
@@ -4899,9 +4899,9 @@ android_get_image (android_drawable handle,
 
   if (bitmap_info.format != ANDROID_BITMAP_FORMAT_A_8)
     {
-      if (INT_MULTIPLY_WRAPV ((size_t) bitmap_info.stride,
-                             (size_t) bitmap_info.height,
-                             &byte_size))
+      if (ckd_mul (&byte_size,
+                  (size_t) bitmap_info.stride,
+                  (size_t) bitmap_info.height))
        {
          ANDROID_DELETE_LOCAL_REF (bitmap);
          memory_full (0);
diff --git a/src/androidmenu.c b/src/androidmenu.c
index 1728ae81e42..362d500ac1a 100644
--- a/src/androidmenu.c
+++ b/src/androidmenu.c
@@ -437,7 +437,7 @@ android_menu_show (struct frame *f, int x, int y, int 
menuflags,
              /* Compute the item ID.  This is the index of value.
                 Make sure it doesn't overflow.  */
 
-             if (!INT_ADD_OK (0, i + MENU_ITEMS_ITEM_VALUE, &item_id))
+             if (ckd_add (&item_id, i + MENU_ITEMS_ITEM_VALUE, 0))
                memory_full (i + MENU_ITEMS_ITEM_VALUE * sizeof (Lisp_Object));
 
              /* Add this menu item with the appropriate state.  */
diff --git a/src/androidselect.c b/src/androidselect.c
index 3ba3058aeb9..5b23c559d2c 100644
--- a/src/androidselect.c
+++ b/src/androidselect.c
@@ -446,7 +446,7 @@ does not have any corresponding data.  In that case, use
     {
       rc = emacs_read_quit (fd, start, BUFSIZ);
 
-      if (!INT_ADD_OK (rc, length, &length)
+      if (ckd_add (&length, length, rc)
          || PTRDIFF_MAX - length < BUFSIZ)
        memory_full (PTRDIFF_MAX);
 
@@ -588,7 +588,7 @@ android_notifications_notify_1 (Lisp_Object title, 
Lisp_Object body,
   if (NILP (replaces_id))
     {
       /* Generate a new identifier.  */
-      INT_ADD_WRAPV (counter, 1, &counter);
+      ckd_add (&counter, counter, 1);
       id = counter;
     }
   else
diff --git a/src/androidterm.c b/src/androidterm.c
index 8632df1d4fc..d4612bb20fa 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -619,7 +619,7 @@ android_decode_utf16 (unsigned short *utf16, size_t n)
   struct coding_system coding;
   ptrdiff_t size;
 
-  if (INT_MULTIPLY_WRAPV (n, sizeof *utf16, &size))
+  if (ckd_mul (&size, n, sizeof *utf16))
     return Qnil;
 
   /* Set up the coding system.  Decoding a UTF-16 string (with no BOM)
@@ -5010,7 +5010,7 @@ android_text_to_string (JNIEnv *env, char *buffer, 
ptrdiff_t n,
     {
       /* This buffer holds no multibyte characters.  */
 
-      if (INT_MULTIPLY_WRAPV (n, sizeof *utf16, &size))
+      if (ckd_mul (&size, n, sizeof *utf16))
        return NULL;
 
       utf16 = malloc (size);
@@ -5033,7 +5033,7 @@ android_text_to_string (JNIEnv *env, char *buffer, 
ptrdiff_t n,
 
   /* Allocate enough to hold N characters.  */
 
-  if (INT_MULTIPLY_WRAPV (n, sizeof *utf16, &size))
+  if (ckd_mul (&size, n, sizeof *utf16))
     return NULL;
 
   utf16 = malloc (size);
diff --git a/src/haiku_select.cc b/src/haiku_select.cc
index 02f3272514f..74467edf710 100644
--- a/src/haiku_select.cc
+++ b/src/haiku_select.cc
@@ -619,8 +619,7 @@ be_display_notification (const char *title, const char 
*body,
       /* SUPERSEDES hasn't been provided, so allocate a new
         notification ID.  */
 
-      INT_ADD_WRAPV (last_notification_id, 1,
-                    &last_notification_id);
+      ckd_add (&last_notification_id, last_notification_id, 1);
       id = last_notification_id;
     }
   else
diff --git a/src/sfnt.c b/src/sfnt.c
index 41dba8b486e..030442fad68 100644
--- a/src/sfnt.c
+++ b/src/sfnt.c
@@ -663,14 +663,13 @@ sfnt_read_cmap_format_8 (int fd,
   min_size = SFNT_ENDOF (struct sfnt_cmap_format_8, num_groups,
                         uint32_t);
 
-  if (INT_MULTIPLY_WRAPV (format8->num_groups, sizeof *format8->groups,
-                         &temp))
+  if (ckd_mul (&temp, format8->num_groups, sizeof *format8->groups))
     {
       xfree (format8);
       return NULL;
     }
 
-  if (INT_ADD_WRAPV (min_size, temp, &min_size))
+  if (ckd_add (&min_size, min_size, temp))
     {
       xfree (format8);
       return NULL;
@@ -755,14 +754,13 @@ sfnt_read_cmap_format_12 (int fd,
   min_size = SFNT_ENDOF (struct sfnt_cmap_format_12, num_groups,
                         uint32_t);
 
-  if (INT_MULTIPLY_WRAPV (format12->num_groups, sizeof *format12->groups,
-                         &temp))
+  if (ckd_mul (&temp, format12->num_groups, sizeof *format12->groups))
     {
       xfree (format12);
       return NULL;
     }
 
-  if (INT_ADD_WRAPV (min_size, temp, &min_size))
+  if (ckd_add (&min_size, min_size, temp))
     {
       xfree (format12);
       return NULL;
@@ -841,9 +839,8 @@ sfnt_read_cmap_format_14 (int fd,
      14 cmap table.  */
 
   size = sizeof *format14;
-  if (INT_MULTIPLY_WRAPV (num_records, sizeof *format14->records,
-                         &temp)
-      || INT_ADD_WRAPV (size, temp, &size))
+  if (ckd_mul (&temp, num_records, sizeof *format14->records)
+      || ckd_add (&size, size, temp))
     return NULL;
 
   format14 = xmalloc (size);
@@ -901,7 +898,7 @@ sfnt_read_cmap_table_1 (int fd, uint32_t directory_offset,
   off_t offset;
   struct sfnt_cmap_encoding_subtable_data header;
 
-  if (INT_ADD_WRAPV (directory_offset, table_offset, &offset))
+  if (ckd_add (&offset, directory_offset, table_offset))
     return (struct sfnt_cmap_encoding_subtable_data *) -1;
 
   if (lseek (fd, offset, SEEK_SET) == (off_t) -1)
@@ -2632,24 +2629,21 @@ sfnt_expand_compound_glyph_context (struct 
sfnt_compound_glyph_context *context,
   size_t size_bytes;
 
   /* Add each field while checking for overflow.  */
-  if (INT_ADD_WRAPV (number_of_contours, context->num_end_points,
-                    &context->num_end_points))
+  if (ckd_add (&context->num_end_points, number_of_contours,
+              context->num_end_points))
     return 1;
 
-  if (INT_ADD_WRAPV (number_of_points, context->num_points,
-                    &context->num_points))
+  if (ckd_add (&context->num_points, number_of_points, context->num_points))
     return 1;
 
   /* Reallocate each array to the new size if necessary.  */
   if (context->points_size < context->num_points)
     {
-      if (INT_MULTIPLY_WRAPV (context->num_points, 2,
-                             &context->points_size))
+      if (ckd_mul (&context->points_size, context->num_points, 2))
        context->points_size = context->num_points;
 
-      if (INT_MULTIPLY_WRAPV (context->points_size,
-                             sizeof *context->x_coordinates,
-                             &size_bytes))
+      if (ckd_mul (&size_bytes, context->points_size,
+                  sizeof *context->x_coordinates))
        return 1;
 
       context->x_coordinates = xrealloc (context->x_coordinates,
@@ -2673,13 +2667,11 @@ sfnt_expand_compound_glyph_context (struct 
sfnt_compound_glyph_context *context,
 
   if (context->end_points_size < context->num_end_points)
     {
-      if (INT_MULTIPLY_WRAPV (context->num_end_points, 2,
-                             &context->end_points_size))
+      if (ckd_mul (&context->end_points_size, context->num_end_points, 2))
        context->end_points_size = context->num_end_points;
 
-      if (INT_MULTIPLY_WRAPV (context->end_points_size,
-                             sizeof *context->contour_end_points,
-                             &size_bytes))
+      if (ckd_mul (&size_bytes, context->end_points_size,
+                  sizeof *context->contour_end_points))
        return 1;
 
       context->contour_end_points
@@ -5109,7 +5101,7 @@ sfnt_poly_edges_exact (struct sfnt_fedge *edges, size_t 
nedges,
   raster.scanlines = height;
   raster.chunks    = NULL;
 
-  if (!INT_MULTIPLY_OK (height, sizeof *raster.steps, &size))
+  if (ckd_mul (&size, height, sizeof *raster.steps))
     abort ();
 
   raster.steps = xzalloc (size);
@@ -6040,11 +6032,10 @@ sfnt_read_meta_table (int fd, struct 
sfnt_offset_subtable *subtable)
      so an unswapped copy of the whole meta contents must be
      retained.  */
 
-  if (INT_MULTIPLY_WRAPV (sizeof *meta->data_maps, meta->num_data_maps,
-                         &map_size)
+  if (ckd_mul (&map_size, sizeof *meta->data_maps, meta->num_data_maps)
       /* Do so while checking for overflow from bad sfnt files.  */
-      || INT_ADD_WRAPV (map_size, sizeof *meta, &data_size)
-      || INT_ADD_WRAPV (data_size, directory->length, &data_size))
+      || ckd_add (&data_size, map_size, sizeof *meta)
+      || ckd_add (&data_size, data_size, directory->length))
     {
       xfree (meta);
       return NULL;
@@ -6094,9 +6085,8 @@ sfnt_read_meta_table (int fd, struct sfnt_offset_subtable 
*subtable)
       /* Verify the data offsets.  Overflow checking is particularly
         important here.  */
 
-      if (INT_ADD_WRAPV (meta->data_maps[i].data_offset,
-                        meta->data_maps[i].data_length,
-                        &offset))
+      if (ckd_add (&offset, meta->data_maps[i].data_offset,
+                  meta->data_maps[i].data_length))
        {
          xfree (meta);
          return NULL;
@@ -6182,9 +6172,7 @@ sfnt_read_ttc_header (int fd)
   /* Now, read the variable length data.  Make sure to check for
      overflow.  */
 
-  if (INT_MULTIPLY_WRAPV (ttc->num_fonts,
-                         sizeof *ttc->offset_table,
-                         &size))
+  if (ckd_mul (&size, ttc->num_fonts, sizeof *ttc->offset_table))
     {
       xfree (ttc);
       return NULL;
@@ -6303,7 +6291,7 @@ sfnt_read_cvt_table (int fd, struct sfnt_offset_subtable 
*subtable)
     return NULL;
 
   /* Figure out the minimum amount that has to be read.  */
-  if (INT_ADD_WRAPV (sizeof *cvt, directory->length, &required))
+  if (ckd_add (&required, directory->length, sizeof *cvt))
     return NULL;
 
   /* Allocate enough for that much data.  */
@@ -6354,7 +6342,7 @@ sfnt_read_fpgm_table (int fd, struct sfnt_offset_subtable 
*subtable)
     return NULL;
 
   /* Figure out the minimum amount that has to be read.  */
-  if (INT_ADD_WRAPV (sizeof *fpgm, directory->length, &required))
+  if (ckd_add (&required, directory->length, sizeof *fpgm))
     return NULL;
 
   /* Allocate enough for that much data.  */
@@ -6402,7 +6390,7 @@ sfnt_read_prep_table (int fd, struct sfnt_offset_subtable 
*subtable)
     return NULL;
 
   /* Figure out the minimum amount that has to be read.  */
-  if (INT_ADD_WRAPV (sizeof *prep, directory->length, &required))
+  if (ckd_add (&required, directory->length, sizeof *prep))
     return NULL;
 
   /* Allocate enough for that much data.  */
@@ -6654,59 +6642,51 @@ sfnt_make_interpreter (struct sfnt_maxp_table *maxp,
   size = sizeof (*interpreter);
 
   /* Add program stack.  */
-  if (INT_ADD_WRAPV ((maxp->max_stack_elements
-                     * sizeof *interpreter->stack),
-                    size, &size))
+  if (ckd_add (&size, size, (maxp->max_stack_elements
+                            * sizeof *interpreter->stack)))
     return NULL;
 
   /* Add twilight zone.  */
 
-  if (INT_ADD_WRAPV ((maxp->max_twilight_points
-                     * sizeof *interpreter->twilight_x),
-                    size, &size))
+  if (ckd_add (&size, size, (maxp->max_twilight_points
+                            * sizeof *interpreter->twilight_x)))
     return NULL;
 
-  if (INT_ADD_WRAPV ((maxp->max_twilight_points
-                     * sizeof *interpreter->twilight_y),
-                    size, &size))
+  if (ckd_add (&size, size, (maxp->max_twilight_points
+                            * sizeof *interpreter->twilight_y)))
     return NULL;
 
-  if (INT_ADD_WRAPV ((maxp->max_twilight_points
-                     * sizeof *interpreter->twilight_y),
-                    size, &size))
+  if (ckd_add (&size, size, (maxp->max_twilight_points
+                            * sizeof *interpreter->twilight_y)))
     return NULL;
 
-  if (INT_ADD_WRAPV ((maxp->max_twilight_points
-                     * sizeof *interpreter->twilight_y),
-                    size, &size))
+  if (ckd_add (&size, size, (maxp->max_twilight_points
+                            * sizeof *interpreter->twilight_y)))
     return NULL;
 
   /* Add the storage area.  */
   storage_size = maxp->max_storage * sizeof *interpreter->storage;
-  if (INT_ADD_WRAPV (storage_size, size, &size))
+  if (ckd_add (&size, size, storage_size))
     return NULL;
 
   /* Add padding for the storage area.  */
   pad = alignof (struct sfnt_interpreter_definition);
   pad -= size & (pad - 1);
-  if (INT_ADD_WRAPV (pad, size, &size))
+  if (ckd_add (&size, size, pad))
     return NULL;
 
   /* Add function and instruction definitions.  */
-  if (INT_ADD_WRAPV ((((int) maxp->max_instruction_defs
-                      + maxp->max_function_defs)
-                     * sizeof *interpreter->function_defs),
-                    size, &size))
+  if (ckd_add (&size, size, (((int) maxp->max_instruction_defs
+                             + maxp->max_function_defs)
+                            * sizeof *interpreter->function_defs)))
     return NULL;
 
   /* Add control value table.  */
 
   if (cvt)
     {
-      if (INT_MULTIPLY_WRAPV (cvt->num_elements,
-                             sizeof *interpreter->cvt,
-                             &temp)
-         || INT_ADD_WRAPV (temp, size, &size))
+      if (ckd_mul (&temp, cvt->num_elements, sizeof *interpreter->cvt)
+         || ckd_add (&size, size, temp))
        return NULL;
     }
 
@@ -12648,19 +12628,16 @@ sfnt_interpret_simple_glyph (struct sfnt_glyph *glyph,
 
   /* Calculate the size of the zone structure.  */
 
-  if (INT_MULTIPLY_WRAPV (glyph->simple->number_of_points + 2,
-                         sizeof *zone->x_points * 4,
-                         &temp)
-      || INT_ADD_WRAPV (temp, zone_size, &zone_size)
-      || INT_MULTIPLY_WRAPV (glyph->number_of_contours,
-                            sizeof *zone->contour_end_points,
-                            &temp)
-      || INT_ADD_WRAPV (temp, zone_size, &zone_size)
-      || INT_MULTIPLY_WRAPV (glyph->simple->number_of_points + 2,
-                            sizeof *zone->flags,
-                            &temp)
-      || INT_ADD_WRAPV (temp, zone_size, &zone_size)
-      || INT_ADD_WRAPV (sizeof *zone, zone_size, &zone_size))
+  if (ckd_mul (&temp, glyph->simple->number_of_points + 2,
+              sizeof *zone->x_points * 4)
+      || ckd_add (&zone_size, zone_size, temp)
+      || ckd_mul (&temp, glyph->number_of_contours,
+                 sizeof *zone->contour_end_points)
+      || ckd_add (&zone_size, zone_size, temp)
+      || ckd_mul (&temp, glyph->simple->number_of_points + 2,
+                 sizeof *zone->flags)
+      || ckd_add (&zone_size, zone_size, temp)
+      || ckd_add (&zone_size, zone_size, sizeof *zone))
     return "Glyph exceeded maximum permissible size";
 
   /* Don't use malloc if possible.  */
@@ -12947,19 +12924,13 @@ sfnt_interpret_compound_glyph_2 (struct sfnt_glyph 
*glyph,
   zone_size = 0;
   zone_was_allocated = false;
 
-  if (INT_MULTIPLY_WRAPV (num_points + 2,
-                         sizeof *zone->x_points * 4,
-                         &temp)
-      || INT_ADD_WRAPV (temp, zone_size, &zone_size)
-      || INT_MULTIPLY_WRAPV (num_contours,
-                            sizeof *zone->contour_end_points,
-                            &temp)
-      || INT_ADD_WRAPV (temp, zone_size, &zone_size)
-      || INT_MULTIPLY_WRAPV (num_points + 2,
-                            sizeof *zone->flags,
-                            &temp)
-      || INT_ADD_WRAPV (temp, zone_size, &zone_size)
-      || INT_ADD_WRAPV (sizeof *zone, zone_size, &zone_size))
+  if (ckd_mul (&temp, num_points + 2, sizeof *zone->x_points * 4)
+      || ckd_add (&zone_size, zone_size, temp)
+      || ckd_mul (&temp, num_contours, sizeof *zone->contour_end_points)
+      || ckd_add (&zone_size, zone_size, temp)
+      || ckd_mul (&temp, num_points + 2, sizeof *zone->flags)
+      || ckd_add (&zone_size, zone_size, temp)
+      || ckd_add (&zone_size, zone_size, sizeof *zone))
     return "Glyph exceeded maximum permissible size";
 
   /* Don't use malloc if possible.  */
@@ -13602,16 +13573,12 @@ sfnt_interpret_compound_glyph (struct sfnt_glyph 
*glyph,
   /* Copy the compound glyph data into an instructed outline.  */
   outline_size = sizeof (*outline);
 
-  if (INT_MULTIPLY_WRAPV (context.num_end_points,
-                         sizeof *outline->contour_end_points,
-                         &temp)
-      || INT_ADD_WRAPV (outline_size, temp, &outline_size)
-      || INT_MULTIPLY_WRAPV (context.num_points,
-                            sizeof *outline->x_points * 2,
-                            &temp)
-      || INT_ADD_WRAPV (outline_size, temp, &outline_size)
-      || INT_ADD_WRAPV (context.num_points, outline_size,
-                       &outline_size))
+  if (ckd_mul (&temp, context.num_end_points,
+              sizeof *outline->contour_end_points)
+      || ckd_add (&outline_size, outline_size, temp)
+      || ckd_mul (&temp, context.num_points, sizeof *outline->x_points * 2)
+      || ckd_add (&outline_size, outline_size, temp)
+      || ckd_add (&outline_size, outline_size, context.num_points))
     {
       xfree (context.x_coordinates);
       xfree (context.y_coordinates);
@@ -13734,9 +13701,8 @@ sfnt_read_default_uvs_table (int fd, off_t offset)
   /* Now, allocate enough to hold the UVS table.  */
 
   size = sizeof *uvs;
-  if (INT_MULTIPLY_WRAPV (sizeof *uvs->ranges, num_ranges,
-                         &temp)
-      || INT_ADD_WRAPV (temp, size, &size))
+  if (ckd_mul (&temp, num_ranges, sizeof *uvs->ranges)
+      || ckd_add (&size, size, temp))
     return NULL;
 
   uvs = xmalloc (size);
@@ -13805,9 +13771,8 @@ sfnt_read_nondefault_uvs_table (int fd, off_t offset)
   /* Now, allocate enough to hold the UVS table.  */
 
   size = sizeof *uvs;
-  if (INT_MULTIPLY_WRAPV (sizeof *uvs->mappings, num_mappings,
-                         &temp)
-      || INT_ADD_WRAPV (temp, size, &size))
+  if (ckd_mul (&temp, num_mappings, sizeof *uvs->mappings)
+      || ckd_add (&size, size, temp))
     return NULL;
 
   uvs = xmalloc (size);
@@ -13887,9 +13852,9 @@ sfnt_create_uvs_context (struct sfnt_cmap_format_14 
*cmap, int fd)
   off_t offset;
   struct sfnt_uvs_context *context;
 
-  if (INT_MULTIPLY_WRAPV (cmap->num_var_selector_records,
-                         sizeof *table_offsets, &size)
-      || INT_MULTIPLY_WRAPV (size, 2, &size))
+  if (ckd_mul (&size, cmap->num_var_selector_records,
+              sizeof *table_offsets)
+      || ckd_mul (&size, size, 2))
     return NULL;
 
   context = NULL;
@@ -13909,9 +13874,8 @@ sfnt_create_uvs_context (struct sfnt_cmap_format_14 
*cmap, int fd)
 
       if (cmap->records[i].default_uvs_offset)
        {
-         if (INT_ADD_WRAPV (cmap->offset,
-                            cmap->records[i].default_uvs_offset,
-                            &table_offsets[j].offset))
+         if (ckd_add (&table_offsets[j].offset, cmap->offset,
+                      cmap->records[i].default_uvs_offset))
            goto bail;
 
          table_offsets[j++].is_nondefault_table = false;
@@ -13919,9 +13883,8 @@ sfnt_create_uvs_context (struct sfnt_cmap_format_14 
*cmap, int fd)
 
       if (cmap->records[i].nondefault_uvs_offset)
        {
-         if (INT_ADD_WRAPV (cmap->offset,
-                            cmap->records[i].nondefault_uvs_offset,
-                            &table_offsets[j].offset))
+         if (ckd_add (&table_offsets[j].offset, cmap->offset,
+                      cmap->records[i].nondefault_uvs_offset))
            goto bail;
 
          table_offsets[j++].is_nondefault_table = true;
@@ -14359,14 +14322,12 @@ sfnt_read_fvar_table (int fd, struct 
sfnt_offset_subtable *subtable)
      name identifier, or 3 * sizeof (uint16_t) + axisCount * sizeof
      (sfnt_fixed), meaning there is.  */
 
-  if (INT_MULTIPLY_WRAPV (fvar->axis_count, sizeof (sfnt_fixed),
-                         &temp)
-      || INT_ADD_WRAPV (2 * sizeof (uint16_t), temp, &non_ps_size))
+  if (ckd_mul (&temp, fvar->axis_count, sizeof (sfnt_fixed))
+      || ckd_add (&non_ps_size, temp, 2 * sizeof (uint16_t)))
     goto bail;
 
-  if (INT_MULTIPLY_WRAPV (fvar->axis_count, sizeof (sfnt_fixed),
-                         &temp)
-      || INT_ADD_WRAPV (3 * sizeof (uint16_t), temp, &ps_size))
+  if (ckd_mul (&temp, fvar->axis_count, sizeof (sfnt_fixed))
+      || ckd_add (&ps_size, temp, 3 * sizeof (uint16_t)))
     goto bail;
 
   if (fvar->instance_size != non_ps_size
@@ -14376,8 +14337,7 @@ sfnt_read_fvar_table (int fd, struct 
sfnt_offset_subtable *subtable)
   /* Now compute the offset of the axis data from the start of the
      font file.  */
 
-  if (INT_ADD_WRAPV (fvar->offset_to_data, directory->offset,
-                    &offset))
+  if (ckd_add (&offset, fvar->offset_to_data, directory->offset))
     goto bail;
 
   /* Seek there.  */
@@ -14394,28 +14354,23 @@ sfnt_read_fvar_table (int fd, struct 
sfnt_offset_subtable *subtable)
      sfnt_instance) + sizeof (sfnt_fixed) * fvar->instance_count *
      fvar->axis_count.  */
 
-  if (INT_MULTIPLY_WRAPV (fvar->axis_count, sizeof *fvar->axis,
-                         &temp)
-      || INT_ADD_WRAPV (min_bytes, temp, &min_bytes))
+  if (ckd_mul (&temp, fvar->axis_count, sizeof *fvar->axis)
+      || ckd_add (&min_bytes, min_bytes, temp))
     goto bail;
 
   pad = alignof (struct sfnt_instance);
   pad -= min_bytes & (pad - 1);
 
-  if (INT_ADD_WRAPV (min_bytes, pad, &min_bytes))
+  if (ckd_add (&min_bytes, min_bytes, pad))
     goto bail;
 
-  if (INT_MULTIPLY_WRAPV (fvar->instance_count,
-                         sizeof *fvar->instance,
-                         &temp)
-      || INT_ADD_WRAPV (min_bytes, temp, &min_bytes))
+  if (ckd_mul (&temp, fvar->instance_count, sizeof *fvar->instance)
+      || ckd_add (&min_bytes, min_bytes, temp))
     goto bail;
 
-  if (INT_MULTIPLY_WRAPV (fvar->instance_count,
-                         sizeof *fvar->instance->coords,
-                         &temp)
-      || INT_MULTIPLY_WRAPV (temp, fvar->axis_count, &temp)
-      || INT_ADD_WRAPV (min_bytes, temp, &min_bytes))
+  if (ckd_mul (&temp, fvar->instance_count, sizeof *fvar->instance->coords)
+      || ckd_mul (&temp, temp, fvar->axis_count)
+      || ckd_add (&min_bytes, min_bytes, temp))
     goto bail;
 
   /* Reallocate fvar.  */
@@ -14597,9 +14552,9 @@ sfnt_read_gvar_table (int fd, struct 
sfnt_offset_subtable *subtable)
     goto bail;
 
   /* Figure out how big gvar needs to be.  */
-  if (INT_ADD_WRAPV (sizeof *gvar, coordinate_size, &min_bytes)
-      || INT_ADD_WRAPV (min_bytes, off_size, &min_bytes)
-      || INT_ADD_WRAPV (min_bytes, data_size, &min_bytes))
+  if (ckd_add (&min_bytes, coordinate_size, sizeof *gvar)
+      || ckd_add (&min_bytes, min_bytes, off_size)
+      || ckd_add (&min_bytes, min_bytes, data_size))
     goto bail;
 
   /* Now allocate enough for all of this extra data.  */
@@ -14635,8 +14590,7 @@ sfnt_read_gvar_table (int fd, struct 
sfnt_offset_subtable *subtable)
 
   if (gvar->shared_coord_count)
     {
-      if (INT_ADD_WRAPV (gvar->offset_to_coord, directory->offset,
-                        &offset))
+      if (ckd_add (&offset, gvar->offset_to_coord, directory->offset))
        goto bail;
 
       if (lseek (fd, offset, SEEK_SET) != offset)
@@ -14660,8 +14614,7 @@ sfnt_read_gvar_table (int fd, struct 
sfnt_offset_subtable *subtable)
 
   if (gvar->data_size)
     {
-      if (INT_ADD_WRAPV (gvar->offset_to_data, directory->offset,
-                        &offset))
+      if (ckd_add (&offset, gvar->offset_to_data, directory->offset))
        goto bail;
 
       if (lseek (fd, offset, SEEK_SET) != offset)
@@ -14757,10 +14710,10 @@ sfnt_read_avar_table (int fd, struct 
sfnt_offset_subtable *subtable)
 
       /* Now add one struct sfnt_short_frac_segment for each axis and
          each of its correspondences.  */
-      if (INT_ADD_WRAPV (sizeof (struct sfnt_short_frac_segment),
-                        min_size, &min_size)
-         || INT_ADD_WRAPV (sizeof (struct sfnt_short_frac_correspondence)
-                           * buffer[k], min_size, &min_size))
+      if (ckd_add (&min_size, min_size, sizeof (struct 
sfnt_short_frac_segment))
+         || ckd_add (&min_size, min_size,
+                     (sizeof (struct sfnt_short_frac_correspondence)
+                      * buffer[k])))
        goto bail1;
 
       /* Verify that words from here to buffer[1 + buffer[k] * 2], the
@@ -15109,8 +15062,7 @@ sfnt_read_cvar_table (int fd, struct 
sfnt_offset_subtable *subtable,
            goto bail2;
 
          tuple += sizeof *coords * fvar->axis_count;
-         if (INT_ADD_WRAPV (size, sizeof *coords * fvar->axis_count,
-                            &size))
+         if (ckd_add (&size, size, sizeof *coords * fvar->axis_count))
            goto bail2;
        }
       else
@@ -15122,20 +15074,20 @@ sfnt_read_cvar_table (int fd, struct 
sfnt_offset_subtable *subtable,
       if (index & 0x4000)
        {
          tuple += fvar->axis_count * 4;
-         if (INT_ADD_WRAPV (size, fvar->axis_count * 4, &size))
+         if (ckd_add (&size, size, fvar->axis_count * 4))
            goto bail2;
        }
 
       /* Add one point and one delta for each CVT element.  */
-      if (INT_ADD_WRAPV (size, cvt->num_elements * 4, &size))
+      if (ckd_add (&size, size, cvt->num_elements * 4))
        goto bail2;
 
       /* Now add the size of the tuple.  */
-      if (INT_ADD_WRAPV (size, sizeof *cvar->variation, &size))
+      if (ckd_add (&size, size, sizeof *cvar->variation))
        goto bail2;
     }
 
-  if (INT_ADD_WRAPV (sizeof *cvar, size, &size))
+  if (ckd_add (&size, size, sizeof *cvar))
     goto bail2;
 
   /* Reallocate cvar.  */
diff --git a/src/sfntfont-android.c b/src/sfntfont-android.c
index 9ead43a9c5d..94aedd0cd66 100644
--- a/src/sfntfont-android.c
+++ b/src/sfntfont-android.c
@@ -78,7 +78,7 @@ static size_t max_scanline_buffer_size;
     {                                                          \
       size_t _size;                                            \
                                                                \
-      if (INT_MULTIPLY_WRAPV (height, stride, &_size))         \
+      if (ckd_mul (&_size, height, stride))                    \
        memory_full (SIZE_MAX);                                 \
                                                                \
       if (_size < MAX_ALLOCA)                                  \
@@ -112,7 +112,7 @@ static size_t max_scanline_buffer_size;
       size_t _size;                                            \
       void *_temp;                                             \
                                                                \
-      if (INT_MULTIPLY_WRAPV (height, stride, &_size))         \
+      if (ckd_mul (&_size, height, stride))                    \
        memory_full (SIZE_MAX);                                 \
                                                                \
       if (_size > scanline_buffer.buffer_size)                 \
diff --git a/src/textconv.c b/src/textconv.c
index 2a7b0ed330d..0d35ec19c55 100644
--- a/src/textconv.c
+++ b/src/textconv.c
@@ -649,8 +649,7 @@ really_commit_text (struct frame *f, EMACS_INT position,
             start of the text that was inserted.  */
          wanted = start;
 
-         if (INT_ADD_WRAPV (wanted, position, &wanted)
-             || wanted < BEGV)
+         if (ckd_add (&wanted, wanted, position) || wanted < BEGV)
            wanted = BEGV;
 
          if (wanted > ZV)
@@ -664,8 +663,7 @@ really_commit_text (struct frame *f, EMACS_INT position,
             TEXT.  */
          wanted = PT;
 
-         if (INT_ADD_WRAPV (wanted, position - 1, &wanted)
-             || wanted > ZV)
+         if (ckd_add (&wanted, wanted, position - 1) || wanted > ZV)
            wanted = ZV;
 
          if (wanted < BEGV)
@@ -712,8 +710,7 @@ really_commit_text (struct frame *f, EMACS_INT position,
 
       if (position <= 0)
        {
-         if (INT_ADD_WRAPV (wanted, position, &wanted)
-             || wanted < BEGV)
+         if (ckd_add (&wanted, wanted, position) || wanted < BEGV)
            wanted = BEGV;
 
          if (wanted > ZV)
@@ -725,8 +722,7 @@ really_commit_text (struct frame *f, EMACS_INT position,
        {
          wanted = PT;
 
-         if (INT_ADD_WRAPV (wanted, position - 1, &wanted)
-             || wanted > ZV)
+         if (ckd_add (&wanted, wanted, position - 1) || wanted > ZV)
            wanted = ZV;
 
          if (wanted < BEGV)
@@ -870,8 +866,7 @@ really_set_composing_text (struct frame *f, ptrdiff_t 
position,
     {
       wanted = start;
 
-      if (INT_SUBTRACT_WRAPV (wanted, position, &wanted)
-         || wanted < BEGV)
+      if (ckd_sub (&wanted, wanted, position) || wanted < BEGV)
        wanted = BEGV;
 
       if (wanted > ZV)
@@ -885,8 +880,7 @@ really_set_composing_text (struct frame *f, ptrdiff_t 
position,
       /* end should be PT after the edit.  */
       eassert (end == PT);
 
-      if (INT_ADD_WRAPV (wanted, position - 1, &wanted)
-         || wanted > ZV)
+      if (ckd_add (&wanted, wanted, position - 1) || wanted > ZV)
        wanted = ZV;
 
       if (wanted < BEGV)
@@ -1256,8 +1250,7 @@ really_replace_text (struct frame *f, ptrdiff_t start, 
ptrdiff_t end,
 
   if (position <= 0)
     {
-      if (INT_ADD_WRAPV (wanted, position, &wanted)
-         || wanted < BEGV)
+      if (ckd_add (&wanted, wanted, position) || wanted < BEGV)
        wanted = BEGV;
 
       if (wanted > ZV)
@@ -1269,8 +1262,7 @@ really_replace_text (struct frame *f, ptrdiff_t start, 
ptrdiff_t end,
     {
       wanted = PT;
 
-      if (INT_ADD_WRAPV (wanted, position - 1, &wanted)
-         || wanted > ZV)
+      if (ckd_add (&wanted, wanted, position - 1) || wanted > ZV)
        wanted = ZV;
 
       if (wanted < BEGV)
@@ -2020,8 +2012,8 @@ get_surrounding_text (struct frame *f, ptrdiff_t left,
 
   /* And subtract left and right.  */
 
-  if (INT_SUBTRACT_WRAPV (start, left, &start)
-      || INT_ADD_WRAPV (end, right, &end))
+  if (ckd_sub (&start, start, left)
+      || ckd_add (&end, end, right))
     goto finish;
 
   start = max (start, BEGV);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]