authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-12-30 18:17:26+11:00
committergravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-12-31 15:36:58+11:00
log41d5aa1b365516c5f1bad63bfa3bdd7ad0ba6842
tree83c0bd392b40e04518d480fdf4773921bde9017a
parent17485110589c953aa39de75a9fb75ac415e4f9cd

prevent by-length slice compile error in static json parsing


1 files changed, 12 insertions(+), 0 deletions(-)

lib/std/json/static.zig+12
......@@ -402,21 +402,33 @@ pub fn innerParse(
402402 },
403403 .partial_string_escaped_1 => |arr| {
404404 if (i + arr.len > r.len) return error.LengthMismatch;
405 // tell the compiler that the by-length slice below is valid;
406 // this assert is required for the inequality to be comptime-known
407 if (arr.len > r.len) unreachable;
405408 @memcpy(r[i..][0..arr.len], arr[0..]);
406409 i += arr.len;
407410 },
408411 .partial_string_escaped_2 => |arr| {
409412 if (i + arr.len > r.len) return error.LengthMismatch;
413 // tell the compiler that the by-length slice below is valid;
414 // this assert is required for the inequality to be comptime-known
415 if (arr.len > r.len) unreachable;
410416 @memcpy(r[i..][0..arr.len], arr[0..]);
411417 i += arr.len;
412418 },
413419 .partial_string_escaped_3 => |arr| {
414420 if (i + arr.len > r.len) return error.LengthMismatch;
421 // tell the compiler that the by-length slice below is valid;
422 // this assert is required for the inequality to be comptime-known
423 if (arr.len > r.len) unreachable;
415424 @memcpy(r[i..][0..arr.len], arr[0..]);
416425 i += arr.len;
417426 },
418427 .partial_string_escaped_4 => |arr| {
419428 if (i + arr.len > r.len) return error.LengthMismatch;
429 // tell the compiler that the by-length slice below is valid;
430 // this assert is required for the inequality to be comptime-known
431 if (arr.len > r.len) unreachable;
420432 @memcpy(r[i..][0..arr.len], arr[0..]);
421433 i += arr.len;
422434 },