Skip to content

Commit c0362e1

Browse files
authored
fix: correct array and map header sizes (#14)
1 parent ca0f153 commit c0362e1

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/array.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ const unpackAny = @import("any.zig").unpackAny;
1616
pub fn sizeOfPackedArrayHeader(len: usize) !usize {
1717
if (len <= hdrs.FIXARRAY_MAX - hdrs.FIXARRAY_MIN) {
1818
return 1;
19-
} else if (len <= std.math.maxInt(u8)) {
20-
return 1 + @sizeOf(u8);
2119
} else if (len <= std.math.maxInt(u16)) {
2220
return 1 + @sizeOf(u16);
2321
} else if (len <= std.math.maxInt(u32)) {
@@ -141,3 +139,7 @@ test "packArray: null" {
141139
test "sizeOfPackedArray" {
142140
try std.testing.expectEqual(1, sizeOfPackedArray(0));
143141
}
142+
143+
test "sizeOfPackedArrayHeader: array16 boundary" {
144+
try std.testing.expectEqual(3, sizeOfPackedArrayHeader(16));
145+
}

src/map.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ const unpackAny = @import("any.zig").unpackAny;
1717
pub fn sizeOfPackedMapHeader(len: usize) !usize {
1818
if (len <= hdrs.FIXMAP_MAX - hdrs.FIXMAP_MIN) {
1919
return 1;
20-
} else if (len <= std.math.maxInt(u8)) {
21-
return 1 + @sizeOf(u8);
2220
} else if (len <= std.math.maxInt(u16)) {
2321
return 1 + @sizeOf(u16);
2422
} else if (len <= std.math.maxInt(u32)) {
@@ -156,3 +154,7 @@ test "unpackMap unmanaged" {
156154
test "sizeOfPackedMap" {
157155
try std.testing.expectEqual(1, sizeOfPackedMap(0));
158156
}
157+
158+
test "sizeOfPackedMapHeader: map16 boundary" {
159+
try std.testing.expectEqual(3, sizeOfPackedMapHeader(16));
160+
}

0 commit comments

Comments
 (0)