Skip to content
Open
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
6 changes: 5 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ sonar.projectKey=aosedge_aos_core_lib_cpp
sonar.organization=aosedge

sonar.sources=src/
sonar.exclusions=**/tests/**
sonar.exclusions=**/tests/**,\
**/pkcs11/cryptoki/**,\
**/crypto/mbedtls/drivers/**,\
**/crypto/mbedtls/mbedtls_config.h,\
**/crypto/mbedtls/pkcs11.h

sonar.tests=src/
sonar.test.inclusions=**/tests/**
Expand Down
8 changes: 4 additions & 4 deletions src/core/cm/alerts/alerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void Alerts::OnDisconnect()

Error Alerts::SendAlert(const AlertVariant& alert)
{
LockGuard lock {mMutex};
LockGuard lock {mMutex}; // NOSONAR cpp:S5489 - false positive; single LockGuard, LIFO unlock on return

LOG_DBG() << "Send alert" << Log::Field("alert", alert);

Expand Down Expand Up @@ -286,14 +286,14 @@ UniquePtr<aos::Alerts> Alerts::CreatePackage()

const auto count = Min<size_t>(cAlertItemsCount, mAlerts.Size());

package->mItems.Assign(Array<AlertVariant>(mAlerts.begin(), count));
(void)package->mItems.Assign(Array<AlertVariant>(mAlerts.begin(), count));

return package;
}

void Alerts::ShrinkCache(size_t count)
{
mAlerts.Erase(mAlerts.begin(), mAlerts.begin() + Min<size_t>(count, mAlerts.Size()));
(void)mAlerts.Erase(mAlerts.begin(), mAlerts.begin() + Min<size_t>(count, mAlerts.Size()));
}

void Alerts::NotifyListeners(const AlertVariant& alert)
Expand All @@ -306,7 +306,7 @@ void Alerts::NotifyListeners(const AlertVariant& alert)
continue;
}

receiver->OnAlertReceived(alert);
(void)receiver->OnAlertReceived(alert);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/core/cm/imagemanager/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ struct Config {
* @param other config to compare.
* @return bool.
*/
bool operator==(const Config& other) const
friend bool operator==(const Config& lhs, const Config& other)
{
return mInstallPath == other.mInstallPath && mDownloadPath == other.mDownloadPath
&& mUpdateItemTTL == other.mUpdateItemTTL && mRemoveOutdatedPeriod == other.mRemoveOutdatedPeriod;
}
return lhs.mInstallPath == other.mInstallPath && lhs.mDownloadPath == other.mDownloadPath
&& lhs.mUpdateItemTTL == other.mUpdateItemTTL && lhs.mRemoveOutdatedPeriod == other.mRemoveOutdatedPeriod;
};

/**
* Compares config.
*
* @param other config to compare.
* @return bool.
*/
bool operator!=(const Config& other) const { return !operator==(other); }
friend bool operator!=(const Config& lhs, const Config& other) { return !(lhs == other); };
};

} // namespace aos::cm::imagemanager
Expand Down
54 changes: 26 additions & 28 deletions src/core/cm/imagemanager/imagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Error ImageManager::Cancel()
LOG_DBG() << "Cancel image manager downloading";

mCancel = true;
mCondVar.NotifyAll();
(void)mCondVar.NotifyAll();

if (!mCurrentDownloadDigest.IsEmpty()) {
if (auto err = mDownloader->Cancel(mCurrentDownloadDigest); !err.IsNone()) {
Expand Down Expand Up @@ -375,9 +375,7 @@ Error ImageManager::GetIndexDigest(const String& itemID, const String& version,
return ErrorEnum::eNotFound;
}

digest = it->mIndexDigest;

return ErrorEnum::eNone;
return AOS_ERROR_WRAP(digest.Assign(it->mIndexDigest));
}

Error ImageManager::GetBlobPath(const String& digest, String& path) const
Expand All @@ -391,7 +389,9 @@ Error ImageManager::GetBlobPath(const String& digest, String& path) const
return AOS_ERROR_WRAP(err);
}

path = blobPath;
if (auto err = path.Assign(blobPath); !err.IsNone()) {
return AOS_ERROR_WRAP(err);
}

auto [exists, err] = fs::FileExist(path);
if (!err.IsNone()) {
Expand Down Expand Up @@ -448,9 +448,7 @@ Error ImageManager::GetItemCurrentVersion(const String& itemID, String& version)
return ErrorEnum::eNotFound;
}

version = it->mVersion;

return ErrorEnum::eNone;
return AOS_ERROR_WRAP(version.Assign(it->mVersion));
}

RetWithError<size_t> ImageManager::RemoveItem(const String& id, const String& version)
Expand Down Expand Up @@ -560,9 +558,9 @@ Error ImageManager::RemoveOutdatedItems()

Error ImageManager::WaitForStop()
{
UniqueLock<Mutex> lock(mMutex);
UniqueLock<Mutex> lock(mMutex); // NOSONAR cpp:S5486 - false positive; lock released before next WaitForStop()

mCondVar.Wait(lock, cRetryTimeout, [this]() { return mCancel; });
(void)mCondVar.Wait(lock, cRetryTimeout, [this]() { return mCancel; });

if (mCancel) {
return ErrorEnum::eCanceled;
Expand Down Expand Up @@ -609,7 +607,7 @@ Error ImageManager::AllocateSpaceForPartialDownloads()
return AOS_ERROR_WRAP(err);
}

space->Accept();
(void)space->Accept();

LOG_DBG() << "Allocated space for partial download" << Log::Field("path", filePath)
<< Log::Field("size", fileSize);
Expand Down Expand Up @@ -792,7 +790,7 @@ Error ImageManager::ProcessDownloadRequest(const Array<UpdateItemInfo>& itemsInf
!removeErr.IsNone()) {
LOG_ERR() << "Failed to remove old version" << Log::Field(removeErr);
} else {
storedItems.Erase(oldVersionIt);
(void)storedItems.Erase(oldVersionIt);
}
}

Expand Down Expand Up @@ -948,13 +946,13 @@ Error ImageManager::LoadIndex(const String& digest, const String& downloadPath,
<< Log::Field(removeErr);
}

space->Release();
(void)space->Release();

return;
}

if (space) {
space->Accept();
(void)space->Accept();
}
});

Expand Down Expand Up @@ -996,13 +994,13 @@ Error ImageManager::LoadManifest(const String& digest, const Array<crypto::Certi
<< Log::Field(removeErr);
}

space->Release();
(void)space->Release();

return;
}

if (space) {
space->Accept();
(void)space->Accept();
}
});

Expand Down Expand Up @@ -1044,12 +1042,12 @@ Error ImageManager::LoadBlob(const oci::ContentDescriptor& descriptor,
<< Log::Field(removeErr);
}

space->Release();
(void)space->Release();
return;
}

if (space) {
space->Accept();
(void)space->Accept();
}
});

Expand Down Expand Up @@ -1101,7 +1099,7 @@ Error ImageManager::EnsureBlob(const String& digest, const String& downloadPath,

if (auto err = mFileInfoProvider->GetFileInfo(downloadPath, downloadFileInfo, crypto::HashEnum::eSHA3_256);
!err.IsNone()) {
downloadingSpace->Release();
(void)downloadingSpace->Release();

return AOS_ERROR_WRAP(err);
}
Expand All @@ -1112,7 +1110,7 @@ Error ImageManager::EnsureBlob(const String& digest, const String& downloadPath,

LOG_WRN() << "Download checksum mismatch, retrying download" << Log::Field("digest", digest);

downloadingSpace->Release();
(void)downloadingSpace->Release();

if (auto removeErr = fs::RemoveAll(downloadPath); !removeErr.IsNone()) {
LOG_ERR() << "Failed to remove download path" << Log::Field("path", downloadPath) << Log::Field(removeErr);
Expand All @@ -1121,7 +1119,7 @@ Error ImageManager::EnsureBlob(const String& digest, const String& downloadPath,

auto err = DecryptAndValidateBlob(downloadPath, installPath, *blobInfo, certificates, certificateChains, space);

downloadingSpace->Release();
(void)downloadingSpace->Release();

if (auto removeErr = fs::RemoveAll(downloadPath); !removeErr.IsNone()) {
LOG_ERR() << "Failed to remove download path" << Log::Field("path", downloadPath) << Log::Field(removeErr);
Expand Down Expand Up @@ -1285,12 +1283,12 @@ Error ImageManager::PerformDownload(const BlobInfo& blobInfo, const String& down
LOG_WRN() << "Failed to get partial download size" << Log::Field("path", downloadPath)
<< Log::Field(retrySizeErr);

downloadingSpace->Release();
(void)downloadingSpace->Release();

return err;
}

downloadingSpace->Release();
(void)downloadingSpace->Release();

Error allocationErr;

Expand All @@ -1300,7 +1298,7 @@ Error ImageManager::PerformDownload(const BlobInfo& blobInfo, const String& down
return AOS_ERROR_WRAP(allocationErr);
}

downloadingSpace->Accept();
(void)downloadingSpace->Accept();

return err;
}
Expand Down Expand Up @@ -1420,7 +1418,7 @@ bool ImageManager::StartAction()
{
UniqueLock lock {mMutex};

mCondVar.Wait(lock, [this]() { return !mInProgress || mCancel; });
(void)mCondVar.Wait(lock, [this]() { return !mInProgress || mCancel; });

const bool cancelledWhileRunning = mCancel && mInProgress;

Expand All @@ -1440,7 +1438,7 @@ void ImageManager::StopAction()
LockGuard lock {mMutex};

mInProgress = false;
mCondVar.NotifyAll();
(void)mCondVar.NotifyAll();
}

void ImageManager::NotifyItemsStatusesChanged(const Array<UpdateItemStatus>& statuses)
Expand All @@ -1463,7 +1461,7 @@ void ImageManager::NotifyItemStatusChanged(
{
StaticArray<UpdateItemStatus, 1> status;

status.Resize(1);
(void)status.Resize(1);

status[0].mItemID = itemID;
status[0].mType = type;
Expand Down Expand Up @@ -1685,7 +1683,7 @@ RetWithError<size_t> ImageManager::CleanupOrphanedBlobs()
auto hash = blobIterator->mPath;

StaticString<oci::cDigestLen> blobDigest;
blobDigest.Append(algorithm).Append(":").Append(hash);
(void)blobDigest.Append(algorithm).Append(":").Append(hash);

if (!IsBlobUsedByItems(blobDigest, *storedItems)) {
auto filePath = fs::JoinPath(algorithmDir, hash);
Expand Down
10 changes: 5 additions & 5 deletions src/core/cm/imagemanager/itf/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ struct ItemInfo {
* @param rhs update item info to compare with.
* @return bool.
*/
bool operator==(const ItemInfo& rhs) const
friend bool operator==(const ItemInfo& lhs, const ItemInfo& rhs)
{
return mItemID == rhs.mItemID && mVersion == rhs.mVersion && mIndexDigest == rhs.mIndexDigest
&& mState == rhs.mState && mTimestamp == rhs.mTimestamp;
}
return lhs.mItemID == rhs.mItemID && lhs.mVersion == rhs.mVersion && lhs.mIndexDigest == rhs.mIndexDigest
&& lhs.mState == rhs.mState && lhs.mTimestamp == rhs.mTimestamp;
};

/**
* Compares update item info.
*
* @param rhs update item info to compare with.
* @return bool.
*/
bool operator!=(const ItemInfo& rhs) const { return !operator==(rhs); }
friend bool operator!=(const ItemInfo& lhs, const ItemInfo& rhs) { return !(lhs == rhs); };
};

/**
Expand Down
21 changes: 11 additions & 10 deletions src/core/cm/launcher/balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@
if (!imageIndex) {
LOG_ERR() << "Can't allocate image index" << Log::Field("instance", id) << Log::Field(ErrorEnum::eNoMemory);

mInstanceManager->ScheduleInstance(instance, AOS_ERROR_WRAP(ErrorEnum::eNoMemory));
(void)mInstanceManager->ScheduleInstance(instance, AOS_ERROR_WRAP(ErrorEnum::eNoMemory));

continue;
}

if (auto err = mImageInfoProvider->GetImageIndex(id.mItemID, info.mVersion, *imageIndex); !err.IsNone()) {
LOG_ERR() << "Can't get images" << Log::Field("instance", id) << Log::Field(err);

mInstanceManager->ScheduleInstance(instance, AOS_ERROR_WRAP(err));
(void)mInstanceManager->ScheduleInstance(instance, AOS_ERROR_WRAP(err));

continue;
}
Expand All @@ -125,7 +125,7 @@
if (!scheduleErr.IsNone()) {
LOG_ERR() << "Can't schedule instance" << Log::Field(scheduleErr);

mInstanceManager->ScheduleInstance(instance, scheduleErr);
(void)mInstanceManager->ScheduleInstance(instance, scheduleErr);
}
}

Expand All @@ -139,7 +139,7 @@
return AOS_ERROR_WRAP(ErrorEnum::eNoMemory);
}

auto releaseConfigs = DeferRelease(reinterpret_cast<int*>(1), [&](int*) { instance->ResetConfigs(); });
auto releaseConfigs = DeferRelease(reinterpret_cast<int32_t*>(1), [&](int32_t*) { instance->ResetConfigs(); });

if (auto err = instance->LoadConfigs(imageDescriptor); !err.IsNone()) {
return AOS_ERROR_WRAP(Error(err, "can't load instance configs"));
Expand Down Expand Up @@ -192,17 +192,18 @@

void Balancer::FilterNodesByID(Instance& instance, Array<Node*>& nodes)
{
nodes.RemoveIf([&instance](const Node* node) { return !instance.IsNodeIDOk(node->GetInfo().mNodeID); });
(void)nodes.RemoveIf([&instance](const Node* node) { return !instance.IsNodeIDOk(node->GetInfo().mNodeID); });
}

void Balancer::FilterNodesByLabels(Instance& instance, Array<Node*>& nodes)
{
nodes.RemoveIf([&instance](const Node* node) { return !instance.AreNodeLabelsOk(node->GetConfig().mLabels); });
(void)nodes.RemoveIf(
[&instance](const Node* node) { return !instance.AreNodeLabelsOk(node->GetConfig().mLabels); });
}

void Balancer::FilterNodesByResources(Instance& instance, Array<Node*>& nodes)
{
nodes.RemoveIf([&instance](const Node* node) { return !instance.AreNodeResourcesOk(*node); });
(void)nodes.RemoveIf([&instance](const Node* node) { return !instance.AreNodeResourcesOk(*node); });
}

RetWithError<Pair<Node*, const RuntimeInfo*>> Balancer::SelectRuntime(Instance& instance, const Array<Node*>& nodes)
Expand Down Expand Up @@ -296,7 +297,7 @@

// Remove node with no runtimes
if (nodeRuntimes.IsEmpty()) {
runtimes.Remove(node);
(void)runtimes.Remove(node);
}
}

Expand Down Expand Up @@ -392,7 +393,7 @@

auto topPriority = topPriorityNode->mFirst->GetConfig().mPriority;

nodes.RemoveIf(
(void)nodes.RemoveIf(
[topPriority](const NodeRuntimes& item) { return item.mFirst->GetConfig().mPriority != topPriority; });
}

Expand Down Expand Up @@ -437,7 +438,7 @@
}

// Load configs
auto releaseConfigs = DeferRelease(reinterpret_cast<int*>(1), [&](int*) { instance->ResetConfigs(); });
auto releaseConfigs = DeferRelease(reinterpret_cast<int32_t*>(1), [&](int32_t*) { instance->ResetConfigs(); });

Check failure on line 441 in src/core/cm/launcher/balancer.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly capture "instance" in a non-transient lambda.

See more on https://sonarcloud.io/project/issues?id=aosedge_aos_core_lib_cpp&issues=AZ_R55H4YaDlDaUMBzIP&open=AZ_R55H4YaDlDaUMBzIP&pullRequest=632

Check warning on line 441 in src/core/cm/launcher/balancer.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "reinterpret_cast" with a safer operation.

See more on https://sonarcloud.io/project/issues?id=aosedge_aos_core_lib_cpp&issues=AZ_R55H4YaDlDaUMBzIO&open=AZ_R55H4YaDlDaUMBzIO&pullRequest=632

if (auto err = instance->LoadConfigs(*imageDescriptor); !err.IsNone()) {
LOG_ERR() << "Can't load configs" << Log::Field("instance", id) << Log::Field(err);
Expand Down
2 changes: 1 addition & 1 deletion src/core/cm/launcher/idpool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class IDPool {
ItemEntry entry {assigned, 1};

if (auto err = mItems.Emplace(key, entry); !err.IsNone()) {
mPool.Release(assigned);
(void)mPool.Release(assigned);

return {0, AOS_ERROR_WRAP(err)};
}
Expand Down
Loading
Loading