Skip to content

Commit

Permalink
Merge pull request #11242 from rouault/csa_2404
Browse files Browse the repository at this point in the history
CI: update to Clang Static Analyzer 18
  • Loading branch information
rouault authored Nov 22, 2024
2 parents 0904e8b + 7c75f2e commit bbf5667
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/clang_static_analyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ permissions:
jobs:

clang_static_analyzer:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Run
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"
run: docker run --rm -v $PWD:$PWD ubuntu:24.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"
10 changes: 7 additions & 3 deletions alg/gdalpansharpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,15 +1463,17 @@ CPLErr GDALPansharpenOperation::ProcessRegion(int nXOff, int nYOff, int nXSize,
nBandBitDepth = atoi(pszNBITS);
if (nBandBitDepth < nBitDepth)
{
if (eWorkDataType == GDT_Byte)
if (eWorkDataType == GDT_Byte && nBitDepth >= 0 &&
nBitDepth <= 8)
{
ClampValues(
reinterpret_cast<GByte *>(pUpsampledSpectralBuffer) +
static_cast<size_t>(i) * nXSize * nYSize,
static_cast<size_t>(nXSize) * nYSize,
static_cast<GByte>((1 << nBitDepth) - 1));
}
else if (eWorkDataType == GDT_UInt16)
else if (eWorkDataType == GDT_UInt16 && nBitDepth >= 0 &&
nBitDepth <= 16)
{
ClampValues(
reinterpret_cast<GUInt16 *>(pUpsampledSpectralBuffer) +
Expand All @@ -1492,7 +1494,9 @@ CPLErr GDALPansharpenOperation::ProcessRegion(int nXOff, int nYOff, int nXSize,
}
}

GUInt32 nMaxValue = (1 << nBitDepth) - 1;
const GUInt32 nMaxValue = (nBitDepth >= 0 && nBitDepth <= 31)
? (1U << nBitDepth) - 1
: UINT32_MAX;

double *padfTempBuffer = nullptr;
GDALDataType eBufDataTypeOri = eBufDataType;
Expand Down
1 change: 1 addition & 0 deletions apps/gdal_grid_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ static void PrintAlgorithmAndOptions(GDALGridAlgorithm eAlgorithm,
case GGA_MetricAverageDistancePts:
{
const char *pszAlgName = "";
CPL_IGNORE_RET_VAL(pszAlgName); // Make CSA happy
switch (eAlgorithm)
{
case GGA_MetricMinimum:
Expand Down
5 changes: 5 additions & 0 deletions apps/ogrinfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static void ReportFieldDomain(CPLString &osRet, CPLJSONObject &oDomains,
osDesc.c_str());
}
const char *pszType = "";
CPL_IGNORE_RET_VAL(pszType); // Make CSA happy
switch (poDomain->GetDomainType())
{
case OFDT_CODED:
Expand Down Expand Up @@ -197,6 +198,7 @@ static void ReportFieldDomain(CPLString &osRet, CPLJSONObject &oDomains,
}

const char *pszSplitPolicy = "";
CPL_IGNORE_RET_VAL(pszSplitPolicy); // Make CSA happy
switch (poDomain->GetSplitPolicy())
{
case OFDSP_DEFAULT_VALUE:
Expand All @@ -220,6 +222,7 @@ static void ReportFieldDomain(CPLString &osRet, CPLJSONObject &oDomains,
}

const char *pszMergePolicy = "";
CPL_IGNORE_RET_VAL(pszMergePolicy); // Make CSA happy
switch (poDomain->GetMergePolicy())
{
case OFDMP_DEFAULT_VALUE:
Expand Down Expand Up @@ -467,6 +470,7 @@ static void ReportRelationships(CPLString &osRet, CPLJSONObject &oRoot,
continue;

const char *pszType = "";
CPL_IGNORE_RET_VAL(pszType); // Make CSA happy
switch (poRelationship->GetType())
{
case GRT_COMPOSITE:
Expand All @@ -481,6 +485,7 @@ static void ReportRelationships(CPLString &osRet, CPLJSONObject &oRoot,
}

const char *pszCardinality = "";
CPL_IGNORE_RET_VAL(pszCardinality); // Make CSA happy
switch (poRelationship->GetCardinality())
{
case GRC_ONE_TO_ONE:
Expand Down
1 change: 1 addition & 0 deletions frmts/ers/ersdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ GDALDataset *ERSDataset::Create(const char *pszFilename, int nXSize, int nYSize,
/* Work out some values we will write. */
/* -------------------------------------------------------------------- */
const char *pszCellType = "Unsigned8BitInteger";
CPL_IGNORE_RET_VAL(pszCellType); // Make CSA happy

if (eType == GDT_Byte)
pszCellType = "Unsigned8BitInteger";
Expand Down
3 changes: 2 additions & 1 deletion frmts/ilwis/ilwisdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ GDALDataset *ILWISDataset::Open(GDALOpenInfo *poOpenInfo)
if (ilwistype.empty())
return nullptr;

const char *pszFileType = ""; // map or map list
const char *pszFileType = ""; // map or map list
CPL_IGNORE_RET_VAL(pszFileType); // Make CSA happy
int iBandCount;
std::string mapsize;
const std::string maptype =
Expand Down
1 change: 1 addition & 0 deletions frmts/iso8211/ddffielddefn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ void DDFFieldDefn::Dump(FILE *fp)

{
const char *pszValue = "";
CPL_IGNORE_RET_VAL(pszValue); // Make CSA happy

fprintf(fp, " DDFFieldDefn:\n");
fprintf(fp, " Tag = `%s'\n", pszTag);
Expand Down
22 changes: 10 additions & 12 deletions frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,25 +964,23 @@ KmlSuperOverlayCreateCopy(const char *pszFilename, GDALDataset *poSrcDS,
/************************************************************************/

/* replace "a/b/../c" pattern by "a/c" */
static CPLString KMLRemoveSlash(const char *pszPathIn)
static std::string KMLRemoveSlash(const char *pszPathIn)
{
char *pszPath = CPLStrdup(pszPathIn);
std::string osRet(pszPathIn);

while (true)
{
char *pszSlashDotDot = strstr(pszPath, "/../");
if (pszSlashDotDot == nullptr || pszSlashDotDot == pszPath)
size_t nSlashDotDot = osRet.find("/../");
if (nSlashDotDot == std::string::npos || nSlashDotDot == 0)
break;
char *pszSlashBefore = pszSlashDotDot - 1;
while (pszSlashBefore > pszPath && *pszSlashBefore != '/')
pszSlashBefore--;
if (pszSlashBefore == pszPath)
size_t nPos = nSlashDotDot - 1;
while (nPos > 0 && osRet[nPos] != '/')
--nPos;
if (nPos == 0)
break;
memmove(pszSlashBefore + 1, pszSlashDotDot + 4,
strlen(pszSlashDotDot + 4) + 1);
osRet = osRet.substr(0, nPos + 1) +
osRet.substr(nSlashDotDot + strlen("/../"));
}
CPLString osRet = pszPath;
CPLFree(pszPath);
return osRet;
}

Expand Down
1 change: 1 addition & 0 deletions frmts/netcdf/netcdfmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ netCDFGroup::CreateDimension(const std::string &osName,
static int CreateOrGetComplexDataType(int gid, GDALDataType eDT)
{
const char *pszName = "";
CPL_IGNORE_RET_VAL(pszName); // Make CSA happy
int nSubTypeId = NC_NAT;
switch (eDT)
{
Expand Down
1 change: 1 addition & 0 deletions frmts/pds/vicardataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ void VICARDataset::BuildLabel()

const auto eType = GetRasterBand(1)->GetRasterDataType();
const char *pszFormat = "";
CPL_IGNORE_RET_VAL(pszFormat); // Make CSA happy
switch (eType)
{
case GDT_Byte:
Expand Down
2 changes: 2 additions & 0 deletions ogr/ograpispy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "cpl_multiproc.h"
#include "ograpispy.h"

#include <cassert>
#include <cstdio>
#include <map>
#include <set>
Expand Down Expand Up @@ -199,6 +200,7 @@ static bool OGRAPISpyEnabled()
if (fpSpyFile == nullptr)
fpSpyFile = stderr;

assert(fpSpyFile != nullptr);
fprintf(fpSpyFile,
"# This file is generated by the OGR_API_SPY mechanism.\n");
fprintf(fpSpyFile, "import os\n");
Expand Down
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/gmlutils/gmlfeatureclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ CPLXMLNode *GMLFeatureClass::SerializeToXML()
{
GMLPropertyDefn *poPDefn = GetProperty(iProperty);
const char *pszTypeName = "Unknown";
CPL_IGNORE_RET_VAL(pszTypeName); // Make CSA happy

CPLXMLNode *psPDefnNode =
CPLCreateXMLNode(nullptr, CXT_Element, "PropertyDefn");
Expand Down
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/gpkg/gdalgeopackagerasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,7 @@ CPLErr GDALGPKGMBTilesLikePseudoDataset::WriteTileInternal()
const CPLString osMemFileName(
VSIMemGenerateHiddenFilename("gpkg_write_tile"));
const char *pszDriverName = "PNG";
CPL_IGNORE_RET_VAL(pszDriverName); // Make CSA happy
bool bTileDriverSupports1Band = false;
bool bTileDriverSupports2Bands = false;
bool bTileDriverSupports4Bands = false;
Expand Down
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ OGRErr OGRGeoPackageTableLayer::FeatureBindParameters(
default:
{
const char *pszVal = "";
CPL_IGNORE_RET_VAL(pszVal); // Make CSA happy
int nValLengthBytes = -1;
sqlite3_destructor_type destructorType = SQLITE_TRANSIENT;
if (eType == OFTDate)
Expand Down
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/libkml/ogrlibkmldatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static void OGRLIBKMLPreProcessInput(std::string &oKml)
{
const char *pszStartTag = "<MultiPolygon>";
const char *pszEndTag = "";
CPL_IGNORE_RET_VAL(pszEndTag); // Make CSA happy
auto nNewPos = oKml.find(pszStartTag, nPos);
if (nNewPos != std::string::npos)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,7 @@ bool OGROpenFileGDBDataSource::UpdateFieldDomain(
asFields[iDefinition].String = CPLStrdup(osXML.c_str());

const char *pszNewTypeUUID = "";
CPL_IGNORE_RET_VAL(pszNewTypeUUID); // Make CSA happy
switch (domain->GetDomainType())
{
case OFDT_CODED:
Expand Down
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/openfilegdb/ogropenfilegdblayer_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ static CPLXMLNode *CreateXMLFieldDefinition(const OGRFieldDefn *poFieldDefn,
}
}
const char *pszFieldType = "";
CPL_IGNORE_RET_VAL(pszFieldType); // Make CSA happy
int nLength = 0;
switch (poGDBFieldDefn->GetType())
{
Expand Down
4 changes: 2 additions & 2 deletions ogr/ogrsf_frmts/pmtiles/pmtiles/pmtiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,15 @@ inline zxy tileid_to_zxy(uint64_t tileid) {
throw std::overflow_error("tile zoom exceeds 64-bit limit");
}

inline uint64_t zxy_to_tileid(uint8_t z, uint32_t x, uint32_t y) {
inline uint64_t zxy_to_tileid(uint32_t z, uint32_t x, uint32_t y) {
if (z > 31) {
throw std::overflow_error("tile zoom exceeds 64-bit limit");
}
if (x > (1U << z) - 1U || y > (1U << z) - 1U) {
throw std::overflow_error("tile x/y outside zoom level bounds");
}
uint64_t acc = 0;
for (uint8_t t_z = 0; t_z < z; t_z++) acc += (1LL << t_z) * (1LL << t_z);
for (uint32_t t_z = 0; t_z < z; t_z++) acc += (1LL << t_z) * (1LL << t_z);
int64_t n = 1LL << z;
int64_t rx, ry, s, d = 0;
int64_t tx = x;
Expand Down
8 changes: 5 additions & 3 deletions ogr/ogrsf_frmts/shape/shape2ogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ OGRGeometry *SHPReadOGRObject(SHPHandle hSHP, int iShape, SHPObject *psShape,
else
{
OGRPolygon **tabPolygons = new OGRPolygon *[psShape->nParts];
for (int iRing = 0; iRing < psShape->nParts; iRing++)
tabPolygons[0] = new OGRPolygon();
auto poExteriorRing = CreateLinearRing(psShape, 0, bHasZ, bHasM);
tabPolygons[0]->addRingDirectly(poExteriorRing);
for (int iRing = 1; iRing < psShape->nParts; iRing++)
{
tabPolygons[iRing] = new OGRPolygon();
tabPolygons[iRing]->addRingDirectly(
Expand Down Expand Up @@ -332,8 +335,7 @@ OGRGeometry *SHPReadOGRObject(SHPHandle hSHP, int iShape, SHPObject *psShape,
// Only inner rings
OGREnvelope sFirstEnvelope;
OGREnvelope sCurEnvelope;
auto poExteriorRing = tabPolygons[0]->getExteriorRing();
tabPolygons[0]->getEnvelope(&sFirstEnvelope);
poExteriorRing->getEnvelope(&sFirstEnvelope);
for (int iRing = 1; iRing < psShape->nParts; iRing++)
{
tabPolygons[iRing]->getEnvelope(&sCurEnvelope);
Expand Down
5 changes: 5 additions & 0 deletions port/cpl_quad_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,14 @@ static bool CPLQuadTreeRemoveInternal(QuadTreeNode *psNode, void *hFeature,
CPLQuadTreeNodeDestroy(psNode->apSubNode[i]);
if (i < psNode->nNumSubNodes - 1)
{
#ifdef CSA_BUILD
for (int j = 0; j < psNode->nNumSubNodes - 1 - i; ++j)
psNode->apSubNode[i + j] = psNode->apSubNode[i + j + 1];
#else
memmove(psNode->apSubNode + i, psNode->apSubNode + i + 1,
(psNode->nNumSubNodes - 1 - i) *
sizeof(QuadTreeNode *));
#endif
}
i--;
psNode->nNumSubNodes--;
Expand Down
29 changes: 12 additions & 17 deletions port/cpl_vsil_abstract_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,31 +303,26 @@ int VSIArchiveFilesystemHandler::FindFileInArchive(
/* CompactFilename() */
/************************************************************************/

static CPLString CompactFilename(const char *pszArchiveInFileNameIn)
static std::string CompactFilename(const char *pszArchiveInFileNameIn)
{
char *pszArchiveInFileName = CPLStrdup(pszArchiveInFileNameIn);
std::string osRet(pszArchiveInFileNameIn);

// Replace a/../b by b and foo/a/../b by foo/b.
while (true)
{
char *pszPrevDir = strstr(pszArchiveInFileName, "/../");
if (pszPrevDir == nullptr || pszPrevDir == pszArchiveInFileName)
size_t nSlashDotDot = osRet.find("/../");
if (nSlashDotDot == std::string::npos || nSlashDotDot == 0)
break;

char *pszPrevSlash = pszPrevDir - 1;
while (pszPrevSlash != pszArchiveInFileName && *pszPrevSlash != '/')
pszPrevSlash--;
if (pszPrevSlash == pszArchiveInFileName)
memmove(pszArchiveInFileName, pszPrevDir + 4,
strlen(pszPrevDir + 4) + 1);
size_t nPos = nSlashDotDot - 1;
while (nPos > 0 && osRet[nPos] != '/')
--nPos;
if (nPos == 0)
osRet = osRet.substr(nSlashDotDot + strlen("/../"));
else
memmove(pszPrevSlash + 1, pszPrevDir + 4,
strlen(pszPrevDir + 4) + 1);
osRet = osRet.substr(0, nPos + 1) +
osRet.substr(nSlashDotDot + strlen("/../"));
}

CPLString osFileInArchive = pszArchiveInFileName;
CPLFree(pszArchiveInFileName);
return osFileInArchive;
return osRet;
}

/************************************************************************/
Expand Down
22 changes: 12 additions & 10 deletions port/cpl_xml_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,21 @@ static void CPLFixPath(char *pszPath)
pszPath[i] = '/';
}

std::string osRet(pszPath);
while (true)
{
char *pszSlashDotDot = strstr(pszPath, "/../");
if (pszSlashDotDot == nullptr || pszSlashDotDot == pszPath)
return;
char *pszSlashBefore = pszSlashDotDot - 1;
while (pszSlashBefore > pszPath && *pszSlashBefore != '/')
pszSlashBefore--;
if (pszSlashBefore == pszPath)
return;
memmove(pszSlashBefore + 1, pszSlashDotDot + 4,
strlen(pszSlashDotDot + 4) + 1);
size_t nSlashDotDot = osRet.find("/../");
if (nSlashDotDot == std::string::npos || nSlashDotDot == 0)
break;
size_t nPos = nSlashDotDot - 1;
while (nPos > 0 && osRet[nPos] != '/')
--nPos;
if (nPos == 0)
break;
osRet = osRet.substr(0, nPos + 1) +
osRet.substr(nSlashDotDot + strlen("/../"));
}
memcpy(pszPath, osRet.data(), osRet.size() + 1);
}

#ifdef HAS_VALIDATION_BUG
Expand Down

0 comments on commit bbf5667

Please sign in to comment.