From 916bda07b0de90b43272be5e4772cda8d0842938 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 15 Nov 2023 01:31:55 +0100 Subject: [PATCH] Fix a few cppcheck warnings --- apps/gdalbuildvrt_lib.cpp | 2 +- frmts/gtiff/gtiffdataset_read.cpp | 2 ++ frmts/raw/loslasdataset.cpp | 2 +- ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp | 1 + ogr/ogrsf_frmts/s57/s57reader.cpp | 4 ++-- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/gdalbuildvrt_lib.cpp b/apps/gdalbuildvrt_lib.cpp index 60c96513542c..86a16a37f640 100644 --- a/apps/gdalbuildvrt_lib.cpp +++ b/apps/gdalbuildvrt_lib.cpp @@ -1055,7 +1055,7 @@ void VRTBuilder::CreateVRTSeparate(VRTDatasetH hVRTDS) const int nSrcBandIdx = nSelectedBands > 0 ? panSelectedBandList[iBandToIter] - 1 : iBandToIter; - + assert(nSrcBandIdx >= 0); GDALAddBand(hVRTDS, psDatasetProperties->aeBandType[nSrcBandIdx], nullptr); diff --git a/frmts/gtiff/gtiffdataset_read.cpp b/frmts/gtiff/gtiffdataset_read.cpp index 2b6fa39bf989..68532efaf78b 100644 --- a/frmts/gtiff/gtiffdataset_read.cpp +++ b/frmts/gtiff/gtiffdataset_read.cpp @@ -36,6 +36,7 @@ #include "gtiffsplitbitmapband.h" #include +#include #include #include #include @@ -937,6 +938,7 @@ static void CPL_STDCALL ThreadDecompressionFuncErrorHandler( psContext->bCacheAllBands ? psContext->panBandMap[i] - 1 : poDS->m_nPlanarConfig == PLANARCONFIG_CONTIG ? i : 0; + assert(iSrcBandIdx >= 0); const int iDstBandIdx = poDS->m_nPlanarConfig == PLANARCONFIG_CONTIG ? i : psJob->iDstBandIdxSeparate; diff --git a/frmts/raw/loslasdataset.cpp b/frmts/raw/loslasdataset.cpp index 63c7d782801a..970d89832165 100644 --- a/frmts/raw/loslasdataset.cpp +++ b/frmts/raw/loslasdataset.cpp @@ -280,7 +280,7 @@ GDALDataset *LOSLASDataset::Open(GDALOpenInfo *poOpenInfo) poDS->adfGeoTransform[2] = 0.0; poDS->adfGeoTransform[3] = min_lat + (poDS->nRasterYSize - 0.5) * delta_lat; poDS->adfGeoTransform[4] = 0.0; - poDS->adfGeoTransform[5] = -1 * delta_lat; + poDS->adfGeoTransform[5] = -1.0 * delta_lat; /* -------------------------------------------------------------------- */ /* Initialize any PAM information. */ diff --git a/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp b/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp index e588e38b033e..9fa49dcfce06 100644 --- a/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp +++ b/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp @@ -296,6 +296,7 @@ OGRErr OGRGeoPackageTableLayer::FeatureBindParameters( { const int iField = nUpdatedFieldsCount < 0 ? idx : panUpdatedFieldsIdx[idx]; + assert(iField >= 0); if (iField == m_iFIDAsRegularColumnIndex || m_abGeneratedColumns[iField]) continue; diff --git a/ogr/ogrsf_frmts/s57/s57reader.cpp b/ogr/ogrsf_frmts/s57/s57reader.cpp index eb2a4606cde7..2590d60c8177 100644 --- a/ogr/ogrsf_frmts/s57/s57reader.cpp +++ b/ogr/ogrsf_frmts/s57/s57reader.cpp @@ -3409,7 +3409,7 @@ bool S57Reader::FindAndApplyUpdates(const char *pszPath) extension.append(buf); dirname.append(buf); } - else if (10 <= iUpdate && iUpdate < 100) + else if (iUpdate < 100) { char buf[3]; CPLsnprintf(buf, sizeof(buf), "%i", iUpdate); @@ -3417,7 +3417,7 @@ bool S57Reader::FindAndApplyUpdates(const char *pszPath) extension.append(buf); dirname.append(buf); } - else if (100 <= iUpdate && iUpdate < 1000) + else if (iUpdate < 1000) { char buf[4]; CPLsnprintf(buf, sizeof(buf), "%i", iUpdate);