Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-05-01 08:00:30 +0300
committerJunio C Hamano <gitster@pobox.com>2022-05-01 08:23:11 +0300
commit08bdd3a1851cca1cebed0c5a26d1d4fcd5a73d16 (patch)
tree5489ff639d8aa1fa37a1dda7dbafef3a8fb399e6
parent6cd33dceed60949e2dbc32e3f0f5e67c4c882e1e (diff)
cocci: drop bogus xstrdup_or_null() rule
13092a91 (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 <gitster@pobox.com>
-rw-r--r--contrib/coccinelle/xstrdup_or_null.cocci8
1 files changed, 0 insertions, 8 deletions
diff --git a/contrib/coccinelle/xstrdup_or_null.cocci b/contrib/coccinelle/xstrdup_or_null.cocci
index 8e05d1ca4b..9c1d2939b6 100644
--- a/contrib/coccinelle/xstrdup_or_null.cocci
+++ b/contrib/coccinelle/xstrdup_or_null.cocci
@@ -1,13 +1,5 @@
@@
expression E;
-expression V;
-@@
-- if (E)
-- V = xstrdup(E);
-+ V = xstrdup_or_null(E);
-
-@@
-expression E;
@@
- xstrdup(absolute_path(E))
+ absolute_pathdup(E)