From: Michael Orlitzky Date: Tue, 11 Dec 2018 21:13:31 +0000 (-0500) Subject: src/libadacl.c: fix a clang-tidy warning by adding a redundant check. X-Git-Tag: v0.4.2~1 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=c16c09587fb3c8de6f9cab77e3c855dd0a81938d;p=apply-default-acl.git src/libadacl.c: fix a clang-tidy warning by adding a redundant check. The clang-tidy program is complaining about a potential null pointer dereference where none is possible. To convince it of that fact, I've added a redundant equality check: we have a case where (a == b) and (a == c), and I've added (b == c) explicitly. This fixes the warning, and should have very little performance impact, so everyone is happy. --- diff --git a/src/libadacl.c b/src/libadacl.c index 956063a..6f74004 100644 --- a/src/libadacl.c +++ b/src/libadacl.c @@ -309,13 +309,20 @@ int acl_update_entry(acl_t aclp, acl_entry_t updated_entry) { } } - /* Otherwise, we have to have matching UIDs or GIDs. */ - if (updated_tag == ACL_USER) { + /* Second, they could have matching UIDs. We don't really need to + check both tags here, since we know that they're equal. However, + clang-tidy can't figure that out, and the redundant equality + check prevents it from complaining about a potential null pointer + dereference. */ + if (updated_tag == ACL_USER && existing_tag == ACL_USER) { qualifiers_match = ( *((uid_t*)existing_qualifier) == *((uid_t*)updated_qualifier) ); } - else if (updated_tag == ACL_GROUP) { + + /* Third, they could have matching GIDs. See above for why + we check the redundant condition existing_tag == ACL_GROUP. */ + if (updated_tag == ACL_GROUP && existing_tag == ACL_GROUP) { qualifiers_match = ( *((gid_t*)existing_qualifier) == *((gid_t*)updated_qualifier) ); @@ -332,7 +339,7 @@ int acl_update_entry(acl_t aclp, acl_entry_t updated_entry) { goto cleanup; } - result = ACL_SUCCESS; + result = ACL_SUCCESS; goto cleanup; } }