authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2021-05-09 18:10:29+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2021-05-09 18:15:42+02:00
log4e399ef62c962d0179f715afa3e50343b2825e7d
tree25dada4ecc63986e5a71bdd88ec2e8e52f6f74ef
parentf67e756211b6e69cc8fadbb6b1ec5af1bd5c7049

Initialize the Stat structure

The system `stat` structure includes padding, and, on some operating systems such as all BSDs, "spare" bytes at the end. We can't reliably compare two `Stat` values if these are uninitialized, while being later compared. This is what was causing the `fstatat` test to fail on FreeBSD since the update to LLVM 12. It was previously only passing by accident.

2 files changed, 2 insertions(+), 6 deletions(-)

lib/std/os.zig+2-2
......@@ -3408,7 +3408,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
34083408 @compileError("fstat is not yet implemented on Windows");
34093409 }
34103410
3411 var stat: Stat = undefined;
3411 var stat: Stat = mem.zeroes(Stat);
34123412 switch (errno(system.fstat(fd, &stat))) {
34133413 0 => return stat,
34143414 EINVAL => unreachable,
......@@ -3459,7 +3459,7 @@ pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!S
34593459/// Same as `fstatat` but `pathname` is null-terminated.
34603460/// See also `fstatat`.
34613461pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
3462 var stat: Stat = undefined;
3462 var stat: Stat = mem.zeroes(Stat);
34633463 switch (errno(system.fstatat(dirfd, pathname, &stat, flags))) {
34643464 0 => return stat,
34653465 EINVAL => unreachable,
lib/std/os/test.zig-4
......@@ -263,10 +263,6 @@ test "linkat with different directories" {
263263test "fstatat" {
264264 // enable when `fstat` and `fstatat` are implemented on Windows
265265 if (builtin.os.tag == .windows) return error.SkipZigTest;
266 if (builtin.os.tag == .freebsd and builtin.mode == .ReleaseFast) {
267 // https://github.com/ziglang/zig/issues/8538
268 return error.SkipZigTest;
269 }
270266
271267 var tmp = tmpDir(.{});
272268 defer tmp.cleanup();