Niels Lohmann
6218aa212b
Throw std::length_error for operator[](SIZE_MAX) instead of corrupting the array ( #5687 )
...
For idx == SIZE_MAX, the non-const array operator[] computed the new size as
idx + 1, which wraps to 0. resize(0) then emptied the array, and the
subsequent operator[](idx) on the now-empty vector wrote one element before
its buffer. Every other too-large index (e.g. SIZE_MAX - 1) already went
through resize(), which throws std::length_error and leaves the array
unchanged; SIZE_MAX was the one value for which the overflow bypassed that
safety net.
Add a guard that throws std::length_error before computing idx + 1 when idx
is the largest representable size_type value, so the array is left
unchanged, matching the exception vector::resize() already throws for
smaller (but still too large) indices.
Fixes #5647 .
Signed-off-by: Niels Lohmann <mail@nlohmann.me >
2026-09-30 20:07:06 +02:00
..
2026-01-01 20:00:39 +01:00
2026-09-25 08:29:02 +02:00
2026-09-27 16:56:21 +02:00
2026-09-24 17:02:57 +02:00
2026-09-24 17:02:57 +02:00
2026-09-24 17:02:57 +02:00
2026-09-24 17:02:57 +02:00
2026-09-25 08:29:02 +02:00
2026-01-01 20:00:39 +01:00
2026-09-25 08:29:02 +02:00
2026-09-16 20:15:46 +02:00
2026-09-27 14:28:38 +02:00
2026-07-31 18:04:30 +02:00
2026-07-08 16:40:58 +02:00
2026-09-27 14:19:22 +02:00
2026-09-27 16:56:21 +02:00
2026-01-01 20:00:39 +01:00
2026-09-27 16:56:21 +02:00
2026-09-27 16:56:21 +02:00
2026-09-27 14:28:38 +02:00
2026-09-27 16:56:21 +02:00
2026-09-24 17:05:37 +02:00
2026-09-27 16:56:21 +02:00
2026-09-16 20:15:46 +02:00
2026-01-01 20:00:39 +01:00
2026-09-28 17:51:07 +02:00
2026-09-27 14:19:22 +02:00
2026-01-01 20:00:39 +01:00
2026-09-30 20:06:26 +02:00
2026-09-27 16:56:21 +02:00
2026-09-27 14:21:58 +02:00
2026-01-01 20:00:39 +01:00
2026-07-09 20:38:39 +02:00
2026-01-01 20:00:39 +01:00
2026-09-11 08:22:50 +02:00
2026-09-30 20:07:02 +02:00
2026-09-15 20:46:37 +02:00
2026-01-01 20:00:39 +01:00
2026-09-27 16:56:21 +02:00
2026-09-27 16:56:21 +02:00
2026-09-25 20:19:43 +02:00
2026-09-27 14:19:22 +02:00
2026-09-30 20:06:55 +02:00
2026-09-30 20:06:34 +02:00
2026-09-30 20:07:06 +02:00
2026-09-27 14:19:22 +02:00
2026-09-27 16:56:21 +02:00
2026-07-02 15:59:36 +02:00
2026-09-24 17:12:02 +02:00
2026-01-01 20:00:39 +01:00
2026-09-09 09:52:58 +02:00
2026-09-09 09:52:58 +02:00
2026-01-01 20:00:39 +01:00
2026-07-09 20:38:39 +02:00
2026-01-01 20:00:39 +01:00
2026-09-27 14:19:22 +02:00
2026-09-30 20:06:59 +02:00
2026-09-27 14:28:38 +02:00
2026-09-28 22:20:43 +02:00
2026-09-27 14:19:22 +02:00
2026-01-01 20:00:39 +01:00
2026-09-30 20:06:51 +02:00
2026-09-28 17:51:07 +02:00
2026-09-16 20:15:46 +02:00
2026-09-09 09:48:17 +02:00
2026-09-16 20:15:46 +02:00
2026-01-01 20:00:39 +01:00
2026-09-27 16:56:21 +02:00
2026-09-24 17:01:15 +02:00
2026-09-30 20:06:34 +02:00
2026-01-01 20:00:39 +01:00
2026-09-25 17:56:18 +02:00
2026-01-01 20:00:39 +01:00
2026-01-01 20:00:39 +01:00
2026-09-28 17:51:07 +02:00
2026-09-27 16:56:21 +02:00
2026-09-27 16:56:21 +02:00
2026-09-27 14:19:22 +02:00
2026-09-27 14:19:22 +02:00
2026-01-01 20:00:39 +01:00
2026-01-01 20:00:39 +01:00
2026-08-03 08:35:53 +02:00
2026-09-27 14:28:38 +02:00
2026-01-01 20:00:39 +01:00
2026-09-25 20:44:30 +02:00
2026-01-01 20:00:39 +01:00
2026-09-09 09:50:39 +02:00
2026-09-09 09:50:39 +02:00
2026-09-16 20:16:43 +02:00
2026-09-16 20:16:43 +02:00
2026-09-16 20:16:43 +02:00
2026-09-10 17:20:48 +02:00
2026-01-01 20:00:39 +01:00
2026-09-27 14:19:22 +02:00
2026-01-01 20:00:39 +01:00