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 12, 2023
1 parent 36c3656 commit 4e17247
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions coccinelle/namedata.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,26 @@ symbol NAMEDATALEN;
- strlcpy(E1, E2, NAMEDATALEN);
+ /* You are using strlcpy with NAMEDATALEN, please consider using NameData and namestrcpy instead. */
+ namestrcpy(E1, E2);

@@
typedef NameData;
NameData E;
@@
- E.data
+ /* Use NameStr rather than accessing data member directly */
+ NameStr(E)

@@
NameData *E;
@@
- E->data
+ /* Use NameStr rather than accessing data member directly */
+ NameStr(*E)

@@
typedef Name;
Name E;
@@
- E->data
+ /* Use NameStr rather than accessing data member directly */
+ 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 4e17247

Please sign in to comment.