Shrink STRING_BYTES_MAX slightly

* src/alloc.c (STRING_BYTES_MAX): Also don’t allow sizes to exceed
PTRDIFF_MAX in internal calculations when calling malloc, as those
are problematic even if the final number of bytes does not exceed
PTRDIFF_MAX.
This commit is contained in:
Paul Eggert 2026-05-20 08:32:41 -07:00
parent 59b2f8f1dc
commit 9851c5ea34

View file

@ -1501,7 +1501,7 @@ sdata_size (ptrdiff_t n)
calculating a value to be passed to malloc. */
static ptrdiff_t const STRING_BYTES_MAX =
min (STRING_BYTES_BOUND,
((SIZE_MAX
((min (PTRDIFF_MAX, SIZE_MAX)
- GC_STRING_EXTRA
- offsetof (struct sblock, data)
- SDATA_DATA_OFFSET)