aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2024-04-08 12:44:42 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2024-04-08 13:24:08 -0400
commit7611d90ba011fb030523e669e85acfb6faae5d19 (patch)
treef1b48f3ac73681c402dce10b5857ecc0f84dd7a4 /lib/std
parent4cd92567e7392b0fe390562d7ea52f68357bb45a (diff)
downloadzig-7611d90ba011fb030523e669e85acfb6faae5d19.tar.gz
zig-7611d90ba011fb030523e669e85acfb6faae5d19.zip
InternPool: remove slice from byte aggregate keys
This deletes a ton of lookups and avoids many UAF bugs. Closes #19485
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/zig/Zir.zig8
1 files changed, 2 insertions, 6 deletions
diff --git a/lib/std/zig/Zir.zig b/lib/std/zig/Zir.zig
index db082b7f8e..64e8a1c805 100644
--- a/lib/std/zig/Zir.zig
+++ b/lib/std/zig/Zir.zig
@@ -106,12 +106,8 @@ pub const NullTerminatedString = enum(u32) {
/// Given an index into `string_bytes` returns the null-terminated string found there.
pub fn nullTerminatedString(code: Zir, index: NullTerminatedString) [:0]const u8 {
- const start = @intFromEnum(index);
- var end: u32 = start;
- while (code.string_bytes[end] != 0) {
- end += 1;
- }
- return code.string_bytes[start..end :0];
+ const slice = code.string_bytes[@intFromEnum(index)..];
+ return slice[0..std.mem.indexOfScalar(u8, slice, 0).? :0];
}
pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {