Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang tidy enable clang-analyzer-core.UndefinedBinaryOperatorResult #17649

Merged
merged 4 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Checks: >
-bugprone-signed-char-misuse,
-bugprone-copy-constructor-init,
-clang-analyzer-core.CallAndMessage,
-clang-analyzer-core.UndefinedBinaryOperatorResult,
-clang-analyzer-core.NullDereference,
-clang-analyzer-optin.cplusplus.UninitializedObject,
-clang-analyzer-core.uninitialized.Branch,
Expand Down
10 changes: 5 additions & 5 deletions src/access/tests/TestAccessControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,11 +1984,11 @@ void TestSubjectsTargets(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, accessControl.CreateEntry(&index, entry) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, int(index) == 2);

FabricIndex fabricIndex;
Privilege privilege;
AuthMode authMode;
size_t count;
NodeId subject;
FabricIndex fabricIndex = 0;
Privilege privilege = Privilege::kView;
AuthMode authMode = AuthMode::kNone;
size_t count = 0;
NodeId subject = kUndefinedNodeId;
Target target;

NL_TEST_ASSERT(inSuite, accessControl.ReadEntry(0, entry) == CHIP_NO_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestClusterStateCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class CacheValidator : public ClusterStateCache::Callback
case AttributeInstruction::kAttributeA: {
ChipLogProgress(DataManagement, "\t\t -- Validating A");

Clusters::TestCluster::Attributes::Int16u::TypeInfo::DecodableType v;
Clusters::TestCluster::Attributes::Int16u::TypeInfo::DecodableType v = 0;
err = cache->Get<Clusters::TestCluster::Attributes::Int16u::TypeInfo>(path, v);
if (err == CHIP_ERROR_IM_STATUS_CODE_RECEIVED)
{
Expand Down
5 changes: 5 additions & 0 deletions src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ void emberAfCopyLongString(uint8_t * dest, const uint8_t * src, size_t size)
// default value of NULL is treated as all zeroes.
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber)
{
if (len == 0)
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
{
// no length means nothing to compare. Shouldn't even happen, since len is sizeof(some-integer-type).
return 0;
}
uint8_t i, j, k;
if (signedNumber)
{ // signed number comparison
Expand Down
6 changes: 6 additions & 0 deletions src/lib/asn1/ASN1Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,18 @@ CHIP_ERROR ASN1Reader::GetInteger(int64_t & val)
ReturnErrorCodeIf(ValueLen > sizeof(int64_t), ASN1_ERROR_VALUE_OVERFLOW);
ReturnErrorCodeIf(mElemStart + mHeadLen + ValueLen > mContainerEnd, ASN1_ERROR_UNDERRUN);

// NOLINTBEGIN(clang-analyzer-core.UndefinedBinaryOperatorResult)
//
// TODO: clang-tidy says that if val is -1, then (val << 8) is not defined.
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
// added above supression to keep clang-tidy validating the rest of the files, however
// this complain likely needs fixing.
const uint8_t * p = Value;
val = ((*p & 0x80) == 0) ? 0 : -1;
for (uint32_t i = ValueLen; i > 0; i--, p++)
{
val = (val << 8) | *p;
}
// NOLINTEND(clang-analyzer-core.UndefinedBinaryOperatorResult)

return CHIP_NO_ERROR;
}
Expand Down