Various tunings to make Clang Static Analyzer 18 happy
This commit is contained in:
parent
971762d900
commit
2293caee7f
|
@ -1463,7 +1463,8 @@ 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) +
|
||||
|
@ -1471,7 +1472,8 @@ CPLErr GDALPansharpenOperation::ProcessRegion(int nXOff, int nYOff, int nXSize,
|
|||
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) +
|
||||
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "cpl_multiproc.h"
|
||||
#include "ograpispy.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -417,7 +417,7 @@ 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");
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ inline uint64_t zxy_to_tileid(uint8_t z, uint32_t x, uint32_t y) {
|
|||
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;
|
||||
|
|
|
@ -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(
|
||||
|
@ -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);
|
||||
|
|
|
@ -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--;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue