aboutsummaryrefslogtreecommitdiff
path: root/lib/std/json
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2024-01-02 17:37:21 +0200
committerGitHub <noreply@github.com>2024-01-02 17:37:21 +0200
commitd9d840a33ac8abb0e616de862f592821a7f4a35e (patch)
treedd17b4f37cf2b08816af8a99159e5630c6268b35 /lib/std/json
parenta04d4330945565b8d6f298ace993f6954c42d0f3 (diff)
parent41d5aa1b365516c5f1bad63bfa3bdd7ad0ba6842 (diff)
downloadzig-d9d840a33ac8abb0e616de862f592821a7f4a35e.tar.gz
zig-d9d840a33ac8abb0e616de862f592821a7f4a35e.zip
Merge pull request #18410 from dweiller/by-length-slice-bug
sema: add compile error for OOB by-length slice of array
Diffstat (limited to 'lib/std/json')
-rw-r--r--lib/std/json/static.zig12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/std/json/static.zig b/lib/std/json/static.zig
index ea0bb6c0f2..d4ae6053f4 100644
--- a/lib/std/json/static.zig
+++ b/lib/std/json/static.zig
@@ -402,21 +402,33 @@ pub fn innerParse(
},
.partial_string_escaped_1 => |arr| {
if (i + arr.len > r.len) return error.LengthMismatch;
+ // tell the compiler that the by-length slice below is valid;
+ // this assert is required for the inequality to be comptime-known
+ if (arr.len > r.len) unreachable;
@memcpy(r[i..][0..arr.len], arr[0..]);
i += arr.len;
},
.partial_string_escaped_2 => |arr| {
if (i + arr.len > r.len) return error.LengthMismatch;
+ // tell the compiler that the by-length slice below is valid;
+ // this assert is required for the inequality to be comptime-known
+ if (arr.len > r.len) unreachable;
@memcpy(r[i..][0..arr.len], arr[0..]);
i += arr.len;
},
.partial_string_escaped_3 => |arr| {
if (i + arr.len > r.len) return error.LengthMismatch;
+ // tell the compiler that the by-length slice below is valid;
+ // this assert is required for the inequality to be comptime-known
+ if (arr.len > r.len) unreachable;
@memcpy(r[i..][0..arr.len], arr[0..]);
i += arr.len;
},
.partial_string_escaped_4 => |arr| {
if (i + arr.len > r.len) return error.LengthMismatch;
+ // tell the compiler that the by-length slice below is valid;
+ // this assert is required for the inequality to be comptime-known
+ if (arr.len > r.len) unreachable;
@memcpy(r[i..][0..arr.len], arr[0..]);
i += arr.len;
},