git/contrib/coccinelle/xstrdup_or_null.cocci
Junio C Hamano 13092a916d cocci: refactor common patterns to use xstrdup_or_null()
d64ea0f83b ("git-compat-util: add xstrdup_or_null helper",
2015-01-12) added a handy wrapper that allows us to get a duplicate
of a string or NULL if the original is NULL, but a handful of
codepath predate its introduction or just weren't aware of it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-10-12 11:22:10 -07:00

7 lines
90 B
Text

@@
expression E;
expression V;
@@
- if (E)
- V = xstrdup(E);
+ V = xstrdup_or_null(E);