From 56571a70d99a896777146e9588d9f6a04124c9a5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 16 Sep 2026 16:05:26 -0700 Subject: [PATCH] std.Build.Cache: fix flagsAndPath implementation it was scanning for sentinel starting from flags rather than flags + 1, which could lead to the scenario where the path is empty because flags is zero --- lib/std/Build/Cache.zig | 14 ++++++-------- src/Compilation.zig | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index 3eaeef3ab92ab88f11c4da1418aa84fb51c960ef..d0a7d93e16b1207429222ee77a96361a345290e4 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -499,9 +499,10 @@ pub const Manifest = struct { pub fn flagsAndPath(off: File.Offset, contents: []const u8) [:0]const u8 { const flags_off = @offsetOf(File, "flags"); comptime assert(@offsetOf(File, "path_start") - flags_off == 1); - const hash_start = @backingInt(off) + flags_off; - const hash_end = mem.findScalarPos(u8, contents, hash_start, 0).?; - return contents[hash_start..hash_end :0]; + const start = @backingInt(off) + flags_off; + // Scan for the sentinel starting from the path_start offset because flags might be zero. + const end = mem.findScalarPos(u8, contents, start + 1, 0).?; + return contents[start..end :0]; } pub fn pathFallible(off: File.Offset, contents: []const u8) error{InvalidFormat}![:0]const u8 { @@ -898,7 +899,8 @@ pub const Manifest = struct { // This is *not* hashing the contents of the input files. It is the // flags (including prefix) and path only. for (man.files.keys()[0..man.input_paths.items.len]) |file_off| { - man.hashFlagsAndPath(file_off, &man.hash.hasher); + const flags_and_path = file_off.flagsAndPath(man.contents.items); + man.hash.hasher.update(mem.absorbSentinel(flags_and_path)); } var input_digest: BinDigest = undefined; @@ -2288,10 +2290,6 @@ pub const Manifest = struct { hasher.update(contents.items[contents_start..][0..contents_len]); hasher.final(bin_digest); } - - fn hashFlagsAndPath(m: *const Manifest, off: File.Offset, hasher: *Hasher) void { - hasher.update(off.flagsAndPath(m.contents.items)); - } }; /// Create/Write a file, close it, then grab its stat.mtime timestamp. diff --git a/src/Compilation.zig b/src/Compilation.zig index 5b3131bf8734ffec53c0bfed5fc04d119716b313..d94b7146b59afed2774f83d89b63604794a1ddbd 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -5530,7 +5530,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr return comp.failCObj(c_object, "checking cache failed: {f}", .{diagnostic.fmt(&man)}); }, }; - log.debug("C object cache {f}", .{status.fmt(&man)}); + log.debug("C object {q} cache {f}", .{ c_object.src.src_path, status.fmt(&man) }); if (status == .hit) break :d man.hitDigestHex(); } var argv: std.array_list.Managed([]const u8) = .init(gpa); -- 2.54.0