Skip to content

Commit

Permalink
Add Coccinelle rule to use NameStr
Browse files Browse the repository at this point in the history
Direct access of the `.data` member of `NameData` structures are
discuraged and `NameStr` should be used instead.

Also adding one instance that was missed in #5336.
  • Loading branch information
mkindahl committed Dec 11, 2023
1 parent 887a39d commit 02aa733
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions coccinelle/namestr.cocci
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Find direct access of data member of a NameData structure
//
// These should use NameStr instead.

@@
typedef NameData;
typedef Name;
NameData E;
@@
- E.data
+ NameStr(E)

@@
NameData *E;
@@
- E->data
+ NameStr(*E)

@@
Name E;
@@
- E->data
+ NameStr(*E)


2 changes: 1 addition & 1 deletion tsl/src/deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ column_is_serial(Relation rel, Name column)
NameStr(rel->rd_rel->relname));
InitFunctionCallInfoData(*fcinfo, NULL, 2, InvalidOid, NULL, NULL);
FC_ARG(fcinfo, 0) = CStringGetTextDatum(relation_name);
FC_ARG(fcinfo, 1) = CStringGetTextDatum(column->data);
FC_ARG(fcinfo, 1) = CStringGetTextDatum(NameStr(*column));
FC_NULL(fcinfo, 0) = false;
FC_NULL(fcinfo, 1) = false;
pg_get_serial_sequence(fcinfo);
Expand Down

0 comments on commit 02aa733

Please sign in to comment.