Skip to content

Commit

Permalink
Merge pull request #8818 from rouault/coverity_fixes
Browse files Browse the repository at this point in the history
Coverity fixes
  • Loading branch information
rouault authored Nov 25, 2023
2 parents d430aff + 5d99523 commit 80e5e39
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
15 changes: 15 additions & 0 deletions frmts/pdf/pdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,11 @@ static int LoadPdfiumDocumentPage(const char *pszFilename,
}
auto pPage = pdfium::MakeRetain<CPDF_Page>(
poDoc->doc,
// coverity is confused by WrapRetain(), believing that multiple
// smart pointers manage the same raw pointer. Which is actually
// true, but a RetainPtr holds a reference counted object. It is
// thus safe to have several RetainPtr holding it.
// coverity[multiple_init_smart_ptr]
pdfium::WrapRetain(const_cast<CPDF_Dictionary *>(pDict.Get())));

poPage = new TPdfiumPageStruct;
Expand Down Expand Up @@ -2537,6 +2542,11 @@ GDALPDFObject *PDFDataset::GetCatalog()
const CPDF_Dictionary *catalog = m_poDocPdfium->doc->GetRoot();
if (catalog)
m_poCatalogObject =
// coverity is confused by WrapRetain(), believing that multiple
// smart pointers manage the same raw pointer. Which is actually
// true, but a RetainPtr holds a reference counted object. It is
// thus safe to have several RetainPtr holding it.
// coverity[multiple_init_smart_ptr]
GDALPDFObjectPdfium::Build(pdfium::WrapRetain(catalog));
}
#endif // ~ HAVE_PDFIUM
Expand Down Expand Up @@ -5401,6 +5411,11 @@ PDFDataset *PDFDataset::Open(GDALOpenInfo *poOpenInfo)
if (bUseLib.test(PDFLIB_PDFIUM))
{
GDALPDFObjectPdfium *poRoot = GDALPDFObjectPdfium::Build(
// coverity is confused by WrapRetain(), believing that multiple
// smart pointers manage the same raw pointer. Which is actually
// true, but a RetainPtr holds a reference counted object. It is
// thus safe to have several RetainPtr holding it.
// coverity[multiple_init_smart_ptr]
pdfium::WrapRetain(poDocPdfium->doc->GetRoot()));
if (poRoot->GetType() == PDFObjectType_Dictionary)
{
Expand Down
3 changes: 1 addition & 2 deletions ogr/swq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ const char *swq_select_summarize(swq_select *select_info, int dest_column,
const char *value)

{
swq_col_def *def = &select_info->column_defs[dest_column];

/* -------------------------------------------------------------------- */
/* Do various checking. */
/* -------------------------------------------------------------------- */
Expand All @@ -333,6 +331,7 @@ const char *swq_select_summarize(swq_select *select_info, int dest_column,
dest_column >= static_cast<int>(select_info->column_defs.size()))
return "dest_column out of range in swq_select_summarize().";

swq_col_def *def = &select_info->column_defs[dest_column];
if (def->col_func == SWQCF_NONE && !def->distinct_flag)
return nullptr;

Expand Down
12 changes: 10 additions & 2 deletions port/cpl_vsil_gzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2454,15 +2454,23 @@ size_t VSIGZipWriteHandleMT::Write(const void *const pBuffer,
{
while (true)
{
// We store in a local variable instead of pCurBuffer_ directly
// to avoid Coverity Scan to be confused by the fact that we
// have used above pCurBuffer_ outside of the mutex. But what
// is protected by the mutex is aposBuffers_, not pCurBuffer_.
std::string *l_pCurBuffer = nullptr;
{
std::lock_guard<std::mutex> oLock(sMutex_);
if (!aposBuffers_.empty())
{
pCurBuffer_ = aposBuffers_.back();
l_pCurBuffer = aposBuffers_.back();
aposBuffers_.pop_back();
break;
}
}
pCurBuffer_ = l_pCurBuffer;
if (pCurBuffer_)
break;

if (poPool_)
{
poPool_->WaitEvent();
Expand Down

0 comments on commit 80e5e39

Please sign in to comment.