git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] cocci: do not directly access the .d_type member in struct dirent

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 18, 2025, 18:07 UTC
Message-ID
<xmqq4iwcgbzb.fsf@gitster.g>
In-Reply-To
<xmqqbjqlexzd.fsf@gitster.g>

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
Previous: Junio C HamanoNext: Collin Funk
Message 2 of 5 in “cocci: matching (multiple) identifiers”
  1. cocci: matching (multiple) identifiersJunio C Hamano, Jun 18, 2025
  2. cocci: do not directly access the .d_type member in struct direntJunio C Hamano, Jun 18, 2025
  3. Collin FunkJun 18, 2025
  4. Junio C HamanoJun 18, 2025
  5. Collin FunkJun 18, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.