From 43373e61fa4ff7098b7b481fa72c1d205c530421 Mon Sep 17 00:00:00 2001 From: Yuto Oguchi Date: Fri, 27 May 2022 09:15:51 +0900 Subject: [PATCH] std.c: Fix incorrect dirent structure (#11602) d_name is a null-terminated string, but it is not guaranteed that the last byte of the array is null. --- lib/std/c/darwin.zig | 6 +++--- lib/std/c/netbsd.zig | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index e44da7e1f71865d2a475f37f8bbebfac6cbe6f99..bb607cb7c391ab5e0c6c6a9f8dfca1cb95b064a1 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -928,12 +928,12 @@ pub const Sigaction = extern struct { }; pub const dirent = extern struct { - d_ino: usize, - d_seekoff: usize, + d_ino: u64, + d_seekoff: u64, d_reclen: u16, d_namlen: u16, d_type: u8, - d_name: u8, // field address is address of first byte of name + d_name: [1024]u8, pub fn reclen(self: dirent) u16 { return self.d_reclen; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index e481de099676a9e68d6c988848630295bfd19f8c..d52568d03a7160518f954f47ed22d14e8c56f915 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -337,7 +337,7 @@ pub const dirent = extern struct { d_reclen: u16, d_namlen: u16, d_type: u8, - d_name: [MAXNAMLEN:0]u8, + d_name: [MAXNAMLEN + 1]u8, pub fn reclen(self: dirent) u16 { return self.d_reclen; -- 2.54.0