diff --git a/.github/workflows/clang_static_analyzer.yml b/.github/workflows/clang_static_analyzer.yml index cfb8b89c5384..aca19bdcd26d 100644 --- a/.github/workflows/clang_static_analyzer.yml +++ b/.github/workflows/clang_static_analyzer.yml @@ -20,11 +20,11 @@ permissions: jobs: clang_static_analyzer: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')" steps: - name: Checkout uses: actions/checkout@v4 - name: Run - run: docker run --rm -v $PWD:$PWD ubuntu:16.04 sh -c "cd $PWD && apt update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sudo software-properties-common && DEBIAN_FRONTEND=noninteractive sh ./ci/travis/csa_common/before_install.sh && sh ./ci/travis/csa_common/install.sh && sh ./ci/travis/csa_common/script.sh" + run: docker run --rm -v $PWD:$PWD ubuntu:22.04 sh -c "cd $PWD && apt update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sudo software-properties-common && DEBIAN_FRONTEND=noninteractive sh ./ci/travis/csa_common/before_install.sh && sh ./ci/travis/csa_common/install.sh && sh ./ci/travis/csa_common/script.sh" diff --git a/alg/gdalpansharpen.cpp b/alg/gdalpansharpen.cpp index 081cbe750c5f..65e5992d4827 100644 --- a/alg/gdalpansharpen.cpp +++ b/alg/gdalpansharpen.cpp @@ -541,7 +541,7 @@ void GDALPansharpenOperation::WeightedBroveyWithNoData( WorkDataType noData, validValue; GDALCopyWord(psOptions->dfNoData, noData); - if (!(std::numeric_limits::is_integer)) + if constexpr (!(std::numeric_limits::is_integer)) validValue = static_cast(noData + 1e-5); else if (noData == std::numeric_limits::min()) validValue = std::numeric_limits::min() + 1; @@ -655,8 +655,11 @@ void GDALPansharpenOperation::WeightedBrovey3( j]; WorkDataType nPansharpenedValue; GDALCopyWord(nRawValue * dfFactor, nPansharpenedValue); - if (bHasBitDepth && nPansharpenedValue > nMaxValue) - nPansharpenedValue = nMaxValue; + if constexpr (bHasBitDepth) + { + if (nPansharpenedValue > nMaxValue) + nPansharpenedValue = nMaxValue; + } GDALCopyWord(nPansharpenedValue, pDataBuf[i * nBandValues + j]); } } @@ -673,15 +676,15 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf, size_t nValues, size_t nBandValues, T nMaxValue) const { - CPL_STATIC_ASSERT(NINPUT == 3 || NINPUT == 4); - CPL_STATIC_ASSERT(NOUTPUT == 3 || NOUTPUT == 4); + static_assert(NINPUT == 3 || NINPUT == 4); + static_assert(NOUTPUT == 3 || NOUTPUT == 4); const XMMReg4Double w0 = XMMReg4Double::Load1ValHighAndLow(psOptions->padfWeights + 0); const XMMReg4Double w1 = XMMReg4Double::Load1ValHighAndLow(psOptions->padfWeights + 1); const XMMReg4Double w2 = XMMReg4Double::Load1ValHighAndLow(psOptions->padfWeights + 2); - const XMMReg4Double w3 = + [[maybe_unused]] const XMMReg4Double w3 = (NINPUT == 3) ? XMMReg4Double::Zero() : XMMReg4Double::Load1ValHighAndLow(psOptions->padfWeights + 3); @@ -703,7 +706,7 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( XMMReg4Double val2 = XMMReg4Double::Load4Val(pUpsampledSpectralBuffer + 2 * nBandValues + j); XMMReg4Double val3; - if (NINPUT == 4 || NOUTPUT == 4) + if constexpr (NINPUT == 4 || NOUTPUT == 4) { val3 = XMMReg4Double::Load4Val(pUpsampledSpectralBuffer + 3 * nBandValues + j); @@ -712,7 +715,7 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( pseudoPanchro += w0 * val0; pseudoPanchro += w1 * val1; pseudoPanchro += w2 * val2; - if (NINPUT == 4) + if constexpr (NINPUT == 4) pseudoPanchro += w3 * val3; /* Little trick to avoid use of ternary operator due to one of the @@ -724,14 +727,14 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( val0 = XMMReg4Double::Min(val0 * factor, maxValue); val1 = XMMReg4Double::Min(val1 * factor, maxValue); val2 = XMMReg4Double::Min(val2 * factor, maxValue); - if (NOUTPUT == 4) + if constexpr (NOUTPUT == 4) { val3 = XMMReg4Double::Min(val3 * factor, maxValue); } val0.Store4Val(pDataBuf + 0 * nBandValues + j); val1.Store4Val(pDataBuf + 1 * nBandValues + j); val2.Store4Val(pDataBuf + 2 * nBandValues + j); - if (NOUTPUT == 4) + if constexpr (NOUTPUT == 4) { val3.Store4Val(pDataBuf + 3 * nBandValues + j); } @@ -746,13 +749,13 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf, size_t nValues, size_t nBandValues, T nMaxValue) const { - // cppcheck-suppress knownConditionTrueFalse - CPLAssert(NINPUT == 3 || NINPUT == 4); + static_assert(NINPUT == 3 || NINPUT == 4); const double dfw0 = psOptions->padfWeights[0]; const double dfw1 = psOptions->padfWeights[1]; const double dfw2 = psOptions->padfWeights[2]; // cppcheck-suppress knownConditionTrueFalse - const double dfw3 = (NINPUT == 3) ? 0 : psOptions->padfWeights[3]; + [[maybe_unused]] const double dfw3 = + (NINPUT == 3) ? 0 : psOptions->padfWeights[3]; size_t j = 0; // Used after for. for (; j + 1 < nValues; j += 2) { @@ -772,7 +775,7 @@ size_t GDALPansharpenOperation::WeightedBroveyPositiveWeightsInternal( dfPseudoPanchro2 += dfw2 * pUpsampledSpectralBuffer[2 * nBandValues + j + 1]; - if (NINPUT == 4) + if constexpr (NINPUT == 4) { dfPseudoPanchro += dfw3 * pUpsampledSpectralBuffer[3 * nBandValues + j]; diff --git a/alg/gdalsievefilter.cpp b/alg/gdalsievefilter.cpp index 6ead6fc3715b..f81f2d3259fe 100644 --- a/alg/gdalsievefilter.cpp +++ b/alg/gdalsievefilter.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -321,9 +322,9 @@ CPLErr CPL_STDCALL GDALSieveFilter(GDALRasterBandH hSrcBand, /* Push the sizes of merged polygon fragments into the */ /* merged polygon id's count. */ /* -------------------------------------------------------------------- */ - for (int iPoly = 0; oFirstEnum.panPolyIdMap != nullptr && // for Coverity - iPoly < oFirstEnum.nNextPolygonId; - iPoly++) + assert(oFirstEnum.panPolyIdMap != nullptr); // for Coverity + assert(oFirstEnum.panPolyValue != nullptr); // for Coverity + for (int iPoly = 0; iPoly < oFirstEnum.nNextPolygonId; iPoly++) { if (oFirstEnum.panPolyIdMap[iPoly] != iPoly) { @@ -462,10 +463,7 @@ CPLErr CPL_STDCALL GDALSieveFilter(GDALRasterBandH hSrcBand, int nIsolatedSmall = 0; int nSieveTargets = 0; - for (int iPoly = 0; oFirstEnum.panPolyIdMap != nullptr && // for Coverity - oFirstEnum.panPolyValue != nullptr && // for Coverity - iPoly < static_cast(anPolySizes.size()); - iPoly++) + for (int iPoly = 0; iPoly < static_cast(anPolySizes.size()); iPoly++) { if (oFirstEnum.panPolyIdMap[iPoly] != iPoly) continue; diff --git a/alg/gdalwarpkernel.cpp b/alg/gdalwarpkernel.cpp index 92cd175780e7..0ed56784ef51 100644 --- a/alg/gdalwarpkernel.cpp +++ b/alg/gdalwarpkernel.cpp @@ -5700,14 +5700,14 @@ static void GWKResampleNoMasksOrDstDensityOnlyThreadInternal(void *pData) for (int iBand = 0; iBand < poWK->nBands; iBand++) { T value = 0; - if (eResample == GRA_NearestNeighbour) + if constexpr (eResample == GRA_NearestNeighbour) { value = reinterpret_cast( poWK->papabySrcImage[iBand])[iSrcOffset]; } - else if (bUse4SamplesFormula) + else if constexpr (bUse4SamplesFormula) { - if (eResample == GRA_Bilinear) + if constexpr (eResample == GRA_Bilinear) GWKBilinearResampleNoMasks4SampleT( poWK, iBand, padfX[iDstX] - poWK->nSrcXOff, padfY[iDstX] - poWK->nSrcYOff, &value); @@ -5774,7 +5774,7 @@ static void GWKResampleNoMasksOrDstDensityOnlyHas4SampleThread(void *pData) { GWKJobStruct *psJob = static_cast(pData); GDALWarpKernel *poWK = psJob->poWK; - CPLAssert(eResample == GRA_Bilinear || eResample == GRA_Cubic); + static_assert(eResample == GRA_Bilinear || eResample == GRA_Cubic); const bool bUse4SamplesFormula = poWK->dfXScale >= 0.95 && poWK->dfYScale >= 0.95; if (bUse4SamplesFormula) diff --git a/apps/gdalmanage.cpp b/apps/gdalmanage.cpp index f64ef82eb6f7..0c59fd1bef5d 100644 --- a/apps/gdalmanage.cpp +++ b/apps/gdalmanage.cpp @@ -105,33 +105,29 @@ static void Identify(int nArgc, char **papszArgv) bool bForceRecurse = false; bool bReportFailures = false; - while (nArgc > 0 && papszArgv[0][0] == '-') + int i = 0; + for (; i < nArgc && papszArgv[i][0] == '-'; ++i) { - if (EQUAL(papszArgv[0], "-r")) + if (EQUAL(papszArgv[i], "-r")) bRecursive = true; - else if (EQUAL(papszArgv[0], "-fr")) + else if (EQUAL(papszArgv[i], "-fr")) { bForceRecurse = true; bRecursive = true; } - else if (EQUAL(papszArgv[0], "-u")) + else if (EQUAL(papszArgv[i], "-u")) bReportFailures = true; else Usage(true); - - papszArgv++; - nArgc--; } /* -------------------------------------------------------------------- */ /* Process given files. */ /* -------------------------------------------------------------------- */ - while (nArgc > 0) + for (; i < nArgc; ++i) { - ProcessIdentifyTarget(papszArgv[0], nullptr, bRecursive, + ProcessIdentifyTarget(papszArgv[i], nullptr, bRecursive, bReportFailures, bForceRecurse); - nArgc--; - papszArgv++; } } @@ -193,7 +189,7 @@ MAIN_START(argc, argv) if (argc < 1) exit(-argc); - for (int i = 0; argv != nullptr && argv[i] != nullptr; i++) + for (int i = 0; i < argc; i++) { if (EQUAL(argv[i], "--help")) { diff --git a/apps/test_ogrsf.cpp b/apps/test_ogrsf.cpp index 70cf97d8fff0..ec3a0a1d5841 100644 --- a/apps/test_ogrsf.cpp +++ b/apps/test_ogrsf.cpp @@ -161,8 +161,7 @@ MAIN_START(nArgc, papszArgv) { pszSQLStatement = papszArgv[++iArg]; } - else if (EQUAL(papszArgv[iArg], "-dialect") && - papszArgv[iArg + 1] != nullptr) + else if (EQUAL(papszArgv[iArg], "-dialect") && iArg + 1 < nArgc) { pszDialect = papszArgv[++iArg]; } diff --git a/ci/travis/csa_common/before_install.sh b/ci/travis/csa_common/before_install.sh index 6652f934b48d..470b438cc21a 100755 --- a/ci/travis/csa_common/before_install.sh +++ b/ci/travis/csa_common/before_install.sh @@ -2,44 +2,85 @@ set -e -sudo apt-get purge -y libgeos* -(sudo mv /etc/apt/sources.list.d/pgdg* /tmp || /bin/true) -#sudo apt-get remove postgresql-9.2 -#sudo apt-get remove postgis libpq5 libpq-dev postgresql-9.1-postgis postgresql-9.1-postgis-2.2-scripts postgresql-9.2-postgis postgresql-9.3-postgis postgresql-9.1 postgresql-9.2 postgresql-9.3 libgdal1 -# This currently fails as of https://lists.osgeo.org/pipermail/ubuntu/2023-October/002046.html -# sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable -sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6B827C12C2D425E227EDCA75089EBE08314DF160 -sudo add-apt-repository -y http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu/ -#sudo add-apt-repository -y ppa:marlam/gta sudo apt-get update -qq -sudo apt-get install -y automake python-numpy postgis libpq-dev libpng12-dev libjpeg-dev libgif-dev liblzma-dev libgeos-dev libcurl4-gnutls-dev libproj-dev libxml2-dev libexpat-dev libxerces-c-dev libnetcdf-dev netcdf-bin libpoppler-dev libpoppler-private-dev libspatialite-dev gpsbabel swig libhdf4-alt-dev libhdf5-serial-dev libhdf5-dev libpodofo-dev poppler-utils libfreexl-dev unixodbc-dev libwebp-dev openjdk-8-jdk libepsilon-dev liblcms2-2 libpcre3-dev mercurial cmake libkml-dev libopenjp2-7-dev libzstd1-dev sqlite3 wget unzip curl -# libgda-dev -# libcrypto++-dev -#sudo apt-get install python-lxml -#sudo apt-get install python-pip -sudo apt-get install libogdi3.2-dev -# Boost for Mongo -#sudo apt-get install libboost-regex-dev libboost-system-dev libboost-thread-dev -#sudo pip install pyflakes -#pyflakes autotest -#pyflakes gdal/swig/python/gdal-utils/scripts -#pyflakes gdal/swig/python/gdal-utils/osgeo_utils/samples -#psql -c "drop database if exists autotest" -U postgres -#psql -c "create database autotest" -U postgres -#psql -c "create extension postgis" -d autotest -U postgres -#mysql -e "create database autotest;" -#mysql -e "GRANT ALL ON autotest.* TO 'root'@'localhost';" -u root -#mysql -e "GRANT ALL ON autotest.* TO 'travis'@'localhost';" -u root +sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated autoconf \ + automake \ + bash \ + ccache \ + cmake \ + curl \ + doxygen \ + fossil \ + g++ \ + git \ + gpsbabel \ + libblosc-dev \ + libboost-dev \ + libcairo2-dev \ + libcfitsio-dev \ + libcrypto++-dev \ + libcurl4-gnutls-dev \ + libexpat-dev \ + libfcgi-dev \ + libfyba-dev \ + libfreexl-dev \ + libgeos-dev \ + libgeotiff-dev \ + libgif-dev \ + libhdf4-alt-dev \ + libhdf5-serial-dev \ + libjpeg-dev \ + libkml-dev \ + liblcms2-2 \ + liblz4-dev \ + liblzma-dev \ + libmysqlclient-dev \ + libnetcdf-dev \ + libogdi-dev \ + libopenexr-dev \ + libopenjp2-7-dev \ + libpcre3-dev \ + libpng-dev \ + libpoppler-dev \ + libpoppler-private-dev \ + libpq-dev \ + libproj-dev \ + librasterlite2-dev \ + libspatialite-dev \ + libssl-dev \ + libwebp-dev \ + libxerces-c-dev \ + libxml2-dev \ + libxslt-dev \ + libzstd-dev \ + locales \ + mysql-client-core-8.0 \ + netcdf-bin \ + openjdk-8-jdk \ + poppler-utils \ + postgis \ + postgresql-client \ + python3-dev \ + python3-numpy \ + python3-pip \ + sqlite3 \ + swig \ + unixodbc-dev \ + wget \ + zip + +sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated clang-tools wget https://github.com/Esri/file-geodatabase-api/raw/master/FileGDB_API_1.5/FileGDB_API_1_5_64gcc51.tar.gz tar xzf FileGDB_API_1_5_64gcc51.tar.gz sudo cp -r FileGDB_API-64gcc51/include/* /usr/local/include sudo cp -r FileGDB_API-64gcc51/lib/* /usr/local/lib +sudo rm -f /usr/local/lib/libstdc++.so* -wget http://s3.amazonaws.com/etc-data.koordinates.com/gdal-travisci/install-libecwj2-ubuntu12.04-64bit.tar.gz -tar xzf install-libecwj2-ubuntu12.04-64bit.tar.gz -sudo cp -r install-libecwj2/include/* /usr/local/include -sudo cp -r install-libecwj2/lib/* /usr/local/lib +wget https://github.com/rouault/libecwj2-3.3-builds/releases/download/v1/install-libecwj2-3.3-ubuntu-20.04.tar.gz +tar xzf install-libecwj2-3.3-ubuntu-20.04.tar.gz +sudo mv opt/libecwj2-3.3 /opt +sudo sh -c 'echo "/opt/libecwj2-3.3/lib" > /etc/ld.so.conf.d/libecwj2-3.3.conf' wget https://github.com/ubarsc/kealib/archive/kealib-1.4.12.zip unzip kealib-1.4.12.zip @@ -48,7 +89,3 @@ cmake . -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX make -j4; sudo make install) sudo ldconfig - -FILE=clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz -URL_ROOT=https://github.com/rouault/gdal_ci_tools/raw/master/${FILE} -curl -Ls ${URL_ROOT}aa ${URL_ROOT}ab ${URL_ROOT}ac ${URL_ROOT}ad ${URL_ROOT}ae | tar xJf - diff --git a/ci/travis/csa_common/install.sh b/ci/travis/csa_common/install.sh index cd608b64ca18..a83b36959e42 100755 --- a/ci/travis/csa_common/install.sh +++ b/ci/travis/csa_common/install.sh @@ -15,26 +15,15 @@ case $SCRIPT_DIR in esac $SCRIPT_DIR/../common_install.sh -# Build proj -(cd proj; ./autogen.sh && CFLAGS='-DPROJ_RENAME_SYMBOLS' CXXFLAGS='-DPROJ_RENAME_SYMBOLS' ./configure --disable-static --prefix=/usr/local && make -j3) -(cd proj; sudo make -j3 install && sudo ldconfig) - -export PATH=$PWD/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04/bin:$PATH - -wget -q https://github.com/Kitware/CMake/releases/download/v3.22.3/cmake-3.22.3-linux-x86_64.tar.gz -tar xzf cmake-3.22.3-linux-x86_64.tar.gz -export PATH=$PWD/cmake-3.22.3-linux-x86_64/bin:$PATH - GDAL_TOPDIR=$PWD mkdir build cd build -export CXXFLAGS="-std=c++11 -DCSA_BUILD -DPROJ_RENAME_SYMBOLS" -export CFLAGS="-DCSA_BUILD -DPROJ_RENAME_SYMBOLS" +export CXXFLAGS="-DCSA_BUILD" +export CFLAGS="-DCSA_BUILD" scan-build cmake .. \ -DCMAKE_BUILD_TYPE=Debug \ - -DPROJ_ROOT=/usr/local \ - -DECW_ROOT=/usr/local \ + -DECW_ROOT=/opt \ -DFileGDB_ROOT=/usr/local \ -DGDAL_ENABLE_DRIVER_GRIB=OFF \ -DBUILD_PYTHON_BINDINGS=OFF \ diff --git a/ci/travis/csa_common/script.sh b/ci/travis/csa_common/script.sh index 6546b56f4d28..ac7bfe1a14c8 100755 --- a/ci/travis/csa_common/script.sh +++ b/ci/travis/csa_common/script.sh @@ -8,7 +8,7 @@ rm -f filtered_scanbuild.txt files=$(find scanbuildoutput -name "*.sarif") for f in $files; do # CSA 10 uses artifactLocation. Earlier versions used fileLocation - (sed 's/fileLocation/artifactLocation/g' < $f) |jq '.runs[].results[] | (if .locations[].physicalLocation.artifactLocation.uri | (contains("/usr/include") or contains("degrib") or contains("libpng") or contains("libjpeg") or contains("EHapi") or contains("GDapi") or contains("SWapi") or contains("osr_cs_wkt_parser") or contains("ods_formula_parser") or contains("swq_parser") or contains("json_tokener") ) then empty else { "uri": .locations[].physicalLocation.artifactLocation.uri, "msg": .message.text, "location": .codeFlows[-1].threadFlows[-1].locations[-1] } end)' > tmp.txt + (sed 's/fileLocation/artifactLocation/g' < $f) |jq '.runs[].results[] | (if .locations[].physicalLocation.artifactLocation.uri | (contains("/usr/include") or contains("degrib") or contains("libpng") or contains("libjpeg") or contains("EHapi") or contains("GDapi") or contains("SWapi") or contains("osr_cs_wkt_parser") or contains("ods_formula_parser") or contains("swq_parser") or contains("libjson") or contains("flatbuffers") or contains("cpl_minizip_zip.cpp") or contains("gdal_rpc.cpp") or contains("internal_libqhull") ) then empty else { "uri": .locations[].physicalLocation.artifactLocation.uri, "msg": .message.text, "location": .codeFlows[-1].threadFlows[-1].locations[-1] } end)' > tmp.txt if [ -s tmp.txt ]; then echo "Errors from $f: " cat $f diff --git a/frmts/gtiff/gtiffrasterband_read.cpp b/frmts/gtiff/gtiffrasterband_read.cpp index 458ea20465d3..eafdd9192056 100644 --- a/frmts/gtiff/gtiffrasterband_read.cpp +++ b/frmts/gtiff/gtiffrasterband_read.cpp @@ -1604,7 +1604,7 @@ const char *GTiffRasterBand::GetMetadataItem(const char *pszName, return CPLSPrintf(CPL_FRMT_GUIB, static_cast(nByteCount)); } } - else if (pszDomain != nullptr && EQUAL(pszDomain, "_DEBUG_")) + else if (pszName && pszDomain && EQUAL(pszDomain, "_DEBUG_")) { if (EQUAL(pszName, "HAS_BLOCK_CACHE")) return HasBlockCache() ? "1" : "0"; @@ -1612,7 +1612,7 @@ const char *GTiffRasterBand::GetMetadataItem(const char *pszName, const char *pszRet = m_oGTiffMDMD.GetMetadataItem(pszName, pszDomain); - if (pszRet == nullptr && eDataType == GDT_Byte && pszDomain != nullptr && + if (pszRet == nullptr && eDataType == GDT_Byte && pszName && pszDomain && EQUAL(pszDomain, "IMAGE_STRUCTURE") && EQUAL(pszName, "PIXELTYPE")) { // to get a chance of emitting the warning about this legacy usage diff --git a/frmts/iso8211/ddffield.cpp b/frmts/iso8211/ddffield.cpp index 6a0e03dcd060..fe870e200d0b 100644 --- a/frmts/iso8211/ddffield.cpp +++ b/frmts/iso8211/ddffield.cpp @@ -72,8 +72,9 @@ void DDFField::Dump(FILE *fp) { int nMaxRepeat = 8; - if (getenv("DDF_MAXDUMP") != nullptr) - nMaxRepeat = atoi(getenv("DDF_MAXDUMP")); + const char *pszDDF_MAXDUMP = getenv("DDF_MAXDUMP"); + if (pszDDF_MAXDUMP != nullptr) + nMaxRepeat = atoi(pszDDF_MAXDUMP); fprintf(fp, " DDFField:\n"); fprintf(fp, " Tag = `%s'\n", poDefn->GetName()); diff --git a/frmts/msgn/msgndataset.cpp b/frmts/msgn/msgndataset.cpp index 558cf94f7824..f80f58288ad1 100644 --- a/frmts/msgn/msgndataset.cpp +++ b/frmts/msgn/msgndataset.cpp @@ -422,19 +422,22 @@ GDALDataset *MSGNDataset::Open(GDALOpenInfo *poOpenInfo) { open_mode_type open_mode = MODE_VISIR; GDALOpenInfo *open_info = poOpenInfo; + std::unique_ptr poOpenInfoToFree; if (!poOpenInfo->bStatOK) { if (STARTS_WITH_CI(poOpenInfo->pszFilename, "HRV:")) { - open_info = new GDALOpenInfo(&poOpenInfo->pszFilename[4], - poOpenInfo->eAccess); + poOpenInfoToFree = std::make_unique( + &poOpenInfo->pszFilename[4], poOpenInfo->eAccess); + open_info = poOpenInfoToFree.get(); open_mode = MODE_HRV; } else if (STARTS_WITH_CI(poOpenInfo->pszFilename, "RAD:")) { - open_info = new GDALOpenInfo(&poOpenInfo->pszFilename[4], - poOpenInfo->eAccess); + poOpenInfoToFree = std::make_unique( + &poOpenInfo->pszFilename[4], poOpenInfo->eAccess); + open_info = poOpenInfoToFree.get(); open_mode = MODE_RAD; } } @@ -446,10 +449,6 @@ GDALDataset *MSGNDataset::Open(GDALOpenInfo *poOpenInfo) /* -------------------------------------------------------------------- */ if (open_info->fpL == nullptr || open_info->nHeaderBytes < 50) { - if (open_info != poOpenInfo) - { - delete open_info; - } return nullptr; } @@ -457,10 +456,6 @@ GDALDataset *MSGNDataset::Open(GDALOpenInfo *poOpenInfo) if (!STARTS_WITH_CI((char *)open_info->pabyHeader, "FormatName : NATIVE")) { - if (open_info != poOpenInfo) - { - delete open_info; - } return nullptr; } @@ -472,10 +467,6 @@ GDALDataset *MSGNDataset::Open(GDALOpenInfo *poOpenInfo) CPLError(CE_Failure, CPLE_NotSupported, "The MSGN driver does not support update access to existing" " datasets.\n"); - if (open_info != poOpenInfo) - { - delete open_info; - } return nullptr; } @@ -485,14 +476,10 @@ GDALDataset *MSGNDataset::Open(GDALOpenInfo *poOpenInfo) VSILFILE *fp = VSIFOpenL(open_info->pszFilename, "rb"); if (fp == nullptr) { - if (open_info != poOpenInfo) - { - delete open_info; - } return nullptr; } - MSGNDataset *poDS = new MSGNDataset(); + auto poDS = std::make_unique(); poDS->m_open_mode = open_mode; poDS->fp = fp; @@ -507,11 +494,6 @@ GDALDataset *MSGNDataset::Open(GDALOpenInfo *poOpenInfo) if (!poDS->msg_reader_core->get_open_success()) { - if (open_info != poOpenInfo) - { - delete open_info; - } - delete poDS; return nullptr; } @@ -675,8 +657,8 @@ GDALDataset *MSGNDataset::Open(GDALOpenInfo *poOpenInfo) if (ok_to_add) { poDS->SetBand(band_count, - new MSGNRasterBand(poDS, band_count, open_mode, - i + 1, + new MSGNRasterBand(poDS.get(), band_count, + open_mode, i + 1, i + 1 - missing_band_count)); band_map[band_count] = (unsigned char)(i + 1); band_count++; @@ -824,12 +806,7 @@ GDALDataset *MSGNDataset::Open(GDALOpenInfo *poOpenInfo) poDS->msg_reader_core->get_col_start()); poDS->SetMetadataItem("Origin", field); - if (open_info != poOpenInfo) - { - delete open_info; - } - - return poDS; + return poDS.release(); } /************************************************************************/ diff --git a/frmts/png/filter_sse2_intrinsics.c b/frmts/png/filter_sse2_intrinsics.c index 5d1b4b55dcf1..f4c35ff2f0c8 100644 --- a/frmts/png/filter_sse2_intrinsics.c +++ b/frmts/png/filter_sse2_intrinsics.c @@ -98,9 +98,9 @@ static void gdal_png_read_filter_row_sub3_sse2(png_row_infop row_info, d = _mm_add_epi8(d, a); store3(row, d); - input += 3; - row += 3; - rb -= 3; + //input += 3; + //row += 3; + //rb -= 3; } } @@ -188,10 +188,10 @@ static void gdal_png_read_filter_row_avg3_sse2(png_row_infop row_info, d = _mm_add_epi8(d, avg); store3(row, d); - input += 3; - prev += 3; - row += 3; - rb -= 3; + // input += 3; + // prev += 3; + // row += 3; + // rb -= 3; } } @@ -366,10 +366,10 @@ static void gdal_png_read_filter_row_paeth3_sse2(png_row_infop row_info, d = _mm_add_epi8(d, nearest); store3(row, _mm_packus_epi16(d, d)); - input += 3; - prev += 3; - row += 3; - rb -= 3; + // input += 3; + // prev += 3; + // row += 3; + // rb -= 3; } } diff --git a/frmts/png/pngdataset.cpp b/frmts/png/pngdataset.cpp index 1983b11597a8..784da7cf48ed 100644 --- a/frmts/png/pngdataset.cpp +++ b/frmts/png/pngdataset.cpp @@ -415,7 +415,7 @@ CPLErr PNGDataset::LoadWholeImage(void *pSingleBuffer, GSpacing nPixelSpace, // We try to read the zlib compressed data into pData, if there is // enough room for that - size_t pDataSize = 0; + size_t nDataSize = 0; std::vector abyCompressedData; // keep in this scope GByte *pabyCompressedData = static_cast(pSingleBuffer); size_t nCompressedDataSize = 0; @@ -424,14 +424,14 @@ CPLErr PNGDataset::LoadWholeImage(void *pSingleBuffer, GSpacing nPixelSpace, if (nPixelSpace == nBands && nLineSpace == nPixelSpace * nRasterXSize && (nBands == 1 || nBandSpace == 1)) { - pDataSize = + nDataSize = static_cast(nRasterXSize) * nRasterYSize * nBands; } else if (nPixelSpace == 1 && nLineSpace == nRasterXSize && nBandSpace == static_cast(nRasterXSize) * nRasterYSize) { - pDataSize = + nDataSize = static_cast(nRasterXSize) * nRasterYSize * nBands; } } @@ -485,7 +485,7 @@ CPLErr PNGDataset::LoadWholeImage(void *pSingleBuffer, GSpacing nPixelSpace, } } - if (nCompressedDataSize + nChunkSize > pDataSize) + if (nCompressedDataSize + nChunkSize > nDataSize) { const bool bVectorEmptyBefore = abyCompressedData.empty(); // unlikely situation: would mean that the zlib compressed @@ -502,9 +502,12 @@ CPLErr PNGDataset::LoadWholeImage(void *pSingleBuffer, GSpacing nPixelSpace, bError = true; break; } - if (bVectorEmptyBefore && nCompressedDataSize > 0) + if (bVectorEmptyBefore && pSingleBuffer && + nCompressedDataSize > 0) + { memcpy(pabyCompressedData, pSingleBuffer, nCompressedDataSize); + } } VSIFReadL(pabyCompressedData + nCompressedDataSize, nChunkSize, 1, fpImage); @@ -1202,7 +1205,8 @@ CPLErr PNGRasterBand::IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, else if (nBlockYSize > 1) { void *apabyBuffers[4]; - GDALRasterBlock *apoBlocks[4]; + GDALRasterBlock *apoBlocks[4] = {nullptr, nullptr, nullptr, + nullptr}; CPLErr eErr = CE_None; bool bNeedToUseDefaultCase = true; for (int i = 0; i < poGDS->nBands; ++i) @@ -1212,7 +1216,6 @@ CPLErr PNGRasterBand::IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, { bNeedToUseDefaultCase = false; apabyBuffers[i] = pData; - apoBlocks[i] = nullptr; } else { diff --git a/gcore/gdal_priv_templates.hpp b/gcore/gdal_priv_templates.hpp index a7962bd7a498..337f6e8317a1 100644 --- a/gcore/gdal_priv_templates.hpp +++ b/gcore/gdal_priv_templates.hpp @@ -54,13 +54,13 @@ inline void GDALGetDataLimits(Tin &tMaxValue, Tin &tMinValue) tMinValue = std::numeric_limits::min(); // Compute the actual minimum value of Tout in terms of Tin. - if (std::numeric_limits::is_signed && - std::numeric_limits::is_integer) + if constexpr (std::numeric_limits::is_signed && + std::numeric_limits::is_integer) { // the minimum value is less than zero - if (std::numeric_limits::digits < - std::numeric_limits::digits || - !std::numeric_limits::is_integer) + if constexpr (std::numeric_limits::digits < + std::numeric_limits::digits || + !std::numeric_limits::is_integer) { // Tout is smaller than Tin, so we need to clamp values in input // to the range of Tout's min/max values @@ -71,12 +71,12 @@ inline void GDALGetDataLimits(Tin &tMaxValue, Tin &tMinValue) tMaxValue = static_cast(std::numeric_limits::max()); } } - else if (std::numeric_limits::is_integer) + else if constexpr (std::numeric_limits::is_integer) { // the output is unsigned, so we just need to determine the max /* coverity[same_on_both_sides] */ - if (std::numeric_limits::digits <= - std::numeric_limits::digits) + if constexpr (std::numeric_limits::digits <= + std::numeric_limits::digits) { // Tout is smaller than Tin, so we need to clamp the input values // to the range of Tout's max diff --git a/gcore/gdalrasterband.cpp b/gcore/gdalrasterband.cpp index d0ca7600a0e9..897d1561a565 100644 --- a/gcore/gdalrasterband.cpp +++ b/gcore/gdalrasterband.cpp @@ -4521,7 +4521,7 @@ struct ComputeStatisticsInternalGeneric nMin = nValue; if (nValue > nMax) nMax = nValue; - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nValidCount++; nSum += nValue; @@ -4531,7 +4531,7 @@ struct ComputeStatisticsInternalGeneric } } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += static_cast(nXCheck) * nYCheck; } @@ -4539,43 +4539,42 @@ struct ComputeStatisticsInternalGeneric else if (nMin == std::numeric_limits::min() && nMax == std::numeric_limits::max()) { - if (!COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { - return; - } - // Optimization when there is no nodata and we know we have already - // reached the min and max - for (int iY = 0; iY < nYCheck; iY++) - { - int iX; - for (iX = 0; iX + 3 < nXCheck; iX += 4) - { - const GPtrDiff_t iOffset = - iX + static_cast(iY) * nBlockXSize; - const GUIntBig nValue = pData[iOffset]; - const GUIntBig nValue2 = pData[iOffset + 1]; - const GUIntBig nValue3 = pData[iOffset + 2]; - const GUIntBig nValue4 = pData[iOffset + 3]; - nSum += nValue; - nSumSquare += nValue * nValue; - nSum += nValue2; - nSumSquare += nValue2 * nValue2; - nSum += nValue3; - nSumSquare += nValue3 * nValue3; - nSum += nValue4; - nSumSquare += nValue4 * nValue4; - } - for (; iX < nXCheck; ++iX) + // Optimization when there is no nodata and we know we have already + // reached the min and max + for (int iY = 0; iY < nYCheck; iY++) { - const GPtrDiff_t iOffset = - iX + static_cast(iY) * nBlockXSize; - const GUIntBig nValue = pData[iOffset]; - nSum += nValue; - nSumSquare += nValue * nValue; + int iX; + for (iX = 0; iX + 3 < nXCheck; iX += 4) + { + const GPtrDiff_t iOffset = + iX + static_cast(iY) * nBlockXSize; + const GUIntBig nValue = pData[iOffset]; + const GUIntBig nValue2 = pData[iOffset + 1]; + const GUIntBig nValue3 = pData[iOffset + 2]; + const GUIntBig nValue4 = pData[iOffset + 3]; + nSum += nValue; + nSumSquare += nValue * nValue; + nSum += nValue2; + nSumSquare += nValue2 * nValue2; + nSum += nValue3; + nSumSquare += nValue3 * nValue3; + nSum += nValue4; + nSumSquare += nValue4 * nValue4; + } + for (; iX < nXCheck; ++iX) + { + const GPtrDiff_t iOffset = + iX + static_cast(iY) * nBlockXSize; + const GUIntBig nValue = pData[iOffset]; + nSum += nValue; + nSumSquare += nValue * nValue; + } } + nSampleCount += static_cast(nXCheck) * nYCheck; + nValidCount += static_cast(nXCheck) * nYCheck; } - nSampleCount += static_cast(nXCheck) * nYCheck; - nValidCount += static_cast(nXCheck) * nYCheck; } else { @@ -4602,7 +4601,7 @@ struct ComputeStatisticsInternalGeneric if (nValue > nMax) nMax = nValue; } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum += nValue; nSumSquare += @@ -4632,7 +4631,7 @@ struct ComputeStatisticsInternalGeneric } } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += static_cast(nXCheck) * nYCheck; nValidCount += static_cast(nXCheck) * nYCheck; @@ -4684,14 +4683,14 @@ struct ComputeStatisticsInternalGeneric nMin = nValue; if (nValue > nMax) nMax = nValue; - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nValidCount32bit++; nSum32bit += nValue; nSumSquare32bit += nValue * nValue; } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += nSampleCount32bit; nValidCount += nValidCount32bit; @@ -4703,52 +4702,52 @@ struct ComputeStatisticsInternalGeneric } else if (nMin == 0 && nMax == 255) { - if (!COMPUTE_OTHER_STATS) - return; - - // Optimization when there is no nodata and we know we have already - // reached the min and max - for (int iY = 0; iY < nYCheck; iY++) + if constexpr (COMPUTE_OTHER_STATS) { - int iX = 0; - for (int k = 0; k < nOuterLoops; k++) + // Optimization when there is no nodata and we know we have already + // reached the min and max + for (int iY = 0; iY < nYCheck; iY++) { - int iMax = iX + 65536; - if (iMax > nXCheck) - iMax = nXCheck; - GUInt32 nSum32bit = 0; - GUInt32 nSumSquare32bit = 0; - for (; iX + 3 < iMax; iX += 4) + int iX = 0; + for (int k = 0; k < nOuterLoops; k++) + { + int iMax = iX + 65536; + if (iMax > nXCheck) + iMax = nXCheck; + GUInt32 nSum32bit = 0; + GUInt32 nSumSquare32bit = 0; + for (; iX + 3 < iMax; iX += 4) + { + const GPtrDiff_t iOffset = + iX + static_cast(iY) * nBlockXSize; + const GUInt32 nValue = pData[iOffset]; + const GUInt32 nValue2 = pData[iOffset + 1]; + const GUInt32 nValue3 = pData[iOffset + 2]; + const GUInt32 nValue4 = pData[iOffset + 3]; + nSum32bit += nValue; + nSumSquare32bit += nValue * nValue; + nSum32bit += nValue2; + nSumSquare32bit += nValue2 * nValue2; + nSum32bit += nValue3; + nSumSquare32bit += nValue3 * nValue3; + nSum32bit += nValue4; + nSumSquare32bit += nValue4 * nValue4; + } + nSum += nSum32bit; + nSumSquare += nSumSquare32bit; + } + for (; iX < nXCheck; ++iX) { const GPtrDiff_t iOffset = iX + static_cast(iY) * nBlockXSize; - const GUInt32 nValue = pData[iOffset]; - const GUInt32 nValue2 = pData[iOffset + 1]; - const GUInt32 nValue3 = pData[iOffset + 2]; - const GUInt32 nValue4 = pData[iOffset + 3]; - nSum32bit += nValue; - nSumSquare32bit += nValue * nValue; - nSum32bit += nValue2; - nSumSquare32bit += nValue2 * nValue2; - nSum32bit += nValue3; - nSumSquare32bit += nValue3 * nValue3; - nSum32bit += nValue4; - nSumSquare32bit += nValue4 * nValue4; + const GUIntBig nValue = pData[iOffset]; + nSum += nValue; + nSumSquare += nValue * nValue; } - nSum += nSum32bit; - nSumSquare += nSumSquare32bit; - } - for (; iX < nXCheck; ++iX) - { - const GPtrDiff_t iOffset = - iX + static_cast(iY) * nBlockXSize; - const GUIntBig nValue = pData[iOffset]; - nSum += nValue; - nSumSquare += nValue * nValue; } + nSampleCount += static_cast(nXCheck) * nYCheck; + nValidCount += static_cast(nXCheck) * nYCheck; } - nSampleCount += static_cast(nXCheck) * nYCheck; - nValidCount += static_cast(nXCheck) * nYCheck; } else { @@ -4782,7 +4781,7 @@ struct ComputeStatisticsInternalGeneric if (nValue > nMax) nMax = nValue; } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum32bit += nValue; nSumSquare32bit += nValue * nValue; @@ -4790,7 +4789,7 @@ struct ComputeStatisticsInternalGeneric nSumSquare32bit += nValue2 * nValue2; } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum += nSum32bit; nSumSquare += nSumSquare32bit; @@ -4805,7 +4804,7 @@ struct ComputeStatisticsInternalGeneric nMin = nValue; if (nValue > nMax) nMax = nValue; - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum += nValue; nSumSquare += @@ -4814,7 +4813,7 @@ struct ComputeStatisticsInternalGeneric } } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += static_cast(nXCheck) * nYCheck; nValidCount += static_cast(nXCheck) * nYCheck; @@ -4882,7 +4881,7 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, GDALm256i ymm_min = GDALmm256_load_si256(reinterpret_cast(pData + i)); GDALm256i ymm_max = ymm_min; - const auto ymm_mask_8bits = GDALmm256_set1_epi16(0xFF); + [[maybe_unused]] const auto ymm_mask_8bits = GDALmm256_set1_epi16(0xFF); for (GPtrDiff_t k = 0; k < nOuterLoops; k++) { @@ -4890,8 +4889,9 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, std::min(nBlockPixels, i + nMaxIterationsPerInnerLoop); // holds 4 uint32 sums in [0], [2], [4] and [6] - GDALm256i ymm_sum = ZERO256; - GDALm256i ymm_sumsquare = ZERO256; // holds 8 uint32 sums + [[maybe_unused]] GDALm256i ymm_sum = ZERO256; + [[maybe_unused]] GDALm256i ymm_sumsquare = + ZERO256; // holds 8 uint32 sums for (; i + 31 < iMax; i += 32) { const GDALm256i ymm = GDALmm256_load_si256( @@ -4905,7 +4905,7 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, ymm_max = GDALmm256_max_epu8(ymm_max, ymm); } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { // Extract even-8bit values const GDALm256i ymm_even = @@ -4931,7 +4931,7 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { GDALmm256_store_si256(reinterpret_cast(panSum), ymm_sum); @@ -4946,24 +4946,24 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, } } - if (COMPUTE_MIN) + if constexpr (COMPUTE_MIN) { GDALmm256_store_si256(reinterpret_cast(pabyMin), ymm_min); } - if (COMPUTE_MAX) + if constexpr (COMPUTE_MAX) { GDALmm256_store_si256(reinterpret_cast(pabyMax), ymm_max); } - if (COMPUTE_MIN || COMPUTE_MAX) + if constexpr (COMPUTE_MIN || COMPUTE_MAX) { for (int j = 0; j < 32; j++) { - if (COMPUTE_MIN) + if constexpr (COMPUTE_MIN) { if (pabyMin[j] < nMin) nMin = pabyMin[j]; } - if (COMPUTE_MAX) + if constexpr (COMPUTE_MAX) { if (pabyMax[j] > nMax) nMax = pabyMax[j]; @@ -4974,17 +4974,17 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, for (; i < nBlockPixels; i++) { const GUInt32 nValue = pData[i]; - if (COMPUTE_MIN) + if constexpr (COMPUTE_MIN) { if (nValue < nMin) nMin = nValue; } - if (COMPUTE_MAX) + if constexpr (COMPUTE_MAX) { if (nValue > nMax) nMax = nValue; } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSum += nValue; nSumSquare += @@ -4992,7 +4992,7 @@ ComputeStatisticsByteNoNodata(GPtrDiff_t nBlockPixels, } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += static_cast(nBlockPixels); nValidCount += static_cast(nBlockPixels); @@ -5047,7 +5047,8 @@ struct ComputeStatisticsInternal GDALmm256_set1_epi8(static_cast(nMin)); GDALm256i ymm_min = ymm_neutral; GDALm256i ymm_max = ymm_neutral; - const auto ymm_mask_8bits = GDALmm256_set1_epi16(0xFF); + [[maybe_unused]] const auto ymm_mask_8bits = + GDALmm256_set1_epi16(0xFF); const GUInt32 nMinThreshold = (nNoDataValue == 0) ? 1 : 0; const GUInt32 nMaxThreshold = (nNoDataValue == 255) ? 254 : 255; @@ -5060,11 +5061,11 @@ struct ComputeStatisticsInternal std::min(nBlockPixels, i + nMaxIterationsPerInnerLoop); // holds 4 uint32 sums in [0], [2], [4] and [6] - GDALm256i ymm_sum = ZERO256; + [[maybe_unused]] GDALm256i ymm_sum = ZERO256; // holds 8 uint32 sums - GDALm256i ymm_sumsquare = ZERO256; + [[maybe_unused]] GDALm256i ymm_sumsquare = ZERO256; // holds 4 uint32 sums in [0], [2], [4] and [6] - GDALm256i ymm_count_nodata_mul_255 = ZERO256; + [[maybe_unused]] GDALm256i ymm_count_nodata_mul_255 = ZERO256; const auto iInit = i; for (; i + 31 < iMax; i += 32) { @@ -5074,7 +5075,7 @@ struct ComputeStatisticsInternal // Check which values are nodata const GDALm256i ymm_eq_nodata = GDALmm256_cmpeq_epi8(ymm, ymm_nodata); - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { // Count how many values are nodata (due to cmpeq // putting 255 when condition is met, this will actually @@ -5104,7 +5105,7 @@ struct ComputeStatisticsInternal GDALmm256_max_epu8(ymm_max, ymm_nodata_by_neutral); } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { // Extract even-8bit values const GDALm256i ymm_even = GDALmm256_and_si256( @@ -5132,7 +5133,7 @@ struct ComputeStatisticsInternal } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { GUInt32 *panCoutNoDataMul255 = panSum; GDALmm256_store_si256( @@ -5176,7 +5177,7 @@ struct ComputeStatisticsInternal } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nSampleCount += nBlockPixels - i; } @@ -5189,7 +5190,7 @@ struct ComputeStatisticsInternal nMin = nValue; if (nValue > nMax) nMax = nValue; - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { nValidCount++; nSum += nValue; @@ -5287,7 +5288,8 @@ struct ComputeStatisticsInternal reinterpret_cast(pData + i)); ymm_min = GDALmm256_add_epi16(ymm_min, ymm_m32768); GDALm256i ymm_max = ymm_min; - GDALm256i ymm_sumsquare = ZERO256; // holds 4 uint64 sums + [[maybe_unused]] GDALm256i ymm_sumsquare = + ZERO256; // holds 4 uint64 sums // Make sure that sum can fit on uint32 // * 8 since we can hold 8 sums per vector register @@ -5298,8 +5300,10 @@ struct ComputeStatisticsInternal nOuterLoops++; const bool bComputeMinMax = nMin > 0 || nMax < 65535; - const auto ymm_mask_16bits = GDALmm256_set1_epi32(0xFFFF); - const auto ymm_mask_32bits = GDALmm256_set1_epi64x(0xFFFFFFFF); + [[maybe_unused]] const auto ymm_mask_16bits = + GDALmm256_set1_epi32(0xFFFF); + [[maybe_unused]] const auto ymm_mask_32bits = + GDALmm256_set1_epi64x(0xFFFFFFFF); GUIntBig nSumThis = 0; for (int k = 0; k < nOuterLoops; k++) @@ -5307,7 +5311,8 @@ struct ComputeStatisticsInternal const auto iMax = std::min(nBlockPixels, i + nMaxIterationsPerInnerLoop); - GDALm256i ymm_sum = ZERO256; // holds 8 uint32 sums + [[maybe_unused]] GDALm256i ymm_sum = + ZERO256; // holds 8 uint32 sums for (; i + 15 < iMax; i += 16) { const GDALm256i ymm = GDALmm256_load_si256( @@ -5320,7 +5325,7 @@ struct ComputeStatisticsInternal ymm_max = GDALmm256_max_epi16(ymm_max, ymm_shifted); } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { // Note: the int32 range can overflow for (0-32768)^2 + // (0-32768)^2 = 0x80000000, but as we know the result @@ -5342,7 +5347,7 @@ struct ComputeStatisticsInternal } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { GUInt32 anSum[8]; GDALmm256_storeu_si256(reinterpret_cast(anSum), @@ -5374,7 +5379,7 @@ struct ComputeStatisticsInternal } } - if (COMPUTE_OTHER_STATS) + if constexpr (COMPUTE_OTHER_STATS) { GUIntBig anSumSquare[4]; GDALmm256_storeu_si256( diff --git a/gcore/overview.cpp b/gcore/overview.cpp index 9ec9343431cb..cbf4e25ef023 100644 --- a/gcore/overview.cpp +++ b/gcore/overview.cpp @@ -3501,7 +3501,7 @@ static CPLErr GDALResampleChunk_ConvolutionT( size_t j = (nSrcLineStart - nChunkYOff) * static_cast(nDstXSize); #ifdef USE_SSE2 - if (eWrkDataType == GDT_Float32) + if constexpr (eWrkDataType == GDT_Float32) { #ifdef __AVX__ for (; iFilteredPixelOff + 15 < nDstXSize; diff --git a/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp b/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp index 24e7d50e7fa9..48c3b07fc435 100644 --- a/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp +++ b/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp @@ -121,7 +121,7 @@ OGRFeature *FGdbBaseLayer::GetNextFeature() OGRFeature *pOGRFeature = nullptr; - if (!OGRFeatureFromGdbRow(&row, &pOGRFeature)) + if (!OGRFeatureFromGdbRow(&row, &pOGRFeature) || !pOGRFeature) { int32 oid = -1; CPL_IGNORE_RET_VAL(row.GetOID(oid)); @@ -3828,7 +3828,7 @@ OGRFeature *FGdbLayer::GetNextFeature() OGRFeature *pOGRFeature = nullptr; Row rowFull; if (GetRow(enumRows, rowFull, oid) != OGRERR_NONE || - !OGRFeatureFromGdbRow(&rowFull, &pOGRFeature)) + !OGRFeatureFromGdbRow(&rowFull, &pOGRFeature) || !pOGRFeature) { GDBErr(hr, CPLSPrintf(