]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cocci: do not directly access the .d_type member in struct dirent
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Jun 2025 18:07:20 +0000 (11:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Jun 2025 22:42:37 +0000 (15:42 -0700)
In "struct dirent", the presence of the .d_type member should not be
assumed and the code should instead use DTYPE() macro, with possibly
a fallback check to determine the type of the file.

Add a rule to catch direct access to the .d_type member and use
DTYPE() macro instead, except in the emulation code paths that work
on platforms that do have the member.  This is probably not sufficient
to notice the lack of necessary fallback code.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/coccinelle/dtype.cocci [new file with mode: 0644]

diff --git a/contrib/coccinelle/dtype.cocci b/contrib/coccinelle/dtype.cocci
new file mode 100644 (file)
index 0000000..8fe66fc
--- /dev/null
@@ -0,0 +1,8 @@
+@@
+identifier f != { finddata2dirent, precompose_utf8_readdir };
+struct dirent *E;
+@@
+  f(...) {<...
+- E->d_type
++ DTYPE(E)
+  ...>}