Skip to content

Commit

Permalink
Merge pull request OSGeo#9076 from rouault/coverity
Browse files Browse the repository at this point in the history
Coverity related fixes
  • Loading branch information
rouault authored Jan 15, 2024
2 parents b6ab258 + db6225e commit c1783d9
Show file tree
Hide file tree
Showing 120 changed files with 422 additions and 424 deletions.
4 changes: 2 additions & 2 deletions apps/gdalmdiminfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ static void DumpArray(const std::shared_ptr<GDALGroup> &rootGroup,
}

serializer.AddObjKey("datatype");
const auto dt(array->GetDataType());
const auto &dt(array->GetDataType());
DumpDataType(dt, serializer);

auto dims = array->GetDimensions();
Expand Down Expand Up @@ -1128,7 +1128,7 @@ char *GDALMultiDimInfo(GDALDatasetH hDataset,
"Cannot find group %s", aosTokens[i]);
return nullptr;
}
curGroup = curGroupNew;
curGroup = std::move(curGroupNew);
}
const char *pszArrayName = aosTokens[aosTokens.size() - 1];
auto array(curGroup->OpenMDArray(pszArrayName));
Expand Down
18 changes: 11 additions & 7 deletions apps/gdalmdimtranslate_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,9 @@ GetDimensionDesc(DimensionRemapper &oDimRemapper,

const bool bIsNumeric =
var->GetDataType().GetClass() == GEDTC_NUMERIC;
const auto dt(bIsNumeric ? GDALExtendedDataType::Create(GDT_Float64)
: GDALExtendedDataType::CreateString());
const GDALExtendedDataType dt(
bIsNumeric ? GDALExtendedDataType::Create(GDT_Float64)
: GDALExtendedDataType::CreateString());

double dfMin = 0;
double dfMax = 0;
Expand Down Expand Up @@ -1158,7 +1159,7 @@ static bool TranslateArray(
dt.FreeDynamicMemory(&abyTmp[0]);
}

const auto unit(srcIndexVar->GetUnit());
const auto &unit(srcIndexVar->GetUnit());
if (!unit.empty())
{
auto dstAttr = dstArray->CreateAttribute(
Expand Down Expand Up @@ -1197,9 +1198,11 @@ static bool TranslateArray(
band < 0 ? srcArray->GetFullName() : std::string(),
band >= 1 ? CPLSPrintf("%d", band) : std::string(),
std::move(anTransposedAxis),
bResampled ? (viewExpr.empty() ? std::string("resample=true")
: "resample=true," + viewExpr)
: viewExpr,
bResampled
? (viewExpr.empty() ? std::string("resample=true")
: std::string("resample=true,")
.append(std::move(viewExpr)))
: std::move(viewExpr),
std::move(anSrcOffset), std::move(anCount), std::move(anStep),
std::move(anDstOffset)));
dstArrayVRT->AddSource(std::move(poSource));
Expand Down Expand Up @@ -1316,7 +1319,8 @@ static bool CopyGroup(
{
CPLErrorHandlerPusher oHandlerPusher(CPLQuietErrorHandler);
CPLErrorStateBackuper oErrorStateBackuper;
oCorrespondingDimIter->second->SetIndexingVariable(dstArray);
oCorrespondingDimIter->second->SetIndexingVariable(
std::move(dstArray));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions apps/ogr2ogr_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3910,8 +3910,8 @@ bool SetupTargetLayer::CanUseWriteArrowBatch(
const auto poSrcFieldDefn =
poSrcFDefn->GetFieldDefn(iSrcField);
// Create field domain in output dataset if not already existing.
const auto osDomainName =
poSrcFieldDefn->GetDomainName();
const std::string osDomainName(
poSrcFieldDefn->GetDomainName());
if (!osDomainName.empty())
{
if (m_poDstDS->TestCapability(
Expand Down Expand Up @@ -4926,7 +4926,7 @@ SetupTargetLayer::Setup(OGRLayer *poSrcLayer, const char *pszNewLayerName,
}

// Create field domain in output dataset if not already existing.
const auto osDomainName = oFieldDefn.GetDomainName();
const std::string osDomainName(oFieldDefn.GetDomainName());
if (!osDomainName.empty())
{
if (m_poDstDS->TestCapability(ODsCAddFieldDomain) &&
Expand Down
1 change: 1 addition & 0 deletions autotest/cpp/test_cpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ TEST_F(test_cpl, CPLStringList_NameValue)
{
CPLStringList oTemp;
oTemp.AddString("test");
// coverity[copy_assignment_call]
oCopy = oTemp;
}
EXPECT_STREQ(oCopy[0], "test");
Expand Down
2 changes: 2 additions & 0 deletions autotest/cpp/test_ogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ TEST_F(test_ogr, DatasetFeature_and_LayerFeature_iterators)
{
GDALDataset::Layers::Iterator srcIter(poDS->GetLayers().begin());
++srcIter;
// coverity[copy_constructor_call]
GDALDataset::Layers::Iterator newIter(srcIter);
ASSERT_EQ(*newIter, layers[1]);
}
Expand All @@ -1451,6 +1452,7 @@ TEST_F(test_ogr, DatasetFeature_and_LayerFeature_iterators)
GDALDataset::Layers::Iterator srcIter(poDS->GetLayers().begin());
++srcIter;
GDALDataset::Layers::Iterator newIter;
// coverity[copy_assignent_call]
newIter = srcIter;
ASSERT_EQ(*newIter, layers[1]);
}
Expand Down
22 changes: 11 additions & 11 deletions autotest/cpp/test_ogr_organize_polygons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ TEST_P(OrganizePolygonsTest, EmptyInputVector)
{
std::vector<OGRGeometry *> polygons;

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -87,7 +87,7 @@ TEST_P(OrganizePolygonsTest, SinglePolygonInput)

std::unique_ptr<OGRGeometry> expected(polygons.front()->clone());

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -102,7 +102,7 @@ TEST_P(OrganizePolygonsTest, SingleCurvePolygonInput)

std::unique_ptr<OGRGeometry> expected(polygons.front()->clone());

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -115,7 +115,7 @@ TEST_P(OrganizePolygonsTest, SinglePointInput)
std::vector<OGRGeometry *> polygons;
polygons.push_back(readWKT("POINT (0 0)"));

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -130,7 +130,7 @@ TEST_P(OrganizePolygonsTest, MixedPolygonCurvePolygonInput)
readWKT("POLYGON ((10 10, 20 10, 20 20, 20 10, 10 10))"));
polygons.push_back(readWKT("CURVEPOLYGON ((0 0, 1 0, 1 1, 0 0))"));

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -152,7 +152,7 @@ TEST_P(OrganizePolygonsTest, MixedPolygonPointInput)

std::unique_ptr<OGRGeometry> expected(polygons[0]->clone());

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -165,7 +165,7 @@ TEST_P(OrganizePolygonsTest, CWPolygonCCWHole)
polygons.push_back(readWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"));
polygons.push_back(readWKT("POLYGON ((1 1, 2 1, 2 2, 1 2, 1 1))"));

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand Down Expand Up @@ -195,7 +195,7 @@ TEST_P(OrganizePolygonsTest, CWPolygonCCWLakeCWIslandInLake)
polygons.push_back(
readWKT("POLYGON ((15 15, 15 16, 16 16, 16 15, 15 15))")); // CW

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -217,7 +217,7 @@ TEST_P(OrganizePolygonsTest, AdjacentCCWPolygons)
polygons.push_back(readWKT("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))")); // CCW
polygons.push_back(readWKT("POLYGON ((1 0, 2 0, 2 1, 1 1, 1 0))")); // CCW

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -236,7 +236,7 @@ TEST_P(OrganizePolygonsTest, HoleAlongEdge)
readWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))")); // CW
polygons.push_back(readWKT("POLYGON ((0 2, 1 2, 1 3, 0 3, 0 2))")); // CCW

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand All @@ -257,7 +257,7 @@ TEST_P(OrganizePolygonsTest, CrossingCCWPolygons)
polygons.push_back(readWKT("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"));
polygons.push_back(readWKT("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"));

auto method = GetParam();
const auto &method = GetParam();
auto result = organizePolygons(polygons, method);

ASSERT_NE(result, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion frmts/adrg/adrgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ GDALDataset *ADRGDataset::Create(const char *pszFilename, int nXSize,
poDS->fdIMG = fdIMG;
poDS->fdTHF = fdTHF;

poDS->osBaseFileName = osBaseFileName;
poDS->osBaseFileName = std::move(osBaseFileName);
poDS->bCreation = TRUE;
poDS->nNextAvailableBlock = 1;
poDS->NFC = (nXSize + 127) / 128;
Expand Down
2 changes: 1 addition & 1 deletion frmts/adrg/srpdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ GDALDataset *SRPDataset::Open(GDALOpenInfo *poOpenInfo)
return nullptr;
}

osGENFileName = osFileName;
osGENFileName = std::move(osFileName);
}
}

Expand Down
17 changes: 9 additions & 8 deletions frmts/aigrid/aigdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,19 +689,20 @@ GDALDataset *AIGDataset::Open(GDALOpenInfo *poOpenInfo)
// Look in parent if we don't find a .clr in the coverage dir.
if (osClrFilename.empty())
{
osTestName.Printf("%s/../%s.clr", psInfo->pszCoverName,
CPLGetFilename(osCleanPath));
CPLString osTestClrFilename;
osTestClrFilename.Printf("%s/../%s.clr", psInfo->pszCoverName,
CPLGetFilename(osCleanPath));

if (VSIStatL(osTestName, &sStatBuf) != 0)
if (VSIStatL(osTestClrFilename, &sStatBuf) != 0)
{
osTestName.Printf("%s/../%s.CLR", psInfo->pszCoverName,
CPLGetFilename(osCleanPath));
osTestClrFilename.Printf("%s/../%s.CLR", psInfo->pszCoverName,
CPLGetFilename(osCleanPath));

if (!VSIStatL(osTestName, &sStatBuf))
osClrFilename = osTestName;
if (!VSIStatL(osTestClrFilename, &sStatBuf))
osClrFilename = std::move(osTestClrFilename);
}
else
osClrFilename = osTestName;
osClrFilename = std::move(osTestClrFilename);
}

if (!osClrFilename.empty())
Expand Down
32 changes: 16 additions & 16 deletions frmts/dimap/dimapdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,17 +554,17 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)
}

VSIStatBufL sStat;
CPLString osMDFilename(osFilename);
std::string osMDFilename(osFilename);
if (VSIStatL(osFilename.c_str(), &sStat) == 0 && VSI_ISDIR(sStat.st_mode))
{
osMDFilename = CPLFormCIFilename(osFilename, "METADATA.DIM", nullptr);

/* DIMAP2 */
if (VSIStatL(osMDFilename, &sStat) != 0)
if (VSIStatL(osMDFilename.c_str(), &sStat) != 0)
{
osMDFilename =
CPLFormCIFilename(osFilename, "VOL_PHR.XML", nullptr);
if (VSIStatL(osMDFilename, &sStat) != 0)
if (VSIStatL(osMDFilename.c_str(), &sStat) != 0)
{
// DIMAP VHR2020 file.
osMDFilename =
Expand All @@ -576,7 +576,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)
/* -------------------------------------------------------------------- */
/* Ingest the xml file. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psProduct = CPLParseXMLFile(osMDFilename);
CPLXMLNode *psProduct = CPLParseXMLFile(osMDFilename.c_str());
if (psProduct == nullptr)
return nullptr;

Expand All @@ -592,9 +592,9 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)

const int nProductVersion = dfMetadataFormatVersion >= 2.0 ? 2 : 1;

CPLString osImageDSFilename;
CPLString osDIMAPFilename;
CPLString osRPCFilename;
std::string osImageDSFilename;
std::string osDIMAPFilename;
std::string osRPCFilename;
CPLXMLNode *psProductDim = nullptr;
CPLXMLNode *psProductStrip = nullptr;

Expand Down Expand Up @@ -662,7 +662,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)
}
else
{
CPLString osPath = CPLGetPath(osMDFilename);
CPLString osPath = CPLGetPath(osMDFilename.c_str());
osDIMAPFilename =
CPLFormFilename(osPath, pszHref, nullptr);
}
Expand All @@ -674,7 +674,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)

if (strlen(pszDataFileHref) > 0)
{
CPLString osPath = CPLGetPath(osMDFilename);
CPLString osPath = CPLGetPath(osMDFilename.c_str());
osImageDSFilename = CPLFormFilename(
osPath, pszDataFileHref, nullptr);
}
Expand All @@ -692,7 +692,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)
}
}

psProductDim = CPLParseXMLFile(osDIMAPFilename);
psProductDim = CPLParseXMLFile(osDIMAPFilename.c_str());
if (psProductDim == nullptr)
{
CPLDestroyXMLNode(psProduct);
Expand Down Expand Up @@ -724,7 +724,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)

if (strlen(pszHref) > 0) // STRIP product found.
{
CPLString osPath = CPLGetPath(osDIMAPFilename);
CPLString osPath = CPLGetPath(osDIMAPFilename.c_str());
osSTRIPFilename =
CPLFormCIFilename(osPath, pszHref, nullptr);
if (VSIStatL(osSTRIPFilename, &sStat) == 0)
Expand Down Expand Up @@ -755,7 +755,7 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)

if (strlen(pszHref) > 0) // RPC product found.
{
CPLString osPath = CPLGetPath(osDIMAPFilename);
CPLString osPath = CPLGetPath(osDIMAPFilename.c_str());
osRPCFilename =
CPLFormCIFilename(osPath, pszHref, nullptr);

Expand All @@ -778,11 +778,11 @@ GDALDataset *DIMAPDataset::Open(GDALOpenInfo *poOpenInfo)
poDS->psProduct = psProduct;
poDS->psProductDim = psProductDim;
poDS->psProductStrip = psProductStrip;
poDS->osRPCFilename = osRPCFilename;
poDS->osRPCFilename = std::move(osRPCFilename);
poDS->nProductVersion = nProductVersion;
poDS->osMDFilename = osMDFilename;
poDS->osImageDSFilename = osImageDSFilename;
poDS->osDIMAPFilename = osDIMAPFilename;
poDS->osMDFilename = std::move(osMDFilename);
poDS->osImageDSFilename = std::move(osImageDSFilename);
poDS->osDIMAPFilename = std::move(osDIMAPFilename);

const int res = (nProductVersion == 2) ? poDS->ReadImageInformation2()
: poDS->ReadImageInformation();
Expand Down
4 changes: 2 additions & 2 deletions frmts/eeda/eedacommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ BuildBandDescArray(json_object *poBands,

EEDAIBandDesc oDesc;
oDesc.osName = pszBandId;
oDesc.osWKT = osWKT;
oDesc.osWKT = std::move(osWKT);
oDesc.eDT = eDT;
oDesc.adfGeoTransform = std::move(adfGeoTransform);
oDesc.nWidth = nWidth;
oDesc.nHeight = nHeight;
aoBandDesc.push_back(oDesc);
aoBandDesc.emplace_back(std::move(oDesc));
}
return aoBandDesc;
}
Expand Down
2 changes: 1 addition & 1 deletion frmts/ers/ersdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ GDALDataset *ERSDataset::Open(GDALOpenInfo *poOpenInfo)
else
poDS->fpImage = VSIFOpenL(osDataFilePath, "r");

poDS->osRawFilename = osDataFilePath;
poDS->osRawFilename = std::move(osDataFilePath);

if (poDS->fpImage != nullptr && nBands > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions frmts/fits/fitsdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ void FITSLayer::RunDeferredFieldCreation(const OGRFeature *poFeature)
(iBit = strtol(pszBit + strlen("_bit"), &pszEndPtr, 10)) > 0 &&
pszEndPtr && *pszEndPtr == '\0')
{
CPLString osName;
std::string osName;
osName.assign(pszFieldName, pszBit - pszFieldName);
if (oSetBitFieldNames.find(osName) == oSetBitFieldNames.end())
{
Expand All @@ -1060,7 +1060,7 @@ void FITSLayer::RunDeferredFieldCreation(const OGRFeature *poFeature)

if (osPendingBitFieldName.empty())
{
osPendingBitFieldName = osName;
osPendingBitFieldName = std::move(osName);
nPendingBitFieldSize = 1;
continue;
}
Expand Down
Loading

0 comments on commit c1783d9

Please sign in to comment.