diff --git a/alg/viewshed/cumulative.cpp b/alg/viewshed/cumulative.cpp index 6b24a91cec79..79d48c68c4d0 100644 --- a/alg/viewshed/cumulative.cpp +++ b/alg/viewshed/cumulative.cpp @@ -136,24 +136,34 @@ void Cumulative::runExecutor(const std::string &srcFilename, Progress &progress, { DatasetPtr srcDs(GDALDataset::Open(srcFilename.c_str(), GA_ReadOnly)); if (!srcDs) + { err = true; - - Location loc; - while (!err && m_observerQueue.pop(loc)) + } + else { - GDALDriver *memDriver = GetGDALDriverManager()->GetDriverByName("MEM"); - DatasetPtr dstDs(memDriver->Create( - "", m_extent.xSize(), m_extent.ySize(), 1, GDT_Byte, nullptr)); - err = (dstDs == nullptr); - if (!err) + Location loc; + while (!err && m_observerQueue.pop(loc)) { - ViewshedExecutor executor(*srcDs->GetRasterBand(1), - *dstDs->GetRasterBand(1), loc.x, loc.y, - m_extent, m_extent, m_opts, progress); - err = !executor.run(); + GDALDriver *memDriver = + GetGDALDriverManager()->GetDriverByName("MEM"); + DatasetPtr dstDs(memDriver ? memDriver->Create("", m_extent.xSize(), + m_extent.ySize(), 1, + GDT_Byte, nullptr) + : nullptr); + if (!dstDs) + { + err = true; + } + else + { + ViewshedExecutor executor( + *srcDs->GetRasterBand(1), *dstDs->GetRasterBand(1), loc.x, + loc.y, m_extent, m_extent, m_opts, progress); + err = !executor.run(); + if (!err) + m_datasetQueue.push(std::move(dstDs)); + } } - if (!err) - m_datasetQueue.push(std::move(dstDs)); } // Job done. Set the output queue state. If all the executor jobs have completed, diff --git a/alg/viewshed/viewshed_executor.cpp b/alg/viewshed/viewshed_executor.cpp index 643846cf1470..01a9d5e32658 100644 --- a/alg/viewshed/viewshed_executor.cpp +++ b/alg/viewshed/viewshed_executor.cpp @@ -136,6 +136,8 @@ ViewshedExecutor::ViewshedExecutor(GDALRasterBand &srcBand, // calculate the height adjustment factor. double ViewshedExecutor::calcHeightAdjFactor() { + std::lock_guard g(iMutex); + const OGRSpatialReference *poDstSRS = m_dstBand.GetDataset()->GetSpatialRef(); diff --git a/apps/gdaldem_lib.cpp b/apps/gdaldem_lib.cpp index 6d9ef904c02a..d23b2389439c 100644 --- a/apps/gdaldem_lib.cpp +++ b/apps/gdaldem_lib.cpp @@ -100,6 +100,7 @@ #include "commonutils.h" #include "gdalargumentparser.h" +#include #include #include #include @@ -1666,13 +1667,10 @@ GDALColorReliefGetRGBA(const std::vector &asColorAssociation, if (eColorSelectionMode == COLOR_SELECTION_NEAREST_ENTRY && asColorAssociation[i - 1].dfVal != dfVal) { - size_t index = i; - if (dfVal - asColorAssociation[i - 1].dfVal < - asColorAssociation[i].dfVal - dfVal) - { - --index; - } - + const size_t index = (dfVal - asColorAssociation[i - 1].dfVal < + asColorAssociation[i].dfVal - dfVal) + ? i - 1 + : i; *pnR = asColorAssociation[index].nR; *pnG = asColorAssociation[index].nG; *pnB = asColorAssociation[index].nB; diff --git a/autotest/cpp/test_alg.cpp b/autotest/cpp/test_alg.cpp index 6d58a164164e..76024d5f88c3 100644 --- a/autotest/cpp/test_alg.cpp +++ b/autotest/cpp/test_alg.cpp @@ -157,6 +157,8 @@ TEST_F(test_alg, GDALWarpResolveWorkingDataType_padfSrcNoDataReal_with_band) GDALDatasetUniquePtr poDS(GDALDriver::FromHandle(GDALGetDriverByName("MEM")) ->Create("", 1, 1, 1, GDT_Byte, nullptr)); GDALWarpOptions *psOptions = GDALCreateWarpOptions(); + // False-positive: hSrcDS is no longer used after GDALDestroyWarpOptions() + // coverity[escape] psOptions->hSrcDS = GDALDataset::ToHandle(poDS.get()); psOptions->nBandCount = 1; psOptions->panSrcBands = diff --git a/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp b/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp index eeab23d79b87..62ba490713b8 100644 --- a/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp +++ b/frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp @@ -2793,6 +2793,9 @@ KmlSuperOverlayReadDataset::Open(const char *pszFilename, auto poOvrDS = std::make_unique(); poOvrDS->bIsOvr = true; + // The life-time of objects is such that poOvrDS is destroyed when + // poDS is destroyed. + // coverity[escape] poOvrDS->poParent = poDS.get(); poOvrDS->nFactor = nFactor; poOvrDS->nRasterXSize = nFactor * poDSIcon->GetRasterXSize(); diff --git a/frmts/vrt/gdaltileindexdataset.cpp b/frmts/vrt/gdaltileindexdataset.cpp index 53215da04218..388f45136164 100644 --- a/frmts/vrt/gdaltileindexdataset.cpp +++ b/frmts/vrt/gdaltileindexdataset.cpp @@ -1184,7 +1184,7 @@ bool GDALTileIndexDataset::Open(GDALOpenInfo *poOpenInfo) ? dfOutMaxY : std::ceil(dfOutMaxY / dfResY) * dfResY); - m_oSRS = oSTACSRS; + m_oSRS = std::move(oSTACSRS); pszResX = osResX.c_str(); pszResY = osResY.c_str(); pszMinX = osMinX.c_str(); diff --git a/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp b/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp index af52e5cdd45b..d6ce19133af9 100644 --- a/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp +++ b/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp @@ -211,6 +211,7 @@ void OGRSQLiteBaseDataSource::FinishSpatialite() std::lock_guard oLock(oCleanupMutex); pfn_spatialite_cleanup_ex(ctxt); } + // coverity[thread1_overwrites_value_in_field] hSpatialiteCtxt = nullptr; } } diff --git a/port/cpl_http.cpp b/port/cpl_http.cpp index 449bb36bd39c..471adadbc20b 100644 --- a/port/cpl_http.cpp +++ b/port/cpl_http.cpp @@ -556,7 +556,7 @@ char **CPLHTTPGetOptionsFromEnv(const char *pszFilename) { CPLStringList aosOptions; std::string osNonStreamingFilename; - if (STARTS_WITH(pszFilename, "/vsi")) + if (pszFilename && STARTS_WITH(pszFilename, "/vsi")) { VSIFilesystemHandler *poFSHandler = VSIFileManager::GetHandler(pszFilename); diff --git a/port/cpl_worker_thread_pool.cpp b/port/cpl_worker_thread_pool.cpp index c3b7df7f53bc..6136b0febb03 100644 --- a/port/cpl_worker_thread_pool.cpp +++ b/port/cpl_worker_thread_pool.cpp @@ -611,8 +611,8 @@ bool CPLJobQueue::SubmitJob(std::function task) } // cppcheck-suppress knownConditionTrueFalse + // coverity[uninit_member,copy_constructor_call] return m_poPool->SubmitJob( - // coverity[uninit_member,copy_constructor_call] [this, task] { task();