Skip to content

Commit 08bdd3a

Browse files
committed
cocci: drop bogus xstrdup_or_null() rule
13092a9 (cocci: refactor common patterns to use xstrdup_or_null(), 2016-10-12) introduced a rule to rewrite this conditional call to xstrdup(E) and an assignment to variable V: - if (E) - V = xstrdup(E); into an unconditional call to xstrdup_or_null(E) and an assignment to variable V: + V = xstrdup_or_null(E); which is utterly bogus. The original code may already have an acceptable value in V and the conditional assignment may be to improve the value already in V with a copy of a better value E when (and only when) E is not NULL. The rewritten construct unconditionally discards the existing value of V and replaces it with a copy of E, even when E is NULL, which changes the meaning of the program. By the way, if it were -if (E && !V) - V = xstrdup(E); +V = xstrdup_or_null(E); it would probably have been correct. But there is no existing code that would have been improved by such a rule, so let's just remove the bogus one without replacing with the more specific one. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6cd33dc commit 08bdd3a

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

contrib/coccinelle/xstrdup_or_null.cocci

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
@@
2-
expression E;
3-
expression V;
4-
@@
5-
- if (E)
6-
- V = xstrdup(E);
7-
+ V = xstrdup_or_null(E);
8-
91
@@
102
expression E;
113
@@

0 commit comments

Comments
 (0)