summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-03-09 23:08:53 +0100
committerThomas Haller <thaller@redhat.com>2022-03-09 23:14:37 +0100
commita628a35e80165c13e59d0061c0e416101830d0f5 (patch)
tree97bfa7ac7f5953f4245ce6ed3f7c19a89e8ddf70
parent2ccfc86939f1d211d713a8a16f2cfd6fa87d349b (diff)
downloadNetworkManager-a628a35e80165c13e59d0061c0e416101830d0f5.tar.gz
contrib/checkpatch: try to warn about uninitialized GError variables
When we have a GError* variable on the stack, we usually want to pass it on to function that can fail. In that case, the variable MUST be initialized to NULL. This is an easy mistake to make. Note that this check still can have lots of false positives, for example, if you have a struct with an GError field. In that case, you would need to ensure that the entire struct is initialized. Ignore the warning then. Also, the check misses if you declare multiple variables on one line. But that is already discouraged by our style.
-rwxr-xr-xcontrib/scripts/checkpatch.pl1
1 files changed, 1 insertions, 0 deletions
diff --git a/contrib/scripts/checkpatch.pl b/contrib/scripts/checkpatch.pl
index 733a42d7b0..4c8d512577 100755
--- a/contrib/scripts/checkpatch.pl
+++ b/contrib/scripts/checkpatch.pl
@@ -193,6 +193,7 @@ complain ("XXX marker are reserved for development while work-in-progress. Use T
complain ("This gtk-doc annotation looks wrong") if $line =~ /\*.*\( *(transfer-(none|container|full)|allow none) *\) *(:|\()/;
complain ("Prefer nm_assert() or g_return*() to g_assert*()") if $line =~ /g_assert/ and (not $filename =~ /\/tests\//) and (not $filename =~ /\/nm-test-/);
complain ("Use gs_free_error with GError variables") if $line =~ /\bgs_free\b +GError *\*/;
+complain ("Initialize GError variables to NULL, if you pass them on") if $line =~ /\bGError +\*([a-z0-9_]+);/;
complain ("Don't use strcmp/g_strcmp0 unless you need to sort. Consider nm_streq()/nm_streq0(),NM_IN_STRSET() for testing equality") if $line =~ /\b(strcmp|g_strcmp0)\b/;
complain ("Don't use API that uses the numeric source id. Instead, use GSource and API like nm_g_idle_add(), nm_g_idle_add_source(), nm_clear_g_source_inst(), etc.") if $line =~ /\b(g_idle_add|g_idle_add_full|g_timeout_add|g_timeout_add_seconds|g_source_remove|nm_clear_g_source)\b/;
complain ("Prefer g_snprintf() over snprintf() (for consistency)") if $line =~ /\b(snprintf)\b/;