Skip to content

Commit 76ea988

Browse files
committed
Make CoverityScan happy
1 parent a69982c commit 76ea988

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

apps/gdalalg_raster_tile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,14 +1588,15 @@ template <class Resource> class ResourceManager /* non final */
15881588

15891589
const std::string &GetErrorMsg() const
15901590
{
1591+
std::lock_guard oLock(m_oMutex);
15911592
return m_errorMsg;
15921593
}
15931594

15941595
protected:
15951596
virtual std::unique_ptr<Resource> CreateResources() = 0;
15961597

15971598
private:
1598-
std::mutex m_oMutex{};
1599+
mutable std::mutex m_oMutex{};
15991600
std::vector<std::unique_ptr<Resource>> m_oResources{};
16001601
std::string m_errorMsg{};
16011602
};
@@ -1929,9 +1930,8 @@ bool GDALRasterTileAlgorithm::RunImpl(GDALProgressFunc pfnProgress,
19291930
m_tileSize = 256;
19301931
if (m_maxZoomLevel < 0)
19311932
{
1932-
m_maxZoomLevel = static_cast<int>(std::ceil(std::log2(std::max(
1933-
1.0, static_cast<double>(std::max(nSrcWidth, nSrcHeight) /
1934-
m_tileSize)))));
1933+
m_maxZoomLevel = static_cast<int>(std::ceil(std::log2(
1934+
std::max(1, std::max(nSrcWidth, nSrcHeight) / m_tileSize))));
19351935
}
19361936
if (bHasNorthUpSrcGT)
19371937
{

port/cpl_worker_thread_pool.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,15 @@ bool CPLWorkerThreadPool::SubmitJob(std::function<void()> task)
210210

211211
{
212212
std::lock_guard<std::mutex> oGuardWT(psWorkerThread->m_mutex);
213-
// coverity[ uninit_use_in_call]
213+
// coverity[uninit_use_in_call]
214214
oGuard.unlock();
215215
psWorkerThread->m_cv.notify_one();
216216
}
217217

218218
CPLFree(psToFree);
219219
}
220220

221+
// coverity[double_unlock]
221222
return true;
222223
}
223224

@@ -300,7 +301,7 @@ bool CPLWorkerThreadPool::SubmitJobs(CPLThreadFunc pfnFunc,
300301
#endif
301302
{
302303
std::lock_guard<std::mutex> oGuardWT(psWorkerThread->m_mutex);
303-
// coverity[ uninit_use_in_call]
304+
// coverity[uninit_use_in_call]
304305
oGuard.unlock();
305306
psWorkerThread->m_cv.notify_one();
306307
}
@@ -453,9 +454,9 @@ void CPLWorkerThreadPool::DeclareJobFinished()
453454
std::function<void()>
454455
CPLWorkerThreadPool::GetNextJob(CPLWorkerThread *psWorkerThread)
455456
{
457+
std::unique_lock<std::mutex> oGuard(m_mutex);
456458
while (true)
457459
{
458-
std::unique_lock<std::mutex> oGuard(m_mutex);
459460
if (eState == CPLWTS_STOP)
460461
return std::function<void()>();
461462

@@ -505,6 +506,7 @@ CPLWorkerThreadPool::GetNextJob(CPLWorkerThread *psWorkerThread)
505506
oGuard.unlock();
506507
// coverity[wait_not_in_locked_loop]
507508
psWorkerThread->m_cv.wait(oGuardThisThread);
509+
oGuard.lock();
508510
}
509511
}
510512

0 commit comments

Comments
 (0)