diff options
| author | Paul Eggert | 2024-01-28 00:15:38 -0800 |
|---|---|---|
| committer | Paul Eggert | 2024-01-28 00:26:44 -0800 |
| commit | ad2c81082a62f9f781e4f5771fc223520d91cefd (patch) | |
| tree | 7abd8b081eb665e84cb127e0c5396fa7df453bb4 /src | |
| parent | a3d7092114db09fee392ccc8187fde03376f2089 (diff) | |
| download | emacs-ad2c81082a62f9f781e4f5771fc223520d91cefd.tar.gz emacs-ad2c81082a62f9f781e4f5771fc223520d91cefd.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/alloc.c | 3 | ||||
| -rw-r--r-- | src/android.c | 22 | ||||
| -rw-r--r-- | src/androidmenu.c | 2 | ||||
| -rw-r--r-- | src/androidselect.c | 4 | ||||
| -rw-r--r-- | src/androidterm.c | 6 | ||||
| -rw-r--r-- | src/haiku_select.cc | 3 | ||||
| -rw-r--r-- | src/sfnt.c | 256 | ||||
| -rw-r--r-- | src/sfntfont-android.c | 4 | ||||
| -rw-r--r-- | 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) | |||
| 6291 | intptr_t symoffset; | 6291 | intptr_t symoffset; |
| 6292 | 6292 | ||
| 6293 | symoffset = (intptr_t) sym; | 6293 | symoffset = (intptr_t) sym; |
| 6294 | INT_SUBTRACT_WRAPV (symoffset, (intptr_t) &lispsym, | 6294 | ckd_sub (&symoffset, symoffset, (intptr_t) &lispsym); |
| 6295 | &symoffset); | ||
| 6296 | 6295 | ||
| 6297 | { | 6296 | { |
| 6298 | Lisp_Object a = TAG_PTR_INITIALLY (Lisp_Symbol, symoffset); | 6297 | 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, | |||
| 3963 | 3963 | ||
| 3964 | /* Turn both into offsets. */ | 3964 | /* Turn both into offsets. */ |
| 3965 | 3965 | ||
| 3966 | if (INT_MULTIPLY_WRAPV (temp, pixel, &offset) | 3966 | if (ckd_mul (&offset, temp, pixel) |
| 3967 | || INT_MULTIPLY_WRAPV (i, mask_info->stride, &offset1) | 3967 | || ckd_mul (&offset1, i, mask_info->stride) |
| 3968 | || INT_ADD_WRAPV (offset, offset1, &offset) | 3968 | || ckd_add (&offset, offset, offset1) |
| 3969 | || INT_ADD_WRAPV ((uintptr_t) mask, offset, &start)) | 3969 | || ckd_add (&start, (uintptr_t) mask, offset)) |
| 3970 | return; | 3970 | return; |
| 3971 | 3971 | ||
| 3972 | if (height <= 0) | 3972 | if (height <= 0) |
| @@ -4271,10 +4271,10 @@ android_blit_xor (int src_x, int src_y, int width, int height, | |||
| 4271 | 4271 | ||
| 4272 | /* Turn both into offsets. */ | 4272 | /* Turn both into offsets. */ |
| 4273 | 4273 | ||
| 4274 | if (INT_MULTIPLY_WRAPV (temp, pixel, &offset) | 4274 | if (ckd_mul (&offset, temp, pixel) |
| 4275 | || INT_MULTIPLY_WRAPV (i, mask_info->stride, &offset1) | 4275 | || ckd_mul (&offset1, i, mask_info->stride) |
| 4276 | || INT_ADD_WRAPV (offset, offset1, &offset) | 4276 | || ckd_add (&offset, offset, offset1) |
| 4277 | || INT_ADD_WRAPV ((uintptr_t) mask, offset, &start)) | 4277 | || ckd_add (&start, (uintptr_t) mask, offset)) |
| 4278 | return; | 4278 | return; |
| 4279 | 4279 | ||
| 4280 | mask = mask_current = (unsigned char *) start; | 4280 | mask = mask_current = (unsigned char *) start; |
| @@ -4899,9 +4899,9 @@ android_get_image (android_drawable handle, | |||
| 4899 | 4899 | ||
| 4900 | if (bitmap_info.format != ANDROID_BITMAP_FORMAT_A_8) | 4900 | if (bitmap_info.format != ANDROID_BITMAP_FORMAT_A_8) |
| 4901 | { | 4901 | { |
| 4902 | if (INT_MULTIPLY_WRAPV ((size_t) bitmap_info.stride, | 4902 | if (ckd_mul (&byte_size, |
| 4903 | (size_t) bitmap_info.height, | 4903 | (size_t) bitmap_info.stride, |
| 4904 | &byte_size)) | 4904 | (size_t) bitmap_info.height)) |
| 4905 | { | 4905 | { |
| 4906 | ANDROID_DELETE_LOCAL_REF (bitmap); | 4906 | ANDROID_DELETE_LOCAL_REF (bitmap); |
| 4907 | memory_full (0); | 4907 | 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, | |||
| 437 | /* Compute the item ID. This is the index of value. | 437 | /* Compute the item ID. This is the index of value. |
| 438 | Make sure it doesn't overflow. */ | 438 | Make sure it doesn't overflow. */ |
| 439 | 439 | ||
| 440 | if (!INT_ADD_OK (0, i + MENU_ITEMS_ITEM_VALUE, &item_id)) | 440 | if (ckd_add (&item_id, i + MENU_ITEMS_ITEM_VALUE, 0)) |
| 441 | memory_full (i + MENU_ITEMS_ITEM_VALUE * sizeof (Lisp_Object)); | 441 | memory_full (i + MENU_ITEMS_ITEM_VALUE * sizeof (Lisp_Object)); |
| 442 | 442 | ||
| 443 | /* Add this menu item with the appropriate state. */ | 443 | /* 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 | |||
| 446 | { | 446 | { |
| 447 | rc = emacs_read_quit (fd, start, BUFSIZ); | 447 | rc = emacs_read_quit (fd, start, BUFSIZ); |
| 448 | 448 | ||
| 449 | if (!INT_ADD_OK (rc, length, &length) | 449 | if (ckd_add (&length, length, rc) |
| 450 | || PTRDIFF_MAX - length < BUFSIZ) | 450 | || PTRDIFF_MAX - length < BUFSIZ) |
| 451 | memory_full (PTRDIFF_MAX); | 451 | memory_full (PTRDIFF_MAX); |
| 452 | 452 | ||
| @@ -588,7 +588,7 @@ android_notifications_notify_1 (Lisp_Object title, Lisp_Object body, | |||
| 588 | if (NILP (replaces_id)) | 588 | if (NILP (replaces_id)) |
| 589 | { | 589 | { |
| 590 | /* Generate a new identifier. */ | 590 | /* Generate a new identifier. */ |
| 591 | INT_ADD_WRAPV (counter, 1, &counter); | 591 | ckd_add (&counter, counter, 1); |
| 592 | id = counter; | 592 | id = counter; |
| 593 | } | 593 | } |
| 594 | else | 594 | 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) | |||
| 619 | struct coding_system coding; | 619 | struct coding_system coding; |
| 620 | ptrdiff_t size; | 620 | ptrdiff_t size; |
| 621 | 621 | ||
| 622 | if (INT_MULTIPLY_WRAPV (n, sizeof *utf16, &size)) | 622 | if (ckd_mul (&size, n, sizeof *utf16)) |
| 623 | return Qnil; | 623 | return Qnil; |
| 624 | 624 | ||
| 625 | /* Set up the coding system. Decoding a UTF-16 string (with no BOM) | 625 | /* 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, | |||
| 5010 | { | 5010 | { |
| 5011 | /* This buffer holds no multibyte characters. */ | 5011 | /* This buffer holds no multibyte characters. */ |
| 5012 | 5012 | ||
| 5013 | if (INT_MULTIPLY_WRAPV (n, sizeof *utf16, &size)) | 5013 | if (ckd_mul (&size, n, sizeof *utf16)) |
| 5014 | return NULL; | 5014 | return NULL; |
| 5015 | 5015 | ||
| 5016 | utf16 = malloc (size); | 5016 | utf16 = malloc (size); |
| @@ -5033,7 +5033,7 @@ android_text_to_string (JNIEnv *env, char *buffer, ptrdiff_t n, | |||
| 5033 | 5033 | ||
| 5034 | /* Allocate enough to hold N characters. */ | 5034 | /* Allocate enough to hold N characters. */ |
| 5035 | 5035 | ||
| 5036 | if (INT_MULTIPLY_WRAPV (n, sizeof *utf16, &size)) | 5036 | if (ckd_mul (&size, n, sizeof *utf16)) |
| 5037 | return NULL; | 5037 | return NULL; |
| 5038 | 5038 | ||
| 5039 | utf16 = malloc (size); | 5039 | 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, | |||
| 619 | /* SUPERSEDES hasn't been provided, so allocate a new | 619 | /* SUPERSEDES hasn't been provided, so allocate a new |
| 620 | notification ID. */ | 620 | notification ID. */ |
| 621 | 621 | ||
| 622 | INT_ADD_WRAPV (last_notification_id, 1, | 622 | ckd_add (&last_notification_id, last_notification_id, 1); |
| 623 | &last_notification_id); | ||
| 624 | id = last_notification_id; | 623 | id = last_notification_id; |
| 625 | } | 624 | } |
| 626 | else | 625 | 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, | |||
| 663 | min_size = SFNT_ENDOF (struct sfnt_cmap_format_8, num_groups, | 663 | min_size = SFNT_ENDOF (struct sfnt_cmap_format_8, num_groups, |
| 664 | uint32_t); | 664 | uint32_t); |
| 665 | 665 | ||
| 666 | if (INT_MULTIPLY_WRAPV (format8->num_groups, sizeof *format8->groups, | 666 | if (ckd_mul (&temp, format8->num_groups, sizeof *format8->groups)) |
| 667 | &temp)) | ||
| 668 | { | 667 | { |
| 669 | xfree (format8); | 668 | xfree (format8); |
| 670 | return NULL; | 669 | return NULL; |
| 671 | } | 670 | } |
| 672 | 671 | ||
| 673 | if (INT_ADD_WRAPV (min_size, temp, &min_size)) | 672 | if (ckd_add (&min_size, min_size, temp)) |
| 674 | { | 673 | { |
| 675 | xfree (format8); | 674 | xfree (format8); |
| 676 | return NULL; | 675 | return NULL; |
| @@ -755,14 +754,13 @@ sfnt_read_cmap_format_12 (int fd, | |||
| 755 | min_size = SFNT_ENDOF (struct sfnt_cmap_format_12, num_groups, | 754 | min_size = SFNT_ENDOF (struct sfnt_cmap_format_12, num_groups, |
| 756 | uint32_t); | 755 | uint32_t); |
| 757 | 756 | ||
| 758 | if (INT_MULTIPLY_WRAPV (format12->num_groups, sizeof *format12->groups, | 757 | if (ckd_mul (&temp, format12->num_groups, sizeof *format12->groups)) |
| 759 | &temp)) | ||
| 760 | { | 758 | { |
| 761 | xfree (format12); | 759 | xfree (format12); |
| 762 | return NULL; | 760 | return NULL; |
| 763 | } | 761 | } |
| 764 | 762 | ||
| 765 | if (INT_ADD_WRAPV (min_size, temp, &min_size)) | 763 | if (ckd_add (&min_size, min_size, temp)) |
| 766 | { | 764 | { |
| 767 | xfree (format12); | 765 | xfree (format12); |
| 768 | return NULL; | 766 | return NULL; |
| @@ -841,9 +839,8 @@ sfnt_read_cmap_format_14 (int fd, | |||
| 841 | 14 cmap table. */ | 839 | 14 cmap table. */ |
| 842 | 840 | ||
| 843 | size = sizeof *format14; | 841 | size = sizeof *format14; |
| 844 | if (INT_MULTIPLY_WRAPV (num_records, sizeof *format14->records, | 842 | if (ckd_mul (&temp, num_records, sizeof *format14->records) |
| 845 | &temp) | 843 | || ckd_add (&size, size, temp)) |
| 846 | || INT_ADD_WRAPV (size, temp, &size)) | ||
| 847 | return NULL; | 844 | return NULL; |
| 848 | 845 | ||
| 849 | format14 = xmalloc (size); | 846 | format14 = xmalloc (size); |
| @@ -901,7 +898,7 @@ sfnt_read_cmap_table_1 (int fd, uint32_t directory_offset, | |||
| 901 | off_t offset; | 898 | off_t offset; |
| 902 | struct sfnt_cmap_encoding_subtable_data header; | 899 | struct sfnt_cmap_encoding_subtable_data header; |
| 903 | 900 | ||
| 904 | if (INT_ADD_WRAPV (directory_offset, table_offset, &offset)) | 901 | if (ckd_add (&offset, directory_offset, table_offset)) |
| 905 | return (struct sfnt_cmap_encoding_subtable_data *) -1; | 902 | return (struct sfnt_cmap_encoding_subtable_data *) -1; |
| 906 | 903 | ||
| 907 | if (lseek (fd, offset, SEEK_SET) == (off_t) -1) | 904 | if (lseek (fd, offset, SEEK_SET) == (off_t) -1) |
| @@ -2632,24 +2629,21 @@ sfnt_expand_compound_glyph_context (struct sfnt_compound_glyph_context *context, | |||
| 2632 | size_t size_bytes; | 2629 | size_t size_bytes; |
| 2633 | 2630 | ||
| 2634 | /* Add each field while checking for overflow. */ | 2631 | /* Add each field while checking for overflow. */ |
| 2635 | if (INT_ADD_WRAPV (number_of_contours, context->num_end_points, | 2632 | if (ckd_add (&context->num_end_points, number_of_contours, |
| 2636 | &context->num_end_points)) | 2633 | context->num_end_points)) |
| 2637 | return 1; | 2634 | return 1; |
| 2638 | 2635 | ||
| 2639 | if (INT_ADD_WRAPV (number_of_points, context->num_points, | 2636 | if (ckd_add (&context->num_points, number_of_points, context->num_points)) |
| 2640 | &context->num_points)) | ||
| 2641 | return 1; | 2637 | return 1; |
| 2642 | 2638 | ||
| 2643 | /* Reallocate each array to the new size if necessary. */ | 2639 | /* Reallocate each array to the new size if necessary. */ |
| 2644 | if (context->points_size < context->num_points) | 2640 | if (context->points_size < context->num_points) |
| 2645 | { | 2641 | { |
| 2646 | if (INT_MULTIPLY_WRAPV (context->num_points, 2, | 2642 | if (ckd_mul (&context->points_size, context->num_points, 2)) |
| 2647 | &context->points_size)) | ||
| 2648 | context->points_size = context->num_points; | 2643 | context->points_size = context->num_points; |
| 2649 | 2644 | ||
| 2650 | if (INT_MULTIPLY_WRAPV (context->points_size, | 2645 | if (ckd_mul (&size_bytes, context->points_size, |
| 2651 | sizeof *context->x_coordinates, | 2646 | sizeof *context->x_coordinates)) |
| 2652 | &size_bytes)) | ||
| 2653 | return 1; | 2647 | return 1; |
| 2654 | 2648 | ||
| 2655 | context->x_coordinates = xrealloc (context->x_coordinates, | 2649 | context->x_coordinates = xrealloc (context->x_coordinates, |
| @@ -2673,13 +2667,11 @@ sfnt_expand_compound_glyph_context (struct sfnt_compound_glyph_context *context, | |||
| 2673 | 2667 | ||
| 2674 | if (context->end_points_size < context->num_end_points) | 2668 | if (context->end_points_size < context->num_end_points) |
| 2675 | { | 2669 | { |
| 2676 | if (INT_MULTIPLY_WRAPV (context->num_end_points, 2, | 2670 | if (ckd_mul (&context->end_points_size, context->num_end_points, 2)) |
| 2677 | &context->end_points_size)) | ||
| 2678 | context->end_points_size = context->num_end_points; | 2671 | context->end_points_size = context->num_end_points; |
| 2679 | 2672 | ||
| 2680 | if (INT_MULTIPLY_WRAPV (context->end_points_size, | 2673 | if (ckd_mul (&size_bytes, context->end_points_size, |
| 2681 | sizeof *context->contour_end_points, | 2674 | sizeof *context->contour_end_points)) |
| 2682 | &size_bytes)) | ||
| 2683 | return 1; | 2675 | return 1; |
| 2684 | 2676 | ||
| 2685 | context->contour_end_points | 2677 | context->contour_end_points |
| @@ -5109,7 +5101,7 @@ sfnt_poly_edges_exact (struct sfnt_fedge *edges, size_t nedges, | |||
| 5109 | raster.scanlines = height; | 5101 | raster.scanlines = height; |
| 5110 | raster.chunks = NULL; | 5102 | raster.chunks = NULL; |
| 5111 | 5103 | ||
| 5112 | if (!INT_MULTIPLY_OK (height, sizeof *raster.steps, &size)) | 5104 | if (ckd_mul (&size, height, sizeof *raster.steps)) |
| 5113 | abort (); | 5105 | abort (); |
| 5114 | 5106 | ||
| 5115 | raster.steps = xzalloc (size); | 5107 | raster.steps = xzalloc (size); |
| @@ -6040,11 +6032,10 @@ sfnt_read_meta_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 6040 | so an unswapped copy of the whole meta contents must be | 6032 | so an unswapped copy of the whole meta contents must be |
| 6041 | retained. */ | 6033 | retained. */ |
| 6042 | 6034 | ||
| 6043 | if (INT_MULTIPLY_WRAPV (sizeof *meta->data_maps, meta->num_data_maps, | 6035 | if (ckd_mul (&map_size, sizeof *meta->data_maps, meta->num_data_maps) |
| 6044 | &map_size) | ||
| 6045 | /* Do so while checking for overflow from bad sfnt files. */ | 6036 | /* Do so while checking for overflow from bad sfnt files. */ |
| 6046 | || INT_ADD_WRAPV (map_size, sizeof *meta, &data_size) | 6037 | || ckd_add (&data_size, map_size, sizeof *meta) |
| 6047 | || INT_ADD_WRAPV (data_size, directory->length, &data_size)) | 6038 | || ckd_add (&data_size, data_size, directory->length)) |
| 6048 | { | 6039 | { |
| 6049 | xfree (meta); | 6040 | xfree (meta); |
| 6050 | return NULL; | 6041 | return NULL; |
| @@ -6094,9 +6085,8 @@ sfnt_read_meta_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 6094 | /* Verify the data offsets. Overflow checking is particularly | 6085 | /* Verify the data offsets. Overflow checking is particularly |
| 6095 | important here. */ | 6086 | important here. */ |
| 6096 | 6087 | ||
| 6097 | if (INT_ADD_WRAPV (meta->data_maps[i].data_offset, | 6088 | if (ckd_add (&offset, meta->data_maps[i].data_offset, |
| 6098 | meta->data_maps[i].data_length, | 6089 | meta->data_maps[i].data_length)) |
| 6099 | &offset)) | ||
| 6100 | { | 6090 | { |
| 6101 | xfree (meta); | 6091 | xfree (meta); |
| 6102 | return NULL; | 6092 | return NULL; |
| @@ -6182,9 +6172,7 @@ sfnt_read_ttc_header (int fd) | |||
| 6182 | /* Now, read the variable length data. Make sure to check for | 6172 | /* Now, read the variable length data. Make sure to check for |
| 6183 | overflow. */ | 6173 | overflow. */ |
| 6184 | 6174 | ||
| 6185 | if (INT_MULTIPLY_WRAPV (ttc->num_fonts, | 6175 | if (ckd_mul (&size, ttc->num_fonts, sizeof *ttc->offset_table)) |
| 6186 | sizeof *ttc->offset_table, | ||
| 6187 | &size)) | ||
| 6188 | { | 6176 | { |
| 6189 | xfree (ttc); | 6177 | xfree (ttc); |
| 6190 | return NULL; | 6178 | return NULL; |
| @@ -6303,7 +6291,7 @@ sfnt_read_cvt_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 6303 | return NULL; | 6291 | return NULL; |
| 6304 | 6292 | ||
| 6305 | /* Figure out the minimum amount that has to be read. */ | 6293 | /* Figure out the minimum amount that has to be read. */ |
| 6306 | if (INT_ADD_WRAPV (sizeof *cvt, directory->length, &required)) | 6294 | if (ckd_add (&required, directory->length, sizeof *cvt)) |
| 6307 | return NULL; | 6295 | return NULL; |
| 6308 | 6296 | ||
| 6309 | /* Allocate enough for that much data. */ | 6297 | /* Allocate enough for that much data. */ |
| @@ -6354,7 +6342,7 @@ sfnt_read_fpgm_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 6354 | return NULL; | 6342 | return NULL; |
| 6355 | 6343 | ||
| 6356 | /* Figure out the minimum amount that has to be read. */ | 6344 | /* Figure out the minimum amount that has to be read. */ |
| 6357 | if (INT_ADD_WRAPV (sizeof *fpgm, directory->length, &required)) | 6345 | if (ckd_add (&required, directory->length, sizeof *fpgm)) |
| 6358 | return NULL; | 6346 | return NULL; |
| 6359 | 6347 | ||
| 6360 | /* Allocate enough for that much data. */ | 6348 | /* Allocate enough for that much data. */ |
| @@ -6402,7 +6390,7 @@ sfnt_read_prep_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 6402 | return NULL; | 6390 | return NULL; |
| 6403 | 6391 | ||
| 6404 | /* Figure out the minimum amount that has to be read. */ | 6392 | /* Figure out the minimum amount that has to be read. */ |
| 6405 | if (INT_ADD_WRAPV (sizeof *prep, directory->length, &required)) | 6393 | if (ckd_add (&required, directory->length, sizeof *prep)) |
| 6406 | return NULL; | 6394 | return NULL; |
| 6407 | 6395 | ||
| 6408 | /* Allocate enough for that much data. */ | 6396 | /* Allocate enough for that much data. */ |
| @@ -6654,59 +6642,51 @@ sfnt_make_interpreter (struct sfnt_maxp_table *maxp, | |||
| 6654 | size = sizeof (*interpreter); | 6642 | size = sizeof (*interpreter); |
| 6655 | 6643 | ||
| 6656 | /* Add program stack. */ | 6644 | /* Add program stack. */ |
| 6657 | if (INT_ADD_WRAPV ((maxp->max_stack_elements | 6645 | if (ckd_add (&size, size, (maxp->max_stack_elements |
| 6658 | * sizeof *interpreter->stack), | 6646 | * sizeof *interpreter->stack))) |
| 6659 | size, &size)) | ||
| 6660 | return NULL; | 6647 | return NULL; |
| 6661 | 6648 | ||
| 6662 | /* Add twilight zone. */ | 6649 | /* Add twilight zone. */ |
| 6663 | 6650 | ||
| 6664 | if (INT_ADD_WRAPV ((maxp->max_twilight_points | 6651 | if (ckd_add (&size, size, (maxp->max_twilight_points |
| 6665 | * sizeof *interpreter->twilight_x), | 6652 | * sizeof *interpreter->twilight_x))) |
| 6666 | size, &size)) | ||
| 6667 | return NULL; | 6653 | return NULL; |
| 6668 | 6654 | ||
| 6669 | if (INT_ADD_WRAPV ((maxp->max_twilight_points | 6655 | if (ckd_add (&size, size, (maxp->max_twilight_points |
| 6670 | * sizeof *interpreter->twilight_y), | 6656 | * sizeof *interpreter->twilight_y))) |
| 6671 | size, &size)) | ||
| 6672 | return NULL; | 6657 | return NULL; |
| 6673 | 6658 | ||
| 6674 | if (INT_ADD_WRAPV ((maxp->max_twilight_points | 6659 | if (ckd_add (&size, size, (maxp->max_twilight_points |
| 6675 | * sizeof *interpreter->twilight_y), | 6660 | * sizeof *interpreter->twilight_y))) |
| 6676 | size, &size)) | ||
| 6677 | return NULL; | 6661 | return NULL; |
| 6678 | 6662 | ||
| 6679 | if (INT_ADD_WRAPV ((maxp->max_twilight_points | 6663 | if (ckd_add (&size, size, (maxp->max_twilight_points |
| 6680 | * sizeof *interpreter->twilight_y), | 6664 | * sizeof *interpreter->twilight_y))) |
| 6681 | size, &size)) | ||
| 6682 | return NULL; | 6665 | return NULL; |
| 6683 | 6666 | ||
| 6684 | /* Add the storage area. */ | 6667 | /* Add the storage area. */ |
| 6685 | storage_size = maxp->max_storage * sizeof *interpreter->storage; | 6668 | storage_size = maxp->max_storage * sizeof *interpreter->storage; |
| 6686 | if (INT_ADD_WRAPV (storage_size, size, &size)) | 6669 | if (ckd_add (&size, size, storage_size)) |
| 6687 | return NULL; | 6670 | return NULL; |
| 6688 | 6671 | ||
| 6689 | /* Add padding for the storage area. */ | 6672 | /* Add padding for the storage area. */ |
| 6690 | pad = alignof (struct sfnt_interpreter_definition); | 6673 | pad = alignof (struct sfnt_interpreter_definition); |
| 6691 | pad -= size & (pad - 1); | 6674 | pad -= size & (pad - 1); |
| 6692 | if (INT_ADD_WRAPV (pad, size, &size)) | 6675 | if (ckd_add (&size, size, pad)) |
| 6693 | return NULL; | 6676 | return NULL; |
| 6694 | 6677 | ||
| 6695 | /* Add function and instruction definitions. */ | 6678 | /* Add function and instruction definitions. */ |
| 6696 | if (INT_ADD_WRAPV ((((int) maxp->max_instruction_defs | 6679 | if (ckd_add (&size, size, (((int) maxp->max_instruction_defs |
| 6697 | + maxp->max_function_defs) | 6680 | + maxp->max_function_defs) |
| 6698 | * sizeof *interpreter->function_defs), | 6681 | * sizeof *interpreter->function_defs))) |
| 6699 | size, &size)) | ||
| 6700 | return NULL; | 6682 | return NULL; |
| 6701 | 6683 | ||
| 6702 | /* Add control value table. */ | 6684 | /* Add control value table. */ |
| 6703 | 6685 | ||
| 6704 | if (cvt) | 6686 | if (cvt) |
| 6705 | { | 6687 | { |
| 6706 | if (INT_MULTIPLY_WRAPV (cvt->num_elements, | 6688 | if (ckd_mul (&temp, cvt->num_elements, sizeof *interpreter->cvt) |
| 6707 | sizeof *interpreter->cvt, | 6689 | || ckd_add (&size, size, temp)) |
| 6708 | &temp) | ||
| 6709 | || INT_ADD_WRAPV (temp, size, &size)) | ||
| 6710 | return NULL; | 6690 | return NULL; |
| 6711 | } | 6691 | } |
| 6712 | 6692 | ||
| @@ -12648,19 +12628,16 @@ sfnt_interpret_simple_glyph (struct sfnt_glyph *glyph, | |||
| 12648 | 12628 | ||
| 12649 | /* Calculate the size of the zone structure. */ | 12629 | /* Calculate the size of the zone structure. */ |
| 12650 | 12630 | ||
| 12651 | if (INT_MULTIPLY_WRAPV (glyph->simple->number_of_points + 2, | 12631 | if (ckd_mul (&temp, glyph->simple->number_of_points + 2, |
| 12652 | sizeof *zone->x_points * 4, | 12632 | sizeof *zone->x_points * 4) |
| 12653 | &temp) | 12633 | || ckd_add (&zone_size, zone_size, temp) |
| 12654 | || INT_ADD_WRAPV (temp, zone_size, &zone_size) | 12634 | || ckd_mul (&temp, glyph->number_of_contours, |
| 12655 | || INT_MULTIPLY_WRAPV (glyph->number_of_contours, | 12635 | sizeof *zone->contour_end_points) |
| 12656 | sizeof *zone->contour_end_points, | 12636 | || ckd_add (&zone_size, zone_size, temp) |
| 12657 | &temp) | 12637 | || ckd_mul (&temp, glyph->simple->number_of_points + 2, |
| 12658 | || INT_ADD_WRAPV (temp, zone_size, &zone_size) | 12638 | sizeof *zone->flags) |
| 12659 | || INT_MULTIPLY_WRAPV (glyph->simple->number_of_points + 2, | 12639 | || ckd_add (&zone_size, zone_size, temp) |
| 12660 | sizeof *zone->flags, | 12640 | || ckd_add (&zone_size, zone_size, sizeof *zone)) |
| 12661 | &temp) | ||
| 12662 | || INT_ADD_WRAPV (temp, zone_size, &zone_size) | ||
| 12663 | || INT_ADD_WRAPV (sizeof *zone, zone_size, &zone_size)) | ||
| 12664 | return "Glyph exceeded maximum permissible size"; | 12641 | return "Glyph exceeded maximum permissible size"; |
| 12665 | 12642 | ||
| 12666 | /* Don't use malloc if possible. */ | 12643 | /* Don't use malloc if possible. */ |
| @@ -12947,19 +12924,13 @@ sfnt_interpret_compound_glyph_2 (struct sfnt_glyph *glyph, | |||
| 12947 | zone_size = 0; | 12924 | zone_size = 0; |
| 12948 | zone_was_allocated = false; | 12925 | zone_was_allocated = false; |
| 12949 | 12926 | ||
| 12950 | if (INT_MULTIPLY_WRAPV (num_points + 2, | 12927 | if (ckd_mul (&temp, num_points + 2, sizeof *zone->x_points * 4) |
| 12951 | sizeof *zone->x_points * 4, | 12928 | || ckd_add (&zone_size, zone_size, temp) |
| 12952 | &temp) | 12929 | || ckd_mul (&temp, num_contours, sizeof *zone->contour_end_points) |
| 12953 | || INT_ADD_WRAPV (temp, zone_size, &zone_size) | 12930 | || ckd_add (&zone_size, zone_size, temp) |
| 12954 | || INT_MULTIPLY_WRAPV (num_contours, | 12931 | || ckd_mul (&temp, num_points + 2, sizeof *zone->flags) |
| 12955 | sizeof *zone->contour_end_points, | 12932 | || ckd_add (&zone_size, zone_size, temp) |
| 12956 | &temp) | 12933 | || ckd_add (&zone_size, zone_size, sizeof *zone)) |
| 12957 | || INT_ADD_WRAPV (temp, zone_size, &zone_size) | ||
| 12958 | || INT_MULTIPLY_WRAPV (num_points + 2, | ||
| 12959 | sizeof *zone->flags, | ||
| 12960 | &temp) | ||
| 12961 | || INT_ADD_WRAPV (temp, zone_size, &zone_size) | ||
| 12962 | || INT_ADD_WRAPV (sizeof *zone, zone_size, &zone_size)) | ||
| 12963 | return "Glyph exceeded maximum permissible size"; | 12934 | return "Glyph exceeded maximum permissible size"; |
| 12964 | 12935 | ||
| 12965 | /* Don't use malloc if possible. */ | 12936 | /* Don't use malloc if possible. */ |
| @@ -13602,16 +13573,12 @@ sfnt_interpret_compound_glyph (struct sfnt_glyph *glyph, | |||
| 13602 | /* Copy the compound glyph data into an instructed outline. */ | 13573 | /* Copy the compound glyph data into an instructed outline. */ |
| 13603 | outline_size = sizeof (*outline); | 13574 | outline_size = sizeof (*outline); |
| 13604 | 13575 | ||
| 13605 | if (INT_MULTIPLY_WRAPV (context.num_end_points, | 13576 | if (ckd_mul (&temp, context.num_end_points, |
| 13606 | sizeof *outline->contour_end_points, | 13577 | sizeof *outline->contour_end_points) |
| 13607 | &temp) | 13578 | || ckd_add (&outline_size, outline_size, temp) |
| 13608 | || INT_ADD_WRAPV (outline_size, temp, &outline_size) | 13579 | || ckd_mul (&temp, context.num_points, sizeof *outline->x_points * 2) |
| 13609 | || INT_MULTIPLY_WRAPV (context.num_points, | 13580 | || ckd_add (&outline_size, outline_size, temp) |
| 13610 | sizeof *outline->x_points * 2, | 13581 | || ckd_add (&outline_size, outline_size, context.num_points)) |
| 13611 | &temp) | ||
| 13612 | || INT_ADD_WRAPV (outline_size, temp, &outline_size) | ||
| 13613 | || INT_ADD_WRAPV (context.num_points, outline_size, | ||
| 13614 | &outline_size)) | ||
| 13615 | { | 13582 | { |
| 13616 | xfree (context.x_coordinates); | 13583 | xfree (context.x_coordinates); |
| 13617 | xfree (context.y_coordinates); | 13584 | xfree (context.y_coordinates); |
| @@ -13734,9 +13701,8 @@ sfnt_read_default_uvs_table (int fd, off_t offset) | |||
| 13734 | /* Now, allocate enough to hold the UVS table. */ | 13701 | /* Now, allocate enough to hold the UVS table. */ |
| 13735 | 13702 | ||
| 13736 | size = sizeof *uvs; | 13703 | size = sizeof *uvs; |
| 13737 | if (INT_MULTIPLY_WRAPV (sizeof *uvs->ranges, num_ranges, | 13704 | if (ckd_mul (&temp, num_ranges, sizeof *uvs->ranges) |
| 13738 | &temp) | 13705 | || ckd_add (&size, size, temp)) |
| 13739 | || INT_ADD_WRAPV (temp, size, &size)) | ||
| 13740 | return NULL; | 13706 | return NULL; |
| 13741 | 13707 | ||
| 13742 | uvs = xmalloc (size); | 13708 | uvs = xmalloc (size); |
| @@ -13805,9 +13771,8 @@ sfnt_read_nondefault_uvs_table (int fd, off_t offset) | |||
| 13805 | /* Now, allocate enough to hold the UVS table. */ | 13771 | /* Now, allocate enough to hold the UVS table. */ |
| 13806 | 13772 | ||
| 13807 | size = sizeof *uvs; | 13773 | size = sizeof *uvs; |
| 13808 | if (INT_MULTIPLY_WRAPV (sizeof *uvs->mappings, num_mappings, | 13774 | if (ckd_mul (&temp, num_mappings, sizeof *uvs->mappings) |
| 13809 | &temp) | 13775 | || ckd_add (&size, size, temp)) |
| 13810 | || INT_ADD_WRAPV (temp, size, &size)) | ||
| 13811 | return NULL; | 13776 | return NULL; |
| 13812 | 13777 | ||
| 13813 | uvs = xmalloc (size); | 13778 | uvs = xmalloc (size); |
| @@ -13887,9 +13852,9 @@ sfnt_create_uvs_context (struct sfnt_cmap_format_14 *cmap, int fd) | |||
| 13887 | off_t offset; | 13852 | off_t offset; |
| 13888 | struct sfnt_uvs_context *context; | 13853 | struct sfnt_uvs_context *context; |
| 13889 | 13854 | ||
| 13890 | if (INT_MULTIPLY_WRAPV (cmap->num_var_selector_records, | 13855 | if (ckd_mul (&size, cmap->num_var_selector_records, |
| 13891 | sizeof *table_offsets, &size) | 13856 | sizeof *table_offsets) |
| 13892 | || INT_MULTIPLY_WRAPV (size, 2, &size)) | 13857 | || ckd_mul (&size, size, 2)) |
| 13893 | return NULL; | 13858 | return NULL; |
| 13894 | 13859 | ||
| 13895 | context = NULL; | 13860 | context = NULL; |
| @@ -13909,9 +13874,8 @@ sfnt_create_uvs_context (struct sfnt_cmap_format_14 *cmap, int fd) | |||
| 13909 | 13874 | ||
| 13910 | if (cmap->records[i].default_uvs_offset) | 13875 | if (cmap->records[i].default_uvs_offset) |
| 13911 | { | 13876 | { |
| 13912 | if (INT_ADD_WRAPV (cmap->offset, | 13877 | if (ckd_add (&table_offsets[j].offset, cmap->offset, |
| 13913 | cmap->records[i].default_uvs_offset, | 13878 | cmap->records[i].default_uvs_offset)) |
| 13914 | &table_offsets[j].offset)) | ||
| 13915 | goto bail; | 13879 | goto bail; |
| 13916 | 13880 | ||
| 13917 | table_offsets[j++].is_nondefault_table = false; | 13881 | table_offsets[j++].is_nondefault_table = false; |
| @@ -13919,9 +13883,8 @@ sfnt_create_uvs_context (struct sfnt_cmap_format_14 *cmap, int fd) | |||
| 13919 | 13883 | ||
| 13920 | if (cmap->records[i].nondefault_uvs_offset) | 13884 | if (cmap->records[i].nondefault_uvs_offset) |
| 13921 | { | 13885 | { |
| 13922 | if (INT_ADD_WRAPV (cmap->offset, | 13886 | if (ckd_add (&table_offsets[j].offset, cmap->offset, |
| 13923 | cmap->records[i].nondefault_uvs_offset, | 13887 | cmap->records[i].nondefault_uvs_offset)) |
| 13924 | &table_offsets[j].offset)) | ||
| 13925 | goto bail; | 13888 | goto bail; |
| 13926 | 13889 | ||
| 13927 | table_offsets[j++].is_nondefault_table = true; | 13890 | table_offsets[j++].is_nondefault_table = true; |
| @@ -14359,14 +14322,12 @@ sfnt_read_fvar_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 14359 | name identifier, or 3 * sizeof (uint16_t) + axisCount * sizeof | 14322 | name identifier, or 3 * sizeof (uint16_t) + axisCount * sizeof |
| 14360 | (sfnt_fixed), meaning there is. */ | 14323 | (sfnt_fixed), meaning there is. */ |
| 14361 | 14324 | ||
| 14362 | if (INT_MULTIPLY_WRAPV (fvar->axis_count, sizeof (sfnt_fixed), | 14325 | if (ckd_mul (&temp, fvar->axis_count, sizeof (sfnt_fixed)) |
| 14363 | &temp) | 14326 | || ckd_add (&non_ps_size, temp, 2 * sizeof (uint16_t))) |
| 14364 | || INT_ADD_WRAPV (2 * sizeof (uint16_t), temp, &non_ps_size)) | ||
| 14365 | goto bail; | 14327 | goto bail; |
| 14366 | 14328 | ||
| 14367 | if (INT_MULTIPLY_WRAPV (fvar->axis_count, sizeof (sfnt_fixed), | 14329 | if (ckd_mul (&temp, fvar->axis_count, sizeof (sfnt_fixed)) |
| 14368 | &temp) | 14330 | || ckd_add (&ps_size, temp, 3 * sizeof (uint16_t))) |
| 14369 | || INT_ADD_WRAPV (3 * sizeof (uint16_t), temp, &ps_size)) | ||
| 14370 | goto bail; | 14331 | goto bail; |
| 14371 | 14332 | ||
| 14372 | if (fvar->instance_size != non_ps_size | 14333 | if (fvar->instance_size != non_ps_size |
| @@ -14376,8 +14337,7 @@ sfnt_read_fvar_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 14376 | /* Now compute the offset of the axis data from the start of the | 14337 | /* Now compute the offset of the axis data from the start of the |
| 14377 | font file. */ | 14338 | font file. */ |
| 14378 | 14339 | ||
| 14379 | if (INT_ADD_WRAPV (fvar->offset_to_data, directory->offset, | 14340 | if (ckd_add (&offset, fvar->offset_to_data, directory->offset)) |
| 14380 | &offset)) | ||
| 14381 | goto bail; | 14341 | goto bail; |
| 14382 | 14342 | ||
| 14383 | /* Seek there. */ | 14343 | /* Seek there. */ |
| @@ -14394,28 +14354,23 @@ sfnt_read_fvar_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 14394 | sfnt_instance) + sizeof (sfnt_fixed) * fvar->instance_count * | 14354 | sfnt_instance) + sizeof (sfnt_fixed) * fvar->instance_count * |
| 14395 | fvar->axis_count. */ | 14355 | fvar->axis_count. */ |
| 14396 | 14356 | ||
| 14397 | if (INT_MULTIPLY_WRAPV (fvar->axis_count, sizeof *fvar->axis, | 14357 | if (ckd_mul (&temp, fvar->axis_count, sizeof *fvar->axis) |
| 14398 | &temp) | 14358 | || ckd_add (&min_bytes, min_bytes, temp)) |
| 14399 | || INT_ADD_WRAPV (min_bytes, temp, &min_bytes)) | ||
| 14400 | goto bail; | 14359 | goto bail; |
| 14401 | 14360 | ||
| 14402 | pad = alignof (struct sfnt_instance); | 14361 | pad = alignof (struct sfnt_instance); |
| 14403 | pad -= min_bytes & (pad - 1); | 14362 | pad -= min_bytes & (pad - 1); |
| 14404 | 14363 | ||
| 14405 | if (INT_ADD_WRAPV (min_bytes, pad, &min_bytes)) | 14364 | if (ckd_add (&min_bytes, min_bytes, pad)) |
| 14406 | goto bail; | 14365 | goto bail; |
| 14407 | 14366 | ||
| 14408 | if (INT_MULTIPLY_WRAPV (fvar->instance_count, | 14367 | if (ckd_mul (&temp, fvar->instance_count, sizeof *fvar->instance) |
| 14409 | sizeof *fvar->instance, | 14368 | || ckd_add (&min_bytes, min_bytes, temp)) |
| 14410 | &temp) | ||
| 14411 | || INT_ADD_WRAPV (min_bytes, temp, &min_bytes)) | ||
| 14412 | goto bail; | 14369 | goto bail; |
| 14413 | 14370 | ||
| 14414 | if (INT_MULTIPLY_WRAPV (fvar->instance_count, | 14371 | if (ckd_mul (&temp, fvar->instance_count, sizeof *fvar->instance->coords) |
| 14415 | sizeof *fvar->instance->coords, | 14372 | || ckd_mul (&temp, temp, fvar->axis_count) |
| 14416 | &temp) | 14373 | || ckd_add (&min_bytes, min_bytes, temp)) |
| 14417 | || INT_MULTIPLY_WRAPV (temp, fvar->axis_count, &temp) | ||
| 14418 | || INT_ADD_WRAPV (min_bytes, temp, &min_bytes)) | ||
| 14419 | goto bail; | 14374 | goto bail; |
| 14420 | 14375 | ||
| 14421 | /* Reallocate fvar. */ | 14376 | /* Reallocate fvar. */ |
| @@ -14597,9 +14552,9 @@ sfnt_read_gvar_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 14597 | goto bail; | 14552 | goto bail; |
| 14598 | 14553 | ||
| 14599 | /* Figure out how big gvar needs to be. */ | 14554 | /* Figure out how big gvar needs to be. */ |
| 14600 | if (INT_ADD_WRAPV (sizeof *gvar, coordinate_size, &min_bytes) | 14555 | if (ckd_add (&min_bytes, coordinate_size, sizeof *gvar) |
| 14601 | || INT_ADD_WRAPV (min_bytes, off_size, &min_bytes) | 14556 | || ckd_add (&min_bytes, min_bytes, off_size) |
| 14602 | || INT_ADD_WRAPV (min_bytes, data_size, &min_bytes)) | 14557 | || ckd_add (&min_bytes, min_bytes, data_size)) |
| 14603 | goto bail; | 14558 | goto bail; |
| 14604 | 14559 | ||
| 14605 | /* Now allocate enough for all of this extra data. */ | 14560 | /* Now allocate enough for all of this extra data. */ |
| @@ -14635,8 +14590,7 @@ sfnt_read_gvar_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 14635 | 14590 | ||
| 14636 | if (gvar->shared_coord_count) | 14591 | if (gvar->shared_coord_count) |
| 14637 | { | 14592 | { |
| 14638 | if (INT_ADD_WRAPV (gvar->offset_to_coord, directory->offset, | 14593 | if (ckd_add (&offset, gvar->offset_to_coord, directory->offset)) |
| 14639 | &offset)) | ||
| 14640 | goto bail; | 14594 | goto bail; |
| 14641 | 14595 | ||
| 14642 | if (lseek (fd, offset, SEEK_SET) != offset) | 14596 | if (lseek (fd, offset, SEEK_SET) != offset) |
| @@ -14660,8 +14614,7 @@ sfnt_read_gvar_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 14660 | 14614 | ||
| 14661 | if (gvar->data_size) | 14615 | if (gvar->data_size) |
| 14662 | { | 14616 | { |
| 14663 | if (INT_ADD_WRAPV (gvar->offset_to_data, directory->offset, | 14617 | if (ckd_add (&offset, gvar->offset_to_data, directory->offset)) |
| 14664 | &offset)) | ||
| 14665 | goto bail; | 14618 | goto bail; |
| 14666 | 14619 | ||
| 14667 | if (lseek (fd, offset, SEEK_SET) != offset) | 14620 | if (lseek (fd, offset, SEEK_SET) != offset) |
| @@ -14757,10 +14710,10 @@ sfnt_read_avar_table (int fd, struct sfnt_offset_subtable *subtable) | |||
| 14757 | 14710 | ||
| 14758 | /* Now add one struct sfnt_short_frac_segment for each axis and | 14711 | /* Now add one struct sfnt_short_frac_segment for each axis and |
| 14759 | each of its correspondences. */ | 14712 | each of its correspondences. */ |
| 14760 | if (INT_ADD_WRAPV (sizeof (struct sfnt_short_frac_segment), | 14713 | if (ckd_add (&min_size, min_size, sizeof (struct sfnt_short_frac_segment)) |
| 14761 | min_size, &min_size) | 14714 | || ckd_add (&min_size, min_size, |
| 14762 | || INT_ADD_WRAPV (sizeof (struct sfnt_short_frac_correspondence) | 14715 | (sizeof (struct sfnt_short_frac_correspondence) |
| 14763 | * buffer[k], min_size, &min_size)) | 14716 | * buffer[k]))) |
| 14764 | goto bail1; | 14717 | goto bail1; |
| 14765 | 14718 | ||
| 14766 | /* Verify that words from here to buffer[1 + buffer[k] * 2], the | 14719 | /* 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, | |||
| 15109 | goto bail2; | 15062 | goto bail2; |
| 15110 | 15063 | ||
| 15111 | tuple += sizeof *coords * fvar->axis_count; | 15064 | tuple += sizeof *coords * fvar->axis_count; |
| 15112 | if (INT_ADD_WRAPV (size, sizeof *coords * fvar->axis_count, | 15065 | if (ckd_add (&size, size, sizeof *coords * fvar->axis_count)) |
| 15113 | &size)) | ||
| 15114 | goto bail2; | 15066 | goto bail2; |
| 15115 | } | 15067 | } |
| 15116 | else | 15068 | else |
| @@ -15122,20 +15074,20 @@ sfnt_read_cvar_table (int fd, struct sfnt_offset_subtable *subtable, | |||
| 15122 | if (index & 0x4000) | 15074 | if (index & 0x4000) |
| 15123 | { | 15075 | { |
| 15124 | tuple += fvar->axis_count * 4; | 15076 | tuple += fvar->axis_count * 4; |
| 15125 | if (INT_ADD_WRAPV (size, fvar->axis_count * 4, &size)) | 15077 | if (ckd_add (&size, size, fvar->axis_count * 4)) |
| 15126 | goto bail2; | 15078 | goto bail2; |
| 15127 | } | 15079 | } |
| 15128 | 15080 | ||
| 15129 | /* Add one point and one delta for each CVT element. */ | 15081 | /* Add one point and one delta for each CVT element. */ |
| 15130 | if (INT_ADD_WRAPV (size, cvt->num_elements * 4, &size)) | 15082 | if (ckd_add (&size, size, cvt->num_elements * 4)) |
| 15131 | goto bail2; | 15083 | goto bail2; |
| 15132 | 15084 | ||
| 15133 | /* Now add the size of the tuple. */ | 15085 | /* Now add the size of the tuple. */ |
| 15134 | if (INT_ADD_WRAPV (size, sizeof *cvar->variation, &size)) | 15086 | if (ckd_add (&size, size, sizeof *cvar->variation)) |
| 15135 | goto bail2; | 15087 | goto bail2; |
| 15136 | } | 15088 | } |
| 15137 | 15089 | ||
| 15138 | if (INT_ADD_WRAPV (sizeof *cvar, size, &size)) | 15090 | if (ckd_add (&size, size, sizeof *cvar)) |
| 15139 | goto bail2; | 15091 | goto bail2; |
| 15140 | 15092 | ||
| 15141 | /* Reallocate cvar. */ | 15093 | /* 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; | |||
| 78 | { \ | 78 | { \ |
| 79 | size_t _size; \ | 79 | size_t _size; \ |
| 80 | \ | 80 | \ |
| 81 | if (INT_MULTIPLY_WRAPV (height, stride, &_size)) \ | 81 | if (ckd_mul (&_size, height, stride)) \ |
| 82 | memory_full (SIZE_MAX); \ | 82 | memory_full (SIZE_MAX); \ |
| 83 | \ | 83 | \ |
| 84 | if (_size < MAX_ALLOCA) \ | 84 | if (_size < MAX_ALLOCA) \ |
| @@ -112,7 +112,7 @@ static size_t max_scanline_buffer_size; | |||
| 112 | size_t _size; \ | 112 | size_t _size; \ |
| 113 | void *_temp; \ | 113 | void *_temp; \ |
| 114 | \ | 114 | \ |
| 115 | if (INT_MULTIPLY_WRAPV (height, stride, &_size)) \ | 115 | if (ckd_mul (&_size, height, stride)) \ |
| 116 | memory_full (SIZE_MAX); \ | 116 | memory_full (SIZE_MAX); \ |
| 117 | \ | 117 | \ |
| 118 | if (_size > scanline_buffer.buffer_size) \ | 118 | 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, | |||
| 649 | start of the text that was inserted. */ | 649 | start of the text that was inserted. */ |
| 650 | wanted = start; | 650 | wanted = start; |
| 651 | 651 | ||
| 652 | if (INT_ADD_WRAPV (wanted, position, &wanted) | 652 | if (ckd_add (&wanted, wanted, position) || wanted < BEGV) |
| 653 | || wanted < BEGV) | ||
| 654 | wanted = BEGV; | 653 | wanted = BEGV; |
| 655 | 654 | ||
| 656 | if (wanted > ZV) | 655 | if (wanted > ZV) |
| @@ -664,8 +663,7 @@ really_commit_text (struct frame *f, EMACS_INT position, | |||
| 664 | TEXT. */ | 663 | TEXT. */ |
| 665 | wanted = PT; | 664 | wanted = PT; |
| 666 | 665 | ||
| 667 | if (INT_ADD_WRAPV (wanted, position - 1, &wanted) | 666 | if (ckd_add (&wanted, wanted, position - 1) || wanted > ZV) |
| 668 | || wanted > ZV) | ||
| 669 | wanted = ZV; | 667 | wanted = ZV; |
| 670 | 668 | ||
| 671 | if (wanted < BEGV) | 669 | if (wanted < BEGV) |
| @@ -712,8 +710,7 @@ really_commit_text (struct frame *f, EMACS_INT position, | |||
| 712 | 710 | ||
| 713 | if (position <= 0) | 711 | if (position <= 0) |
| 714 | { | 712 | { |
| 715 | if (INT_ADD_WRAPV (wanted, position, &wanted) | 713 | if (ckd_add (&wanted, wanted, position) || wanted < BEGV) |
| 716 | || wanted < BEGV) | ||
| 717 | wanted = BEGV; | 714 | wanted = BEGV; |
| 718 | 715 | ||
| 719 | if (wanted > ZV) | 716 | if (wanted > ZV) |
| @@ -725,8 +722,7 @@ really_commit_text (struct frame *f, EMACS_INT position, | |||
| 725 | { | 722 | { |
| 726 | wanted = PT; | 723 | wanted = PT; |
| 727 | 724 | ||
| 728 | if (INT_ADD_WRAPV (wanted, position - 1, &wanted) | 725 | if (ckd_add (&wanted, wanted, position - 1) || wanted > ZV) |
| 729 | || wanted > ZV) | ||
| 730 | wanted = ZV; | 726 | wanted = ZV; |
| 731 | 727 | ||
| 732 | if (wanted < BEGV) | 728 | if (wanted < BEGV) |
| @@ -870,8 +866,7 @@ really_set_composing_text (struct frame *f, ptrdiff_t position, | |||
| 870 | { | 866 | { |
| 871 | wanted = start; | 867 | wanted = start; |
| 872 | 868 | ||
| 873 | if (INT_SUBTRACT_WRAPV (wanted, position, &wanted) | 869 | if (ckd_sub (&wanted, wanted, position) || wanted < BEGV) |
| 874 | || wanted < BEGV) | ||
| 875 | wanted = BEGV; | 870 | wanted = BEGV; |
| 876 | 871 | ||
| 877 | if (wanted > ZV) | 872 | if (wanted > ZV) |
| @@ -885,8 +880,7 @@ really_set_composing_text (struct frame *f, ptrdiff_t position, | |||
| 885 | /* end should be PT after the edit. */ | 880 | /* end should be PT after the edit. */ |
| 886 | eassert (end == PT); | 881 | eassert (end == PT); |
| 887 | 882 | ||
| 888 | if (INT_ADD_WRAPV (wanted, position - 1, &wanted) | 883 | if (ckd_add (&wanted, wanted, position - 1) || wanted > ZV) |
| 889 | || wanted > ZV) | ||
| 890 | wanted = ZV; | 884 | wanted = ZV; |
| 891 | 885 | ||
| 892 | if (wanted < BEGV) | 886 | if (wanted < BEGV) |
| @@ -1256,8 +1250,7 @@ really_replace_text (struct frame *f, ptrdiff_t start, ptrdiff_t end, | |||
| 1256 | 1250 | ||
| 1257 | if (position <= 0) | 1251 | if (position <= 0) |
| 1258 | { | 1252 | { |
| 1259 | if (INT_ADD_WRAPV (wanted, position, &wanted) | 1253 | if (ckd_add (&wanted, wanted, position) || wanted < BEGV) |
| 1260 | || wanted < BEGV) | ||
| 1261 | wanted = BEGV; | 1254 | wanted = BEGV; |
| 1262 | 1255 | ||
| 1263 | if (wanted > ZV) | 1256 | if (wanted > ZV) |
| @@ -1269,8 +1262,7 @@ really_replace_text (struct frame *f, ptrdiff_t start, ptrdiff_t end, | |||
| 1269 | { | 1262 | { |
| 1270 | wanted = PT; | 1263 | wanted = PT; |
| 1271 | 1264 | ||
| 1272 | if (INT_ADD_WRAPV (wanted, position - 1, &wanted) | 1265 | if (ckd_add (&wanted, wanted, position - 1) || wanted > ZV) |
| 1273 | || wanted > ZV) | ||
| 1274 | wanted = ZV; | 1266 | wanted = ZV; |
| 1275 | 1267 | ||
| 1276 | if (wanted < BEGV) | 1268 | if (wanted < BEGV) |
| @@ -2020,8 +2012,8 @@ get_surrounding_text (struct frame *f, ptrdiff_t left, | |||
| 2020 | 2012 | ||
| 2021 | /* And subtract left and right. */ | 2013 | /* And subtract left and right. */ |
| 2022 | 2014 | ||
| 2023 | if (INT_SUBTRACT_WRAPV (start, left, &start) | 2015 | if (ckd_sub (&start, start, left) |
| 2024 | || INT_ADD_WRAPV (end, right, &end)) | 2016 | || ckd_add (&end, end, right)) |
| 2025 | goto finish; | 2017 | goto finish; |
| 2026 | 2018 | ||
| 2027 | start = max (start, BEGV); | 2019 | start = max (start, BEGV); |