aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPo Lu2023-05-18 09:04:57 +0800
committerPo Lu2023-05-18 09:04:57 +0800
commit074c0268fd32d6527e124cff386bb6b15cf90017 (patch)
tree62111c3c70d46a738f15514e988a707409ca45f4 /src/alloc.c
parentdb48eff8cf4a88393c0209f663ca194ee37fa747 (diff)
parent5ef169ed701fa4f850fdca5563cdd468207d5d4f (diff)
downloademacs-074c0268fd32d6527e124cff386bb6b15cf90017.tar.gz
emacs-074c0268fd32d6527e124cff386bb6b15cf90017.zip
Merge remote-tracking branch 'origin/master' into feature/android
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/alloc.c b/src/alloc.c
index d87cc44b59b..82b1c6b0355 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -867,7 +867,7 @@ xnmalloc (ptrdiff_t nitems, ptrdiff_t item_size)
867{ 867{
868 eassert (0 <= nitems && 0 < item_size); 868 eassert (0 <= nitems && 0 < item_size);
869 ptrdiff_t nbytes; 869 ptrdiff_t nbytes;
870 if (INT_MULTIPLY_WRAPV (nitems, item_size, &nbytes) || SIZE_MAX < nbytes) 870 if (ckd_mul (&nbytes, nitems, item_size) || SIZE_MAX < nbytes)
871 memory_full (SIZE_MAX); 871 memory_full (SIZE_MAX);
872 return xmalloc (nbytes); 872 return xmalloc (nbytes);
873} 873}
@@ -881,7 +881,7 @@ xnrealloc (void *pa, ptrdiff_t nitems, ptrdiff_t item_size)
881{ 881{
882 eassert (0 <= nitems && 0 < item_size); 882 eassert (0 <= nitems && 0 < item_size);
883 ptrdiff_t nbytes; 883 ptrdiff_t nbytes;
884 if (INT_MULTIPLY_WRAPV (nitems, item_size, &nbytes) || SIZE_MAX < nbytes) 884 if (ckd_mul (&nbytes, nitems, item_size) || SIZE_MAX < nbytes)
885 memory_full (SIZE_MAX); 885 memory_full (SIZE_MAX);
886 return xrealloc (pa, nbytes); 886 return xrealloc (pa, nbytes);
887} 887}
@@ -928,13 +928,13 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
928 NITEMS_MAX, and what the C language can represent safely. */ 928 NITEMS_MAX, and what the C language can represent safely. */
929 929
930 ptrdiff_t n, nbytes; 930 ptrdiff_t n, nbytes;
931 if (INT_ADD_WRAPV (n0, n0 >> 1, &n)) 931 if (ckd_add (&n, n0, n0 >> 1))
932 n = PTRDIFF_MAX; 932 n = PTRDIFF_MAX;
933 if (0 <= nitems_max && nitems_max < n) 933 if (0 <= nitems_max && nitems_max < n)
934 n = nitems_max; 934 n = nitems_max;
935 935
936 ptrdiff_t adjusted_nbytes 936 ptrdiff_t adjusted_nbytes
937 = ((INT_MULTIPLY_WRAPV (n, item_size, &nbytes) || SIZE_MAX < nbytes) 937 = ((ckd_mul (&nbytes, n, item_size) || SIZE_MAX < nbytes)
938 ? min (PTRDIFF_MAX, SIZE_MAX) 938 ? min (PTRDIFF_MAX, SIZE_MAX)
939 : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0); 939 : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0);
940 if (adjusted_nbytes) 940 if (adjusted_nbytes)
@@ -946,9 +946,9 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
946 if (! pa) 946 if (! pa)
947 *nitems = 0; 947 *nitems = 0;
948 if (n - n0 < nitems_incr_min 948 if (n - n0 < nitems_incr_min
949 && (INT_ADD_WRAPV (n0, nitems_incr_min, &n) 949 && (ckd_add (&n, n0, nitems_incr_min)
950 || (0 <= nitems_max && nitems_max < n) 950 || (0 <= nitems_max && nitems_max < n)
951 || INT_MULTIPLY_WRAPV (n, item_size, &nbytes))) 951 || ckd_mul (&nbytes, n, item_size)))
952 memory_full (SIZE_MAX); 952 memory_full (SIZE_MAX);
953 pa = xrealloc (pa, nbytes); 953 pa = xrealloc (pa, nbytes);
954 *nitems = n; 954 *nitems = n;
@@ -2379,7 +2379,7 @@ a multibyte string even if INIT is an ASCII character. */)
2379 ptrdiff_t len = CHAR_STRING (c, str); 2379 ptrdiff_t len = CHAR_STRING (c, str);
2380 EMACS_INT string_len = XFIXNUM (length); 2380 EMACS_INT string_len = XFIXNUM (length);
2381 2381
2382 if (INT_MULTIPLY_WRAPV (len, string_len, &nbytes)) 2382 if (ckd_mul (&nbytes, len, string_len))
2383 string_overflow (); 2383 string_overflow ();
2384 val = make_clear_multibyte_string (string_len, nbytes, clearit); 2384 val = make_clear_multibyte_string (string_len, nbytes, clearit);
2385 if (!clearit) 2385 if (!clearit)
@@ -5239,7 +5239,7 @@ mark_memory (void const *start, void const *end)
5239 a Lisp_Object might be split into registers saved into 5239 a Lisp_Object might be split into registers saved into
5240 non-adjacent words and P might be the low-order word's value. */ 5240 non-adjacent words and P might be the low-order word's value. */
5241 intptr_t ip; 5241 intptr_t ip;
5242 INT_ADD_WRAPV ((intptr_t) p, (intptr_t) lispsym, &ip); 5242 ckd_add (&ip, (intptr_t) p, (intptr_t) lispsym);
5243 mark_maybe_pointer ((void *) ip, true); 5243 mark_maybe_pointer ((void *) ip, true);
5244 } 5244 }
5245} 5245}