Skip to content

Commit

Permalink
cppcheck fixes with latest cppcheck master
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 12, 2024
1 parent 8a65aaf commit 0b98a86
Show file tree
Hide file tree
Showing 29 changed files with 105 additions and 114 deletions.
3 changes: 2 additions & 1 deletion frmts/gif/gifabstractdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,14 @@ void GIFAbstractDataset::CollectXMPMetadata()
if (!osXMP.empty())
{
/* Avoid setting the PAM dirty bit just for that */
int nOldPamFlags = nPamFlags;
const int nOldPamFlags = nPamFlags;

char *apszMDList[2];
apszMDList[0] = (char *)osXMP.c_str();
apszMDList[1] = nullptr;
SetMetadata(apszMDList, "xml:XMP");

// cppcheck-suppress redundantAssignment
nPamFlags = nOldPamFlags;
}

Expand Down
1 change: 1 addition & 0 deletions frmts/gsg/gsagdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ CPLErr GSAGRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage)
}
else if (*szStart != '\0')
{
// cppcheck-suppress redundantAssignment
szEnd = szStart;
while (!isspace((unsigned char)*szEnd) && *szEnd != '\0')
szEnd++;
Expand Down
12 changes: 5 additions & 7 deletions frmts/gtiff/gt_citation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,7 @@ OGRBoolean CheckCitationKeyForStatePlaneUTM(GTIF *hGTIF, GTIFDefn *psDefn,
if (GDALGTIFKeyGetASCII(hGTIF, GTCitationGeoKey, szCTString,
sizeof(szCTString)))
{
CPLString osLCCT = szCTString;

osLCCT.tolower();
const CPLString osLCCT = CPLString(szCTString).tolower();

if (strstr(osLCCT, "us") && strstr(osLCCT, "survey") &&
(strstr(osLCCT, "feet") || strstr(osLCCT, "foot")))
Expand Down Expand Up @@ -659,8 +657,9 @@ OGRBoolean CheckCitationKeyForStatePlaneUTM(GTIF *hGTIF, GTIFDefn *psDefn,

if (poUnit != nullptr && poUnit->GetChildCount() >= 2)
{
CPLString unitName = poUnit->GetChild(0)->GetValue();
unitName.tolower();
const CPLString unitName =
CPLString(poUnit->GetChild(0)->GetValue())
.tolower();

if (strstr(units, "us_survey_feet"))
{
Expand Down Expand Up @@ -692,9 +691,8 @@ OGRBoolean CheckCitationKeyForStatePlaneUTM(GTIF *hGTIF, GTIFDefn *psDefn,
GTIFGetUOMLengthInfo(psDefn->UOMLength, &pszUnitsName, nullptr);
if (pszUnitsName)
{
CPLString osLCCT = pszUnitsName;
const CPLString osLCCT = CPLString(pszUnitsName).tolower();
GTIFFreeMemory(pszUnitsName);
osLCCT.tolower();

if (strstr(osLCCT, "us") && strstr(osLCCT, "survey") &&
(strstr(osLCCT, "feet") || strstr(osLCCT, "foot")))
Expand Down
8 changes: 0 additions & 8 deletions frmts/jp2lura/jp2lurarasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,11 @@ JP2LuraRasterBand::JP2LuraRasterBand(JP2LuraDataset *poDSIn, int nBandIn,
{
nBlockXSize = 2048;
}
else
{
nBlockXSize = nRasterXSize;
}

if (nRasterYSize >= 128)
{
nBlockYSize = 128;
}
else
{
nBlockYSize = nRasterYSize;
}
}

if ((nBits % 8) != 0)
Expand Down
7 changes: 2 additions & 5 deletions frmts/jpeg/jpgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ void JPGDatasetCommon::ReadXMPMetadata()
char *apszMDList[2] = {pszXMP, nullptr};
SetMetadata(apszMDList, "xml:XMP");

// cppcheck-suppress redundantAssignment
nPamFlags = nOldPamFlags;
}
VSIFree(pszXMP);
Expand Down Expand Up @@ -3036,7 +3037,7 @@ JPGDatasetCommon *JPGDataset::OpenStage2(JPGDatasetOpenArgs *psArgs,
// Open the file using the large file api if necessary.
VSILFILE *fpImage = fpLin;

if (fpImage == nullptr)
if (!fpImage)
{
fpImage = VSIFOpenL(real_filename, "rb");

Expand All @@ -3049,10 +3050,6 @@ JPGDatasetCommon *JPGDataset::OpenStage2(JPGDatasetOpenArgs *psArgs,
return nullptr;
}
}
else
{
fpImage = fpLin;
}

// Create a corresponding GDALDataset.
poDS->nQLevel = nQLevel;
Expand Down
4 changes: 2 additions & 2 deletions frmts/ngsgeoid/ngsgeoiddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ const OGRSpatialReference *NGSGEOIDDataset::GetSpatialRef() const
return &m_oSRS;
}

CPLString osFilename(CPLGetBasename(GetDescription()));
osFilename.tolower();
const CPLString osFilename =
CPLString(CPLGetBasename(GetDescription())).tolower();

// See https://www.ngs.noaa.gov/GEOID/GEOID12B/faq_2012B.shtml

Expand Down
3 changes: 2 additions & 1 deletion frmts/png/pngdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,11 +1588,12 @@ void PNGDataset::CollectXMPMetadata()
if (memcmp(pszContent, "XML:com.adobe.xmp\0\0\0\0\0", 22) == 0)
{
// Avoid setting the PAM dirty bit just for that.
int nOldPamFlags = nPamFlags;
const int nOldPamFlags = nPamFlags;

char *apszMDList[2] = {pszContent + 22, nullptr};
SetMetadata(apszMDList, "xml:XMP");

// cppcheck-suppress redundantAssignment
nPamFlags = nOldPamFlags;

VSIFree(pszContent);
Expand Down
1 change: 1 addition & 0 deletions frmts/webp/webpdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ char **WEBPDataset::GetMetadata(const char *pszDomain)
char *apszMDList[2] = {pszXMP, nullptr};
SetMetadata(apszMDList, "xml:XMP");

// cppcheck-suppress redundantAssignment
nPamFlags = nOldPamFlags;

VSIFree(pszXMP);
Expand Down
4 changes: 2 additions & 2 deletions frmts/wms/minidriver_arcgis_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ CPLErr WMSMiniDriver_AGS::Initialize(CPLXMLNode *config,

m_image_format = CPLGetXMLValue(config, "ImageFormat", "png");
m_time_range = CPLGetXMLValue(config, "TimeRange", "");
m_transparent = CPLGetXMLValue(config, "Transparent", "");
m_transparent.tolower();
m_transparent =
CPLString(CPLGetXMLValue(config, "Transparent", "")).tolower();
m_layers = CPLGetXMLValue(config, "Layers", "");

const char *irs = CPLGetXMLValue(config, "SRS", "102100");
Expand Down
4 changes: 2 additions & 2 deletions gcore/gdal_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,9 +1869,9 @@ CPLString GDALFindAssociatedFile(const char *pszBaseFilename,
CPLString osAltExt = pszExt;

if (islower(static_cast<unsigned char>(pszExt[0])))
osAltExt.toupper();
osAltExt = osAltExt.toupper();
else
osAltExt.tolower();
osAltExt = osAltExt.tolower();

osTarget = CPLResetExtension(pszBaseFilename, osAltExt);

Expand Down
5 changes: 3 additions & 2 deletions gcore/gdal_pam.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class GDALPamRasterBand;
#define GCIF_SCALEOFFSET 0x008000
#define GCIF_UNITTYPE 0x010000
#define GCIF_COLORTABLE 0x020000
/* Same value as GCIF_COLORTABLE */
#define GCIF_COLORINTERP 0x020000
#define GCIF_BAND_METADATA 0x040000
#define GCIF_RAT 0x080000
Expand All @@ -50,8 +51,8 @@ class GDALPamRasterBand;
#define GCIF_PAM_DEFAULT \
(GCIF_GEOTRANSFORM | GCIF_PROJECTION | GCIF_METADATA | GCIF_GCPS | \
GCIF_NODATA | GCIF_CATEGORYNAMES | GCIF_MINMAX | GCIF_SCALEOFFSET | \
GCIF_UNITTYPE | GCIF_COLORTABLE | GCIF_COLORINTERP | GCIF_BAND_METADATA | \
GCIF_RAT | GCIF_MASK | GCIF_ONLY_IF_MISSING | GCIF_PROCESS_BANDS | \
GCIF_UNITTYPE | GCIF_COLORTABLE | GCIF_BAND_METADATA | GCIF_RAT | \
GCIF_MASK | GCIF_ONLY_IF_MISSING | GCIF_PROCESS_BANDS | \
GCIF_BAND_DESCRIPTION)

/* GDAL PAM Flags */
Expand Down
2 changes: 1 addition & 1 deletion gcore/gdaldriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ bool GDALDriver::CanVectorTranslateFrom(
if (!ppapszFailureReasons)
{
for (const char *pszReason :
cpl::Iterate(CSLConstList(papszFailureReasons)))
cpl::Iterate(static_cast<CSLConstList>(papszFailureReasons)))
{
CPLDebug("GDAL", "%s", pszReason);
}
Expand Down
4 changes: 2 additions & 2 deletions gcore/gdaljp2abstractdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ void GDALJP2AbstractDataset::LoadJP2Metadata(GDALOpenInfo *poOpenInfo,
GDALMultiDomainMetadata oLocalMDMD;
oLocalMDMD.XMLInit(psXMLNode, FALSE);
GDALDataset::SetMetadata(oLocalMDMD.GetMetadata());
for (const char *pszDomain :
cpl::Iterate(CSLConstList(oLocalMDMD.GetDomainList())))
for (const char *pszDomain : cpl::Iterate(
static_cast<CSLConstList>(oLocalMDMD.GetDomainList())))
{
if (!EQUAL(pszDomain, "") &&
!EQUAL(pszDomain, "IMAGE_STRUCTURE"))
Expand Down
10 changes: 6 additions & 4 deletions gcore/gdalmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6962,7 +6962,8 @@ bool GDALMDArrayMask::IRead(const GUInt64 *arrayStartIdx, const size_t *count,
m_poParent->GetRawNoDataValue() == nullptr &&
GDALDataTypeIsInteger(m_poParent->GetDataType().GetNumericDataType()))
{
if (bufferDataType == m_dt) // Byte case
const bool bBufferDataTypeIsByte = bufferDataType == m_dt;
if (bBufferDataTypeIsByte) // Byte case
{
bool bContiguous = true;
for (size_t i = 0; i < nDims; i++)
Expand Down Expand Up @@ -6999,7 +7000,6 @@ bool GDALMDArrayMask::IRead(const GUInt64 *arrayStartIdx, const size_t *count,

size_t dimIdx = 0;
const size_t nDimsMinus1 = nDims > 0 ? nDims - 1 : 0;
const bool bBufferDataTypeIsByte = bufferDataType == m_dt;
GByte abyOne[16]; // 16 is sizeof GDT_CFloat64
CPLAssert(nBufferDTSize <= 16);
const GByte flag = 1;
Expand All @@ -7015,6 +7015,7 @@ bool GDALMDArrayMask::IRead(const GUInt64 *arrayStartIdx, const size_t *count,

while (true)
{
// cppcheck-suppress knownConditionTrueFalse
if (bBufferDataTypeIsByte)
{
*dst_ptr = flag;
Expand Down Expand Up @@ -9485,8 +9486,9 @@ GDALDatasetFromArray *GDALDatasetFromArray::Create(
poDS->SetDerivedDatasetName(osDerivedDatasetName.c_str());
poDS->TryLoadXML();

for (const auto &[pszKey, pszValue] : cpl::IterateNameValue(
CSLConstList(poDS->GDALPamDataset::GetMetadata())))
for (const auto &[pszKey, pszValue] :
cpl::IterateNameValue(static_cast<CSLConstList>(
poDS->GDALPamDataset::GetMetadata())))
{
poDS->m_oMDD.SetMetadataItem(pszKey, pszValue);
}
Expand Down
2 changes: 1 addition & 1 deletion gcore/gdalpamdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ void GDALPamDataset::ClearStatistics()
GDALRasterBand *poBand = GetRasterBand(i);
CPLStringList aosNewMD;
for (const char *pszStr :
cpl::Iterate(CSLConstList(poBand->GetMetadata())))
cpl::Iterate(static_cast<CSLConstList>(poBand->GetMetadata())))
{
if (STARTS_WITH_CI(pszStr, "STATISTICS_"))
{
Expand Down
1 change: 1 addition & 0 deletions gcore/gdalpamproxydb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ static void InitProxyDB()
{
CPLMutexHolderD(&hProxyDBLock);
// cppcheck-suppress identicalInnerCondition
// cppcheck-suppress knownConditionTrueFalse
if (!bProxyDBInitialized)
{
const char *pszProxyDir =
Expand Down
6 changes: 1 addition & 5 deletions gnm/gnmgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ void GNMGraph::TraceTargets(std::queue<GNMGFID> &vertexQueue,
std::set<GNMGFID> &markedVertIds,
GNMPATH &connectedIds)
{
GNMCONSTVECTOR::const_iterator it;
std::queue<GNMGFID> neighbours_queue;

// See all given vertices except thouse that have been already seen.
Expand All @@ -591,11 +590,8 @@ void GNMGraph::TraceTargets(std::queue<GNMGFID> &vertexQueue,
LPGNMCONSTVECTOR panOutcomeEdgeIDs = GetOutEdges(nCurVertID);
if (nullptr != panOutcomeEdgeIDs)
{
for (it = panOutcomeEdgeIDs->begin();
it != panOutcomeEdgeIDs->end(); ++it)
for (const GNMGFID nCurEdgeID : *panOutcomeEdgeIDs)
{
GNMGFID nCurEdgeID = *it;

// ISSUE: think about to return a sequence of vertices and
// edges (which is more universal), as now we are going to
// return only sequence of edges.
Expand Down
1 change: 1 addition & 0 deletions ogr/ogrfielddefn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,7 @@ OGRCodedFieldDomain::~OGRCodedFieldDomain()
/* OGRRangeFieldDomain() */
/************************************************************************/

// cppcheck-suppress uninitMemberVar
OGRRangeFieldDomain::OGRRangeFieldDomain(
const std::string &osName, const std::string &osDescription,
OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
Expand Down
11 changes: 3 additions & 8 deletions ogr/ogrsf_frmts/generic/ogrunionlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,14 @@ OGRUnionLayerGeomFieldDefn::~OGRUnionLayerGeomFieldDefn()
/* OGRUnionLayer() */
/************************************************************************/

// cppcheck-suppress uninitMemberVar
OGRUnionLayer::OGRUnionLayer(const char *pszName, int nSrcLayersIn,
OGRLayer **papoSrcLayersIn,
int bTakeLayerOwnership)
: osName(pszName), nSrcLayers(nSrcLayersIn), papoSrcLayers(papoSrcLayersIn),
bHasLayerOwnership(bTakeLayerOwnership), poFeatureDefn(nullptr),
nFields(0), papoFields(nullptr), nGeomFields(0), papoGeomFields(nullptr),
eFieldStrategy(FIELD_UNION_ALL_LAYERS), bPreserveSrcFID(FALSE),
nFeatureCount(-1), iCurLayer(-1), pszAttributeFilter(nullptr),
nNextFID(0), panMap(nullptr), bAttrFilterPassThroughValue(-1),
bHasLayerOwnership(bTakeLayerOwnership),
pabModifiedLayers(static_cast<int *>(CPLCalloc(sizeof(int), nSrcLayers))),
pabCheckIfAutoWrap(
static_cast<int *>(CPLCalloc(sizeof(int), nSrcLayers))),
poGlobalSRS(nullptr)
pabCheckIfAutoWrap(static_cast<int *>(CPLCalloc(sizeof(int), nSrcLayers)))
{
CPLAssert(nSrcLayersIn > 0);

Expand Down
42 changes: 21 additions & 21 deletions ogr/ogrsf_frmts/generic/ogrunionlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,32 @@ class CPL_DLL OGRUnionLayer final : public OGRLayer
CPL_DISALLOW_COPY_ASSIGN(OGRUnionLayer)

protected:
CPLString osName;
int nSrcLayers;
OGRLayer **papoSrcLayers;
int bHasLayerOwnership;

OGRFeatureDefn *poFeatureDefn;
int nFields;
OGRFieldDefn **papoFields;
int nGeomFields;
OGRUnionLayerGeomFieldDefn **papoGeomFields;
FieldUnionStrategy eFieldStrategy;
CPLString osName{};
int nSrcLayers = 0;
OGRLayer **papoSrcLayers = nullptr;
int bHasLayerOwnership = false;

OGRFeatureDefn *poFeatureDefn = nullptr;
int nFields = 0;
OGRFieldDefn **papoFields = nullptr;
int nGeomFields = 0;
OGRUnionLayerGeomFieldDefn **papoGeomFields = nullptr;
FieldUnionStrategy eFieldStrategy = FIELD_UNION_ALL_LAYERS;
CPLString osSourceLayerFieldName{};

int bPreserveSrcFID;
int bPreserveSrcFID = false;

GIntBig nFeatureCount;
GIntBig nFeatureCount = -1;

int iCurLayer;
char *pszAttributeFilter;
int nNextFID;
int *panMap;
int iCurLayer = -1;
char *pszAttributeFilter = nullptr;
int nNextFID = 0;
int *panMap = nullptr;
CPLStringList m_aosIgnoredFields{};
int bAttrFilterPassThroughValue;
int *pabModifiedLayers;
int *pabCheckIfAutoWrap;
const OGRSpatialReference *poGlobalSRS;
int bAttrFilterPassThroughValue = -1;
int *pabModifiedLayers = nullptr;
int *pabCheckIfAutoWrap = nullptr;
const OGRSpatialReference *poGlobalSRS = nullptr;

void AutoWarpLayerIfNecessary(int iSubLayer);
OGRFeature *TranslateFromSrcLayer(OGRFeature *poSrcFeature);
Expand Down
Loading

0 comments on commit 0b98a86

Please sign in to comment.