From: Junio C Hamano <gitster@pobox•com>
To: git@vger•kernel.org
Cc: "Carlo Marcelo Arenas Belón" <carenas@gmail•com>,
"Jacob Keller" <jacob.keller@gmail•com>
Subject: [PATCH] cocci: do not directly access the .d_type member in struct dirent
Date: Wed, 18 Jun 2025 11:07:20 -0700 [thread overview]
Message-ID: <xmqq4iwcgbzb.fsf@gitster.g> (raw)
In-Reply-To: <xmqqbjqlexzd.fsf@gitster.g> (Junio C. Hamano's message of "Wed, 18 Jun 2025 10:55:02 -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 | 8 ++++++++
1 file changed, 8 insertions(+)
create mode 100644 contrib/coccinelle/dtype.cocci
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)
+ ...>}
--
2.50.0-228-g6e205fdad9
next prev parent reply other threads:[~2025-06-18 18:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-18 17:55 [PATCH] cocci: matching (multiple) identifiers Junio C Hamano
2025-06-18 18:07 ` Junio C Hamano [this message]
2025-06-18 18:31 ` [PATCH] cocci: do not directly access the .d_type member in struct dirent Collin Funk
2025-06-18 19:29 ` Junio C Hamano
2025-06-18 19:45 ` Collin Funk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq4iwcgbzb.fsf@gitster.g \
--to=gitster@pobox$(echo .)com \
--cc=carenas@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=jacob.keller@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox