Skip to content

Commit

Permalink
Address cppcheck warnings constVariableReference/constParameterReference
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 17, 2024
1 parent bf83dbe commit b4345da
Show file tree
Hide file tree
Showing 73 changed files with 194 additions and 155 deletions.
15 changes: 13 additions & 2 deletions alg/gdal_simplesurf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ double &GDALFeaturePoint::operator[](int nIndex)
return padfDescriptor[nIndex];
}

double GDALFeaturePoint::operator[](int nIndex) const
{
if (nIndex < 0 || nIndex >= DESC_SIZE)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Descriptor index is out of range");
}

return padfDescriptor[nIndex];
}

GDALFeaturePoint::~GDALFeaturePoint()
{
delete[] padfDescriptor;
Expand Down Expand Up @@ -273,8 +284,8 @@ GDALSimpleSURF::ExtractFeaturePoints(GDALIntegralImage *poImg,
return poCollection;
}

double GDALSimpleSURF::GetEuclideanDistance(GDALFeaturePoint &firstPoint,
GDALFeaturePoint &secondPoint)
double GDALSimpleSURF::GetEuclideanDistance(const GDALFeaturePoint &firstPoint,
const GDALFeaturePoint &secondPoint)
{
double sum = 0.0;

Expand Down
16 changes: 14 additions & 2 deletions alg/gdal_simplesurf.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ class GDALFeaturePoint
*/
double &operator[](int nIndex);

/**
* Provide access to point's descriptor.
*
* @param nIndex Position of descriptor's value.
* nIndex should be within range from 0 to DESC_SIZE (in current version -
* 64)
*
* @return Reference to value of descriptor in 'nIndex' position.
* If index is out of range then behavior is undefined.
*/
double operator[](int nIndex) const;

/** Descriptor length */
static const int DESC_SIZE = 64;

Expand Down Expand Up @@ -555,8 +567,8 @@ class GDALSimpleSURF
*
* @return Euclidean distance between descriptors.
*/
static double GetEuclideanDistance(GDALFeaturePoint &firstPoint,
GDALFeaturePoint &secondPoint);
static double GetEuclideanDistance(const GDALFeaturePoint &firstPoint,
const GDALFeaturePoint &secondPoint);

/**
* Set provided distance values to range from 0 to 1.
Expand Down
2 changes: 1 addition & 1 deletion alg/gdalsievefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static CPLErr GPMaskImageData(GDALRasterBandH hMaskBand, GByte *pabyMaskLine,
static inline void CompareNeighbour(int nPolyId1, int nPolyId2,
int *panPolyIdMap,
std::int64_t * /* panPolyValue */,
std::vector<int> &anPolySizes,
const std::vector<int> &anPolySizes,
std::vector<int> &anBigNeighbour)

{
Expand Down
8 changes: 4 additions & 4 deletions alg/gdaltransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4299,9 +4299,9 @@ int GDALTransformLonLatToDestApproxTransformer(void *hTransformArg,
* location is placed.
*/

void CPL_STDCALL GDALApplyGeoTransform(double *padfGeoTransform, double dfPixel,
double dfLine, double *pdfGeoX,
double *pdfGeoY)
void CPL_STDCALL GDALApplyGeoTransform(const double *padfGeoTransform,
double dfPixel, double dfLine,
double *pdfGeoX, double *pdfGeoY)
{
*pdfGeoX = padfGeoTransform[0] + dfPixel * padfGeoTransform[1] +
dfLine * padfGeoTransform[2];
Expand All @@ -4325,7 +4325,7 @@ void CPL_STDCALL GDALApplyGeoTransform(double *padfGeoTransform, double dfPixel,
* @return TRUE on success or FALSE if the equation is uninvertable.
*/

int CPL_STDCALL GDALInvGeoTransform(double *gt_in, double *gt_out)
int CPL_STDCALL GDALInvGeoTransform(const double *gt_in, double *gt_out)

{
// Special case - no rotation - to avoid computing determinate
Expand Down
14 changes: 7 additions & 7 deletions alg/gdalwarpkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ void GWKThreadsEnd(void *psThreadDataIn)
GWKThreadData *psThreadData = static_cast<GWKThreadData *>(psThreadDataIn);
if (psThreadData->poJobQueue)
{
// cppcheck-suppress constVariableReference
for (auto &pair : psThreadData->mapThreadToTransformerArg)
{
CPLAssert(pair.second != psThreadData->pTransformerArgInput);
Expand Down Expand Up @@ -533,15 +534,14 @@ static CPLErr GWKRun(GDALWarpKernel *poWK, const char *pszFuncName,
*/
if (poWK->pfnProgress != GDALDummyProgress)
{
int &counter = psThreadData->counter;
while (counter < nDstYSize)
while (psThreadData->counter < nDstYSize)
{
psThreadData->cv.wait(lock);
if (!poWK->pfnProgress(
poWK->dfProgressBase +
poWK->dfProgressScale *
(counter / static_cast<double>(nDstYSize)),
"", poWK->pProgress))
if (!poWK->pfnProgress(poWK->dfProgressBase +
poWK->dfProgressScale *
(psThreadData->counter /
static_cast<double>(nDstYSize)),
"", poWK->pProgress))
{
CPLError(CE_Failure, CPLE_UserInterrupt, "User terminated");
psThreadData->stopFlag = true;
Expand Down
7 changes: 5 additions & 2 deletions alg/polygonize_polygonizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ IndexedArc RPolygon::newArc(bool bFollowRighthand)
return IndexedArc{poArc, iArcIndex};
}

void RPolygon::setArcConnection(IndexedArc &oArc, IndexedArc &oNextArc)
void RPolygon::setArcConnection(const IndexedArc &oArc,
const IndexedArc &oNextArc)
{
oArcConnections[oArc.iIndex] = oNextArc.iIndex;
}
Expand Down Expand Up @@ -350,6 +351,7 @@ Polygonizer<PolyIdType, DataType>::Polygonizer(
template <typename PolyIdType, typename DataType>
Polygonizer<PolyIdType, DataType>::~Polygonizer()
{
// cppcheck-suppress constVariableReference
for (auto &pair : oPolygonMap_)
{
delete pair.second;
Expand Down Expand Up @@ -436,6 +438,7 @@ void Polygonizer<PolyIdType, DataType>::processLine(
oCompletedPolygons.push_back(entry);
}
}
// cppcheck-suppress constVariableReference
for (auto &entry : oCompletedPolygons)
{
PolyIdType nPolyId = entry.first;
Expand Down Expand Up @@ -483,7 +486,7 @@ void OGRPolygonWriter<DataType>::receive(RPolygon *poPolygon,
poPolygon->oArcRighthandFollow[iArcIndex];
for (std::size_t i = 0; i < oArc->size(); ++i)
{
Point &oPixel =
const Point &oPixel =
(*oArc)[bArcFollowRighthand ? i : (oArc->size() - i - 1)];

const double dfX = padfGeoTransform[0] +
Expand Down
2 changes: 1 addition & 1 deletion alg/polygonize_polygonizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct RPolygon
/**
* set the next arc index of the current arc
*/
void setArcConnection(IndexedArc &oArc, IndexedArc &oNextArc);
void setArcConnection(const IndexedArc &oArc, const IndexedArc &oNextArc);

/**
* update the bottom-right most cell index of the current polygon
Expand Down
13 changes: 7 additions & 6 deletions frmts/daas/daasdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ bool GDALDAASDataset::GetAuthorization()
/* GetObject() */
/************************************************************************/

static CPLJSONObject GetObject(CPLJSONObject &oContainer, const char *pszPath,
static CPLJSONObject GetObject(const CPLJSONObject &oContainer,
const char *pszPath,
CPLJSONObject::Type eExpectedType,
const char *pszExpectedType, bool bVerboseError,
bool &bError)
Expand Down Expand Up @@ -632,7 +633,7 @@ static CPLJSONObject GetObject(CPLJSONObject &oContainer, const char *pszPath,
/* GetInteger() */
/************************************************************************/

static int GetInteger(CPLJSONObject &oContainer, const char *pszPath,
static int GetInteger(const CPLJSONObject &oContainer, const char *pszPath,
bool bVerboseError, bool &bError)
{
CPLJSONObject oObj =
Expand All @@ -649,7 +650,7 @@ static int GetInteger(CPLJSONObject &oContainer, const char *pszPath,
/* GetDouble() */
/************************************************************************/

static double GetDouble(CPLJSONObject &oContainer, const char *pszPath,
static double GetDouble(const CPLJSONObject &oContainer, const char *pszPath,
bool bVerboseError, bool &bError)
{
CPLJSONObject oObj = oContainer.GetObj(pszPath);
Expand All @@ -676,7 +677,7 @@ static double GetDouble(CPLJSONObject &oContainer, const char *pszPath,
/* GetString() */
/************************************************************************/

static CPLString GetString(CPLJSONObject &oContainer, const char *pszPath,
static CPLString GetString(const CPLJSONObject &oContainer, const char *pszPath,
bool bVerboseError, bool &bError)
{
CPLJSONObject oObj =
Expand Down Expand Up @@ -2165,7 +2166,7 @@ CPLErr GDALDAASRasterBand::GetBlocks(int nBlockXOff, int nBlockYOff,

CPLJSONArray oBands;
bool bOK = true;
for (auto &iBand : anRequestedBands)
for (const int iBand : anRequestedBands)
{
auto desc = (iBand == MAIN_MASK_BAND_NUMBER)
? poGDS->m_poMaskBand->GetDescription()
Expand Down Expand Up @@ -2212,7 +2213,7 @@ CPLErr GDALDAASRasterBand::GetBlocks(int nBlockXOff, int nBlockYOff,
{
for (int iXBlock = 0; iXBlock < nXBlocks; iXBlock++)
{
for (auto &iBand : anRequestedBands)
for (const int iBand : anRequestedBands)
{
GByte *pabyDstBuffer = nullptr;
GDALDAASRasterBand *poIterBand;
Expand Down
1 change: 1 addition & 0 deletions frmts/gtiff/gtiffdataset_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ CPLErr GTiffDataset::MultiThreadedRead(int nXOff, int nYOff, int nXSize,

// Make sure that all blocks that we are going to read and that are
// being written by a worker thread are completed.
// cppcheck-suppress constVariableReference
auto &oQueue =
m_poBaseDS ? m_poBaseDS->m_asQueueJobIdx : m_asQueueJobIdx;
if (!oQueue.empty())
Expand Down
5 changes: 5 additions & 0 deletions frmts/gtiff/gtiffdataset_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,9 @@ void GTiffDataset::WaitCompletionForBlock(int nBlockId)
{
auto poQueue = m_poBaseDS ? m_poBaseDS->m_poCompressQueue.get()
: m_poCompressQueue.get();
// cppcheck-suppress constVariableReference
auto &oQueue = m_poBaseDS ? m_poBaseDS->m_asQueueJobIdx : m_asQueueJobIdx;
// cppcheck-suppress constVariableReference
auto &asJobs =
m_poBaseDS ? m_poBaseDS->m_asCompressionJobs : m_asCompressionJobs;

Expand Down Expand Up @@ -1227,6 +1229,7 @@ bool GTiffDataset::SubmitCompressionJob(int nStripOrTile, GByte *pabyData,
poQueue->WaitCompletion();

// Flush remaining data
// cppcheck-suppress constVariableReference
auto &oQueue =
m_poBaseDS ? m_poBaseDS->m_asQueueJobIdx : m_asQueueJobIdx;
while (!oQueue.empty())
Expand Down Expand Up @@ -2085,6 +2088,8 @@ CPLErr GTiffDataset::FlushCacheInternal(bool bAtClosing, bool bFlushDirectory)
poQueue->WaitCompletion();

// Flush remaining data
// cppcheck-suppress constVariableReference

auto &oQueue =
m_poBaseDS ? m_poBaseDS->m_asQueueJobIdx : m_asQueueJobIdx;
while (!oQueue.empty())
Expand Down
4 changes: 2 additions & 2 deletions frmts/hdf4/hdf4multidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,7 @@ HDF4SDSGroup::GetDimensions(CSLConstList) const
std::string osTransformationMatrix;
if (m_bIsGDALDataset)
{
for (auto &poAttr : m_oGlobalAttributes)
for (const auto &poAttr : m_oGlobalAttributes)
{
if (poAttr->GetName() == "Projection" &&
poAttr->GetDataType().GetClass() == GEDTC_STRING)
Expand Down Expand Up @@ -2812,7 +2812,7 @@ std::shared_ptr<OGRSpatialReference> HDF4SDSArray::GetSpatialRef() const
if (m_bIsGDALDataset)
{
std::string osProjection;
for (auto &poAttr : m_oGlobalAttributes)
for (const auto &poAttr : m_oGlobalAttributes)
{
if (poAttr->GetName() == "Projection" &&
poAttr->GetDataType().GetClass() == GEDTC_STRING)
Expand Down
2 changes: 1 addition & 1 deletion frmts/hdf5/hdf5dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ CPLErr HDF5Dataset::HDF5ListGroupObjects(HDF5GroupObjects *poRootGroup,
int nYDimSize = 0;
int nOtherDimSize = 0;
std::string osOtherDimName;
for (auto &oDim : oGridMetadata.aoDimensions)
for (const auto &oDim : oGridMetadata.aoDimensions)
{
if (oDim.osName == "XDim")
nXDimSize = oDim.nSize;
Expand Down
2 changes: 1 addition & 1 deletion frmts/hdf5/hdf5eosparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ bool HDF5EOSParser::GridMetadata::GetGeoTransform(
int nRasterXSize = 0;
int nRasterYSize = 0;

for (auto &oDim : aoDimensions)
for (const auto &oDim : aoDimensions)
{
if (oDim.osName == "XDim")
nRasterXSize = oDim.nSize;
Expand Down
2 changes: 1 addition & 1 deletion frmts/hdf5/hdf5imagedataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ GDALDataset *HDF5ImageDataset::Open(GDALOpenInfo *poOpenInfo)
poDS->ndims)
{
int iDim = 0;
for (auto &oDim : oGridDataFieldMetadata.aoDimensions)
for (const auto &oDim : oGridDataFieldMetadata.aoDimensions)
{
if (oDim.osName == "XDim")
poDS->m_nXIndex = iDim;
Expand Down
8 changes: 4 additions & 4 deletions frmts/hdf5/hdf5multidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ void HDF5Array::InstantiateDimensions(const std::string &osParentName,
std::map<std::string, std::shared_ptr<GDALDimension>> oMap;
const auto groupDims = m_poShared->GetEOSGridDimensions(
oGridDataFieldMetadata.poGridMetadata->osGridName);
for (auto &dim : groupDims)
for (const auto &dim : groupDims)
{
oMap[dim->GetName()] = dim;
}
Expand Down Expand Up @@ -1383,7 +1383,7 @@ void HDF5Array::InstantiateDimensions(const std::string &osParentName,
std::map<std::string, std::shared_ptr<GDALDimension>> oMap;
const auto groupDims = m_poShared->GetEOSSwathDimensions(
oSwathDataFieldMetadata.poSwathMetadata->osSwathName);
for (auto &dim : groupDims)
for (const auto &dim : groupDims)
{
oMap[dim->GetName()] = dim;
}
Expand All @@ -1408,7 +1408,7 @@ void HDF5Array::InstantiateDimensions(const std::string &osParentName,
std::map<std::string, std::shared_ptr<GDALDimension>> oMap;
const auto groupDims = m_poShared->GetEOSSwathDimensions(
oSwathGeolocationFieldMetadata.poSwathMetadata->osSwathName);
for (auto &dim : groupDims)
for (const auto &dim : groupDims)
{
oMap[dim->GetName()] = dim;
}
Expand Down Expand Up @@ -1508,7 +1508,7 @@ void HDF5Array::InstantiateDimensions(const std::string &osParentName,
if (poGroup && !mapDimIndexToDimFullName.empty())
{
auto groupDims = poGroup->GetDimensions();
for (auto &dim : groupDims)
for (const auto &dim : groupDims)
{
oMapFullNameToDim[dim->GetFullName()] = dim;
}
Expand Down
2 changes: 1 addition & 1 deletion frmts/hdf5/s102dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ GDALDataset *S102Dataset::Open(GDALOpenInfo *poOpenInfo)
if (!poDS->Init())
return nullptr;

auto &poRootGroup = poDS->m_poRootGroup;
const auto &poRootGroup = poDS->m_poRootGroup;
auto poBathymetryCoverage01 = poRootGroup->OpenGroupFromFullname(
"/BathymetryCoverage/BathymetryCoverage.01");
if (!poBathymetryCoverage01)
Expand Down
2 changes: 1 addition & 1 deletion frmts/hdf5/s104dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ GDALDataset *S104Dataset::Open(GDALOpenInfo *poOpenInfo)
if (!poDS->Init())
return nullptr;

auto &poRootGroup = poDS->m_poRootGroup;
const auto &poRootGroup = poDS->m_poRootGroup;

auto poWaterLevel = poRootGroup->OpenGroup("WaterLevel");
if (!poWaterLevel)
Expand Down
2 changes: 1 addition & 1 deletion frmts/hdf5/s111dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ GDALDataset *S111Dataset::Open(GDALOpenInfo *poOpenInfo)
if (!poDS->Init())
return nullptr;

auto &poRootGroup = poDS->m_poRootGroup;
const auto &poRootGroup = poDS->m_poRootGroup;

auto poSurfaceCurrent = poRootGroup->OpenGroup("SurfaceCurrent");
if (!poSurfaceCurrent)
Expand Down
4 changes: 2 additions & 2 deletions frmts/mrf/JPEG_band.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@ static boolean MaskProcessor(j_decompress_ptr pcinfo)
* @param sz if non-zero, test that uncompressed data fits in the buffer.
*/
#if defined(JPEG12_ON)
CPLErr JPEG_Codec::DecompressJPEG12(buf_mgr &dst, buf_mgr &isrc)
CPLErr JPEG_Codec::DecompressJPEG12(buf_mgr &dst, const buf_mgr &isrc)
#else
CPLErr JPEG_Codec::DecompressJPEG(buf_mgr &dst, buf_mgr &isrc)
CPLErr JPEG_Codec::DecompressJPEG(buf_mgr &dst, const buf_mgr &isrc)
#endif

{
Expand Down
3 changes: 2 additions & 1 deletion frmts/mrf/LERC_band.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ static CPLErr CompressLERC1(buf_mgr &dst, buf_mgr &src, const ILImage &img,
}

// LERC 1 Decompression
static CPLErr DecompressLERC1(buf_mgr &dst, buf_mgr &src, const ILImage &img)
static CPLErr DecompressLERC1(buf_mgr &dst, const buf_mgr &src,
const ILImage &img)
{
Lerc1Image zImg;

Expand Down
2 changes: 1 addition & 1 deletion frmts/mrf/PNG_band.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ CPLErr PNG_Codec::DecompressPNG(buf_mgr &dst, buf_mgr &src)
*
*/

CPLErr PNG_Codec::CompressPNG(buf_mgr &dst, buf_mgr &src)
CPLErr PNG_Codec::CompressPNG(buf_mgr &dst, const buf_mgr &src)

{
png_structp pngp;
Expand Down
Loading

0 comments on commit b4345da

Please sign in to comment.