Skip to content

Commit

Permalink
NGW: Fix Coverity Scan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Baryshnikov committed Feb 18, 2025
1 parent 8777894 commit 6c419b1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
10 changes: 5 additions & 5 deletions ogr/ogrsf_frmts/ngw/gdalngwdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static std::string GetStylesIdentifiers(const CPLJSONArray &aoStyles, int nDeep)
{
if (sOut.empty())
{
sOut = sId;
sOut = std::move(sId);
}
else
{
Expand All @@ -109,7 +109,7 @@ static std::string GetStylesIdentifiers(const CPLJSONArray &aoStyles, int nDeep)
{
if (sOut.empty())
{
sOut = sId;
sOut = std::move(sId);
}
else
{
Expand Down Expand Up @@ -1682,7 +1682,7 @@ bool OGRNGWDataset::DeleteFieldDomain(const std::string &name,
/*
* CreateNGWLookupTableJson()
*/
static std::string CreateNGWLookupTableJson(OGRCodedFieldDomain *pDomain,
static std::string CreateNGWLookupTableJson(const OGRCodedFieldDomain *pDomain,
GIntBig nResourceId)
{
CPLJSONObject oResourceJson;
Expand Down Expand Up @@ -1801,7 +1801,7 @@ bool OGRNGWDataset::UpdateFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
}

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

if (!NGWAPI::UpdateResource(osUrl, osResourceId, osPayload, GetHeaders()))
Expand Down Expand Up @@ -1851,7 +1851,7 @@ OGRNGWCodedFieldDomain OGRNGWDataset::GetDomainByID(GIntBig id) const
*/
GIntBig OGRNGWDataset::GetDomainIdByName(const std::string &osDomainName) const
{
for (auto oDom : moDomains)
for (auto const &oDom : moDomains)
{
if (oDom.second.HasDomainName(osDomainName))
{
Expand Down
88 changes: 43 additions & 45 deletions ogr/ogrsf_frmts/ngw/ngw_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,53 @@
namespace NGWAPI
{

static bool ReportErrorToCPL(const std::string &osErrorMessage)
static std::string GetErrorMessage(const CPLJSONObject &oRoot,
const std::string &osErrorMessage)
{
CPLError(CE_Failure, CPLE_AppDefined,
"NGW driver failed to fetch data with error: %s",
osErrorMessage.c_str());

return false;
if (oRoot.IsValid())
{
std::string osErrorMessageInt =
oRoot.GetString("message", osErrorMessage);
if (!osErrorMessageInt.empty())
{
return osErrorMessageInt;
}
}
return osErrorMessage;
}

bool CheckRequestResult(bool bResult, const CPLJSONObject &oRoot,
const std::string &osErrorMessage)
{
if (!bResult)
{
if (oRoot.IsValid())
{
std::string osErrorMessageInt =
oRoot.GetString("message", osErrorMessage);
if (!osErrorMessageInt.empty())
{
return ReportErrorToCPL(osErrorMessageInt);
}
}
return ReportErrorToCPL(osErrorMessage);
}
auto osMsg = GetErrorMessage(oRoot, osErrorMessage);

if (!oRoot.IsValid())
{
return ReportErrorToCPL(osErrorMessage);
CPLError(CE_Failure, CPLE_AppDefined,
"NGW driver failed to fetch data with error: %s",
osMsg.c_str());
return false;
}

return true;
}

static void ReportError(const GByte *pabyData, int nDataLen,
const std::string &osErrorMessage)
{
CPLJSONDocument oResult;
if (oResult.LoadMemory(pabyData, nDataLen))
{
CPLJSONObject oRoot = oResult.GetRoot();
auto osMsg = GetErrorMessage(oRoot, osErrorMessage);
CPLError(CE_Failure, CPLE_AppDefined, "%s", osMsg.c_str());
}
else
{
CPLError(CE_Failure, CPLE_AppDefined, "%s", osErrorMessage.c_str());
}
}

bool CheckSupportedType(bool bIsRaster, const std::string &osType)
{
//TODO: Add "raster_mosaic", "tileset", "wfsserver_service" and "wmsserver_service"
Expand Down Expand Up @@ -169,16 +182,6 @@ GetFeaturePageURL(const std::string &osUrl, const std::string &osResourceId,
}
}

if (bParamAdd)
{
osFeatureUrl += "&extensions=" + osExtensions;
}
else
{
osFeatureUrl += "?extensions=" + osExtensions;
bParamAdd = true;
}

if (IsGeometryIgnored)
{
if (bParamAdd)
Expand All @@ -188,9 +191,19 @@ GetFeaturePageURL(const std::string &osUrl, const std::string &osResourceId,
else
{
osFeatureUrl += "?geom=no";
bParamAdd = true;
}
}

if (bParamAdd)
{
osFeatureUrl += "&extensions=" + osExtensions;
}
else
{
osFeatureUrl += "?extensions=" + osExtensions;
}

return osFeatureUrl;
}

Expand Down Expand Up @@ -281,21 +294,6 @@ Uri ParseUri(const std::string &osUrl)
return stOut;
}

static void ReportError(const GByte *pabyData, int nDataLen,
const std::string &osErrorMessage)
{
CPLJSONDocument oResult;
if (oResult.LoadMemory(pabyData, nDataLen))
{
CPLJSONObject oRoot = oResult.GetRoot();
CheckRequestResult(false, oRoot, osErrorMessage);
}
else
{
CPLError(CE_Failure, CPLE_AppDefined, "%s", osErrorMessage.c_str());
}
}

std::string CreateResource(const std::string &osUrl,
const std::string &osPayload,
const CPLStringList &aosHTTPOptions)
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/ngw/ogrngwlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ std::string OGRNGWLayer::CreateNGWResourceJson()
{
OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn(iField);
CPLJSONObject oField;
auto sComment = poFieldDefn->GetComment();
auto const &sComment = poFieldDefn->GetComment();
if (!sComment.empty())
{
CPLJSONDocument oComment;
Expand Down

0 comments on commit 6c419b1

Please sign in to comment.