Skip to content

Commit

Permalink
Fix Coverity Scan warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 4, 2025
1 parent 25a0338 commit 6d3dd57
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions autotest/cpp/testfloat16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ TEST(TestFloat16, math)
if (x >= 0)
{
using std::sqrt;
// coverity[negative_returns]
EXPECT_NEAR(sqrt(GFloat16(x)), sqrt(x), fabs(sqrt(x) / 1024));
}
}
Expand Down
16 changes: 15 additions & 1 deletion gcore/gdalalgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,21 @@ class CPL_DLL GDALAlgorithmArg /* non-final */
!std::is_same_v<T, std::vector<GDALArgDatasetValue>>)
{
if (decl.HasDefaultValue())
*std::get<T *>(m_value) = decl.GetDefault<T>();
{
try
{
*std::get<T *>(m_value) = decl.GetDefault<T>();
}
catch (const std::bad_variant_access &e)
{
// I don't think that can happen, but Coverity Scan thinks
// so
CPLError(CE_Failure, CPLE_AppDefined,
"*std::get<T *>(m_value) = decl.GetDefault<T>() "
"failed: %s",
e.what());
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions ogr/ogrsf_frmts/ngw/gdalngwdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ bool OGRNGWDataset::AddFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
}

auto osPalyload = CreateNGWLookupTableJson(
dynamic_cast<OGRCodedFieldDomain *>(domain.get()),
static_cast<OGRCodedFieldDomain *>(domain.get()),
static_cast<GIntBig>(std::stol(osResourceId)));

std::string osResourceIdInt =
Expand Down Expand Up @@ -1801,7 +1801,7 @@ bool OGRNGWDataset::UpdateFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
}

auto osPayload = CreateNGWLookupTableJson(
dynamic_cast<const OGRCodedFieldDomain *>(domain.get()),
static_cast<const OGRCodedFieldDomain *>(domain.get()),
static_cast<GIntBig>(std::stol(osResourceId)));

if (!NGWAPI::UpdateResource(osUrl, osResourceId, osPayload, GetHeaders()))
Expand Down Expand Up @@ -1859,4 +1859,4 @@ GIntBig OGRNGWDataset::GetDomainIdByName(const std::string &osDomainName) const
}
}
return 0L;
}
}

0 comments on commit 6d3dd57

Please sign in to comment.