From dfbf1c8a0ac59206efcf819b420fbbb5bcf55251 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 2 Aug 2019 19:14:42 -0400 Subject: [PATCH] Package Kit: Avoid discarding potential error values. Spotted by Clang and the [[nodiscard]] patch. --- .../package/ActivateRepositoryConfigJob.cpp | 5 ++- src/kits/package/AddRepositoryRequest.cpp | 4 +- .../package/PackageInfoContentHandler.cpp | 45 +++++++------------ src/kits/package/PackageRoster.cpp | 8 +++- src/kits/package/RefreshRepositoryRequest.cpp | 6 ++- .../package/hpkg/PackageFileHeapWriter.cpp | 4 +- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/kits/package/ActivateRepositoryConfigJob.cpp b/src/kits/package/ActivateRepositoryConfigJob.cpp index f2bf86162c..23ff6f2464 100644 --- a/src/kits/package/ActivateRepositoryConfigJob.cpp +++ b/src/kits/package/ActivateRepositoryConfigJob.cpp @@ -46,7 +46,10 @@ ActivateRepositoryConfigJob::Execute() if (result != B_OK) return result; - fTargetEntry.SetTo(&fTargetDirectory, repoInfo.Name().String()); + result = fTargetEntry.SetTo(&fTargetDirectory, repoInfo.Name().String()); + if (result != B_OK) + return result; + if (fTargetEntry.Exists()) { BString description = BString("A repository configuration for ") << repoInfo.Name() << " already exists."; diff --git a/src/kits/package/AddRepositoryRequest.cpp b/src/kits/package/AddRepositoryRequest.cpp index 05191b7d31..71378c4a15 100644 --- a/src/kits/package/AddRepositoryRequest.cpp +++ b/src/kits/package/AddRepositoryRequest.cpp @@ -77,7 +77,9 @@ AddRepositoryRequest::CreateInitialJobs() tempEntry, fRepositoryBaseURL, targetDirectory); if (activateJob == NULL) return B_NO_MEMORY; - activateJob->AddDependency(fetchJob); + result = activateJob->AddDependency(fetchJob); + if (result != B_OK) + return result; if ((result = QueueJob(activateJob)) != B_OK) { delete activateJob; return result; diff --git a/src/kits/package/PackageInfoContentHandler.cpp b/src/kits/package/PackageInfoContentHandler.cpp index 62ae30d6d6..0e4ad1d5d1 100644 --- a/src/kits/package/PackageInfoContentHandler.cpp +++ b/src/kits/package/PackageInfoContentHandler.cpp @@ -92,44 +92,34 @@ BPackageInfoContentHandler::HandlePackageAttribute( break; case B_PACKAGE_INFO_COPYRIGHTS: - fPackageInfo.AddCopyright(value.string); - break; + return fPackageInfo.AddCopyright(value.string); case B_PACKAGE_INFO_LICENSES: - fPackageInfo.AddLicense(value.string); - break; + return fPackageInfo.AddLicense(value.string); case B_PACKAGE_INFO_PROVIDES: - fPackageInfo.AddProvides(value.resolvable); - break; + return fPackageInfo.AddProvides(value.resolvable); case B_PACKAGE_INFO_REQUIRES: - fPackageInfo.AddRequires(value.resolvableExpression); - break; + return fPackageInfo.AddRequires(value.resolvableExpression); case B_PACKAGE_INFO_SUPPLEMENTS: - fPackageInfo.AddSupplements(value.resolvableExpression); - break; + return fPackageInfo.AddSupplements(value.resolvableExpression); case B_PACKAGE_INFO_CONFLICTS: - fPackageInfo.AddConflicts(value.resolvableExpression); - break; + return fPackageInfo.AddConflicts(value.resolvableExpression); case B_PACKAGE_INFO_FRESHENS: - fPackageInfo.AddFreshens(value.resolvableExpression); - break; + return fPackageInfo.AddFreshens(value.resolvableExpression); case B_PACKAGE_INFO_REPLACES: - fPackageInfo.AddReplaces(value.string); - break; + return fPackageInfo.AddReplaces(value.string); case B_PACKAGE_INFO_URLS: - fPackageInfo.AddURL(value.string); - break; + return fPackageInfo.AddURL(value.string); case B_PACKAGE_INFO_SOURCE_URLS: - fPackageInfo.AddSourceURL(value.string); - break; + return fPackageInfo.AddSourceURL(value.string); case B_PACKAGE_INFO_CHECKSUM: fPackageInfo.SetChecksum(value.string); @@ -144,25 +134,20 @@ BPackageInfoContentHandler::HandlePackageAttribute( break; case B_PACKAGE_INFO_GLOBAL_WRITABLE_FILES: - fPackageInfo.AddGlobalWritableFileInfo( + return fPackageInfo.AddGlobalWritableFileInfo( value.globalWritableFileInfo); - break; case B_PACKAGE_INFO_USER_SETTINGS_FILES: - fPackageInfo.AddUserSettingsFileInfo(value.userSettingsFileInfo); - break; + return fPackageInfo.AddUserSettingsFileInfo(value.userSettingsFileInfo); case B_PACKAGE_INFO_USERS: - fPackageInfo.AddUser(value.user); - break; + return fPackageInfo.AddUser(value.user); case B_PACKAGE_INFO_GROUPS: - fPackageInfo.AddGroup(value.string); - break; + return fPackageInfo.AddGroup(value.string); case B_PACKAGE_INFO_POST_INSTALL_SCRIPTS: - fPackageInfo.AddPostInstallScript(value.string); - break; + return fPackageInfo.AddPostInstallScript(value.string); default: if (fErrorOutput != NULL) { diff --git a/src/kits/package/PackageRoster.cpp b/src/kits/package/PackageRoster.cpp index bae024c657..16e13fbc9d 100644 --- a/src/kits/package/PackageRoster.cpp +++ b/src/kits/package/PackageRoster.cpp @@ -181,7 +181,9 @@ BPackageRoster::GetRepositoryCache(const BString& name, return result; path.Append(name.String()); - repoCacheEntry.SetTo(path.Path()); + result = repoCacheEntry.SetTo(path.Path()); + if (result != B_OK) + return result; return repositoryCache->SetTo(repoCacheEntry); } @@ -208,7 +210,9 @@ BPackageRoster::GetRepositoryConfig(const BString& name, return result; path.Append(name.String()); - repoConfigEntry.SetTo(path.Path()); + result = repoConfigEntry.SetTo(path.Path()); + if (result != B_OK) + return result; return repositoryConfig->SetTo(repoConfigEntry); } diff --git a/src/kits/package/RefreshRepositoryRequest.cpp b/src/kits/package/RefreshRepositoryRequest.cpp index 300c1e481e..da23156f9b 100644 --- a/src/kits/package/RefreshRepositoryRequest.cpp +++ b/src/kits/package/RefreshRepositoryRequest.cpp @@ -74,7 +74,11 @@ BRefreshRepositoryRequest::CreateInitialJobs() BRepositoryCache repoCache; BPackageRoster roster; - roster.GetRepositoryCache(fRepoConfig.Name(), &repoCache); + result = roster.GetRepositoryCache(fRepoConfig.Name(), &repoCache); + if (result != B_OK) { + delete fetchChecksumJob; + return result; + } ValidateChecksumJob* validateChecksumJob = new (std::nothrow) ValidateChecksumJob(fContext, diff --git a/src/kits/package/hpkg/PackageFileHeapWriter.cpp b/src/kits/package/hpkg/PackageFileHeapWriter.cpp index 7d1f7acf3f..a86510784c 100644 --- a/src/kits/package/hpkg/PackageFileHeapWriter.cpp +++ b/src/kits/package/hpkg/PackageFileHeapWriter.cpp @@ -317,7 +317,9 @@ PackageFileHeapWriter::RemoveDataRanges( // Before we begin flush any pending data, so we don't need any special // handling and also can use the pending data buffer. - _FlushPendingData(); + status_t status = _FlushPendingData(); + if (status != B_OK) + throw status_t(status); // We potentially have to recompress all data from the first affected chunk // to the end (minus the removed ranges, of course). As a basic algorithm we