From: Junio C Hamano Date: Wed, 18 Jun 2025 18:07:20 +0000 (-0700) Subject: cocci: do not directly access the .d_type member in struct dirent X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=caab88678c75c909cc1c29346c450d8380959947;p=thirdparty%2Fgit.git cocci: do not directly access the .d_type member in struct dirent 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 --- diff --git a/contrib/coccinelle/dtype.cocci b/contrib/coccinelle/dtype.cocci new file mode 100644 index 0000000000..8fe66fce95 --- /dev/null +++ b/contrib/coccinelle/dtype.cocci @@ -0,0 +1,8 @@ +@@ +identifier f != { finddata2dirent, precompose_utf8_readdir }; +struct dirent *E; +@@ + f(...) {<... +- E->d_type ++ DTYPE(E) + ...>}