authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2021-05-30 17:08:27+10:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-05-31 14:09:59+03:00
log556d3e3d800378efcf9d7d35ad63879cc06c5e88
treed7a6e09c0a76d9ad3c0b8a969064303548b8ef6f
parent11ae6c42c1851fc44b286e5a76f73d55ea0bca5e

std: fix json.parse with 0 length arrays


1 files changed, 4 insertions(+), 2 deletions(-)

lib/std/json.zig+4-2
......@@ -1698,10 +1698,11 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
16981698 var r: T = undefined;
16991699 var i: usize = 0;
17001700 errdefer {
1701 while (true) : (i -= 1) {
1701 // Without the r.len check `r[i]` is not allowed
1702 if (r.len > 0) while (true) : (i -= 1) {
17021703 parseFree(arrayInfo.child, r[i], options);
17031704 if (i == 0) break;
1704 }
1705 };
17051706 }
17061707 while (i < r.len) : (i += 1) {
17071708 r[i] = try parse(arrayInfo.child, tokens, options);
......@@ -1854,6 +1855,7 @@ test "parse" {
18541855
18551856 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
18561857 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
1858 try testing.expectEqual(@as([0]u8, undefined), try parse([0]u8, &TokenStream.init("[]"), ParseOptions{}));
18571859}
18581860
18591861test "parse into enum" {