authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-20 00:22:26-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-20 11:56:52-07:00
log711130742b747249e472c6d6b8d77d6692a28744
tree1e59555586196a99ac13874368311beff975f050
parentbadf016b83583df98ac9c56e4147235fb9bd7f8c

InternPool: include sentinel when checking for repeating bytes


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

src/InternPool.zig+1-1
...@@ -7899,7 +7899,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:...@@ -7899,7 +7899,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
78997899
7900 repeated: {7900 repeated: {
7901 switch (aggregate.storage) {7901 switch (aggregate.storage) {
7902 .bytes => |bytes| for (bytes.toSlice(len, ip)[1..]) |byte|7902 .bytes => |bytes| for (bytes.toSlice(len_including_sentinel, ip)[1..]) |byte|
7903 if (byte != bytes.at(0, ip)) break :repeated,7903 if (byte != bytes.at(0, ip)) break :repeated,
7904 .elems => |elems| for (elems[1..@intCast(len_including_sentinel)]) |elem|7904 .elems => |elems| for (elems[1..@intCast(len_including_sentinel)]) |elem|
7905 if (elem != elems[0]) break :repeated,7905 if (elem != elems[0]) break :repeated,
test/behavior/comptime_memory.zig+10
...@@ -618,3 +618,13 @@ test "comptime store to sentinel-terminated array in an extern struct" {...@@ -618,3 +618,13 @@ test "comptime store to sentinel-terminated array in an extern struct" {
618 assert(x.a[2] == 0);618 assert(x.a[2] == 0);
619 }619 }
620}620}
621
622test "comptime store to repeated string bytes" {
623 comptime {
624 var x = "aa".*;
625 x[0] = 'b';
626 assert(x[0] == 'b');
627 assert(x[1] == 'a');
628 assert(x[2] == 0);
629 }
630}