Skip to content

Commit

Permalink
Merge pull request #10723 from rouault/wfs_gml_strong_cxx_wflags
Browse files Browse the repository at this point in the history
[Lint] GML: enable STRONG_CXX_WFLAGS and fix related warnings
  • Loading branch information
rouault authored Sep 7, 2024
2 parents 4eeccba + d61da59 commit 113b677
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 254 deletions.
4 changes: 3 additions & 1 deletion ogr/ogrsf_frmts/gml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ add_gdal_driver(
gmlutils.cpp
ogrgmldatasource.cpp
parsexsd.h
BUILTIN)
BUILTIN
STRONG_CXX_WFLAGS
)
gdal_standard_includes(ogr_GML)

set(GDAL_DATA_FILES
Expand Down
13 changes: 7 additions & 6 deletions ogr/ogrsf_frmts/gml/gfstemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@
class GFSTemplateItem
{
private:
char *m_pszName;
int n_nItemCount;
int n_nGeomCount;
GFSTemplateItem *pNext;
char *m_pszName = nullptr;
int n_nItemCount = 0;
int n_nGeomCount = 0;
GFSTemplateItem *pNext = nullptr;

CPL_DISALLOW_COPY_ASSIGN(GFSTemplateItem)

public:
explicit GFSTemplateItem(const char *pszName);
Expand Down Expand Up @@ -340,8 +342,7 @@ int GFSTemplateList::GetClassCount()
/***************************************************/

GFSTemplateItem::GFSTemplateItem(const char *pszName)
: m_pszName(CPLStrdup(pszName)), n_nItemCount(0), n_nGeomCount(0),
pNext(nullptr)
: m_pszName(CPLStrdup(pszName))
{
}

Expand Down
38 changes: 17 additions & 21 deletions ogr/ogrsf_frmts/gml/gmlhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void GMLExpatHandler::DealWithError(OGRErr eErr)
if (eErr != OGRERR_NONE)
{
m_bStopParsing = true;
XML_StopParser(m_oParser, XML_FALSE);
XML_StopParser(m_oParser, static_cast<XML_Bool>(false));
if (eErr == OGRERR_NOT_ENOUGH_MEMORY)
CPLError(CE_Failure, CPLE_OutOfMemory, "Out of memory");
}
Expand Down Expand Up @@ -344,7 +344,7 @@ void XMLCALL GMLExpatHandler::dataHandlerCbk(void *pUserData, const char *data,
CPLError(CE_Failure, CPLE_AppDefined,
"File probably corrupted (million laugh pattern)");
pThis->m_bStopParsing = true;
XML_StopParser(pThis->m_oParser, XML_FALSE);
XML_StopParser(pThis->m_oParser, static_cast<XML_Bool>(false));
return;
}

Expand All @@ -357,7 +357,7 @@ void XMLCALL GMLExpatHandler::dataHandlerCbk(void *pUserData, const char *data,

const char *GMLExpatHandler::GetFID(void *attr)
{
const char **papszIter = (const char **)attr;
const char *const *papszIter = static_cast<const char *const *>(attr);
while (*papszIter)
{
if (strcmp(*papszIter, "fid") == 0 || strcmp(*papszIter, "gml:id") == 0)
Expand Down Expand Up @@ -404,7 +404,7 @@ CPLXMLNode *GMLExpatHandler::AddAttributes(CPLXMLNode *psNode, void *attr)
char *GMLExpatHandler::GetAttributeValue(void *attr,
const char *pszAttributeName)
{
const char **papszIter = (const char **)attr;
const char *const *papszIter = static_cast<const char *const *>(attr);
while (*papszIter)
{
if (strcmp(*papszIter, pszAttributeName) == 0)
Expand All @@ -425,7 +425,7 @@ char *GMLExpatHandler::GetAttributeValue(void *attr,
char *GMLExpatHandler::GetAttributeByIdx(void *attr, unsigned int idx,
char **ppszKey)
{
const char **papszIter = (const char **)attr;
const char *const *papszIter = static_cast<const char *const *>(attr);
if (papszIter[2 * idx] == nullptr)
{
*ppszKey = nullptr;
Expand Down Expand Up @@ -490,10 +490,12 @@ struct _GeometryNamesStruct
/* GMLHandlerSortGeometryElements() */
/************************************************************************/

static int GMLHandlerSortGeometryElements(const void *_pA, const void *_pB)
static int GMLHandlerSortGeometryElements(const void *pAIn, const void *pBIn)
{
GeometryNamesStruct *pA = (GeometryNamesStruct *)_pA;
GeometryNamesStruct *pB = (GeometryNamesStruct *)_pB;
const GeometryNamesStruct *pA =
static_cast<const GeometryNamesStruct *>(pAIn);
const GeometryNamesStruct *pB =
static_cast<const GeometryNamesStruct *>(pBIn);
CPLAssert(pA->nHash != pB->nHash);
if (pA->nHash < pB->nHash)
return -1;
Expand All @@ -506,15 +508,7 @@ static int GMLHandlerSortGeometryElements(const void *_pA, const void *_pB)
/************************************************************************/

GMLHandler::GMLHandler(GMLReader *poReader)
: m_pszCurField(nullptr), m_nCurFieldAlloc(0), m_nCurFieldLen(0),
m_bInCurField(false), m_nAttributeIndex(-1), m_nAttributeDepth(0),
m_pszGeometry(nullptr), m_nGeomAlloc(0), m_nGeomLen(0),
m_nGeometryDepth(0), m_bAlreadyFoundGeometry(false),
m_nGeometryPropertyIndex(0), m_nDepth(0), m_nDepthFeature(0),
m_inBoundedByDepth(0), m_pszCityGMLGenericAttrName(nullptr),
m_inCityGMLGenericAttrDepth(0), m_bReportHref(false), m_pszHref(nullptr),
m_pszUom(nullptr), m_pszValue(nullptr), m_pszKieli(nullptr),
pasGeometryNames(static_cast<GeometryNamesStruct *>(
: pasGeometryNames(static_cast<GeometryNamesStruct *>(
CPLMalloc(GML_GEOMETRY_TYPE_COUNT * sizeof(GeometryNamesStruct)))),
m_nSRSDimensionIfMissing(
atoi(CPLGetConfigOption("GML_SRS_DIMENSION_IF_MISSING", "0"))),
Expand Down Expand Up @@ -757,9 +751,10 @@ OGRErr GMLHandler::startElementGeometry(const char *pszName, int nLenName,
}

/* Create new XML Element */
CPLXMLNode *psCurNode = (CPLXMLNode *)CPLCalloc(sizeof(CPLXMLNode), 1);
CPLXMLNode *psCurNode =
static_cast<CPLXMLNode *>(CPLCalloc(sizeof(CPLXMLNode), 1));
psCurNode->eType = CXT_Element;
psCurNode->pszValue = (char *)CPLMalloc(nLenName + 1);
psCurNode->pszValue = static_cast<char *>(CPLMalloc(nLenName + 1));
memcpy(psCurNode->pszValue, pszName, nLenName + 1);

/* Attach element as the last child of its parent */
Expand Down Expand Up @@ -1482,7 +1477,7 @@ OGRErr GMLHandler::startElementDefault(const char *pszName, int nLenName,
/* WFS 2.0 GetFeature documents have a wfs:FeatureCollection */
/* as a wfs:member of the top wfs:FeatureCollection. We don't want this */
/* wfs:FeatureCollection to be recognized as a feature */
else if ((!(nLenName == (int)strlen("FeatureCollection") &&
else if ((!(nLenName == static_cast<int>(strlen("FeatureCollection")) &&
strcmp(pszName, "FeatureCollection") == 0)) &&
(nClassIndex = m_poReader->GetFeatureElementIndex(
pszName, nLenName, eAppSchemaType)) != -1)
Expand Down Expand Up @@ -1640,7 +1635,8 @@ OGRErr GMLHandler::endElementGeometry()
{
if (m_nGeomLen)
{
CPLXMLNode *psNode = (CPLXMLNode *)CPLCalloc(sizeof(CPLXMLNode), 1);
CPLXMLNode *psNode =
static_cast<CPLXMLNode *>(CPLCalloc(sizeof(CPLXMLNode), 1));
psNode->eType = CXT_Text;
psNode->pszValue = m_pszGeometry;

Expand Down
6 changes: 2 additions & 4 deletions ogr/ogrsf_frmts/gml/gmlpropertydefn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
/************************************************************************/

GMLPropertyDefn::GMLPropertyDefn(const char *pszName, const char *pszSrcElement)
: m_pszName(CPLStrdup(pszName)), m_eType(GMLPT_Untyped), m_nWidth(0),
m_nPrecision(0),
: m_pszName(CPLStrdup(pszName)),
m_pszSrcElement(pszSrcElement ? CPLStrdup(pszSrcElement) : nullptr),
m_nSrcElementLen(pszSrcElement ? strlen(pszSrcElement) : 0),
m_pszCondition(nullptr), m_bNullable(true)
m_nSrcElementLen(pszSrcElement ? strlen(pszSrcElement) : 0)
{
}

Expand Down
51 changes: 15 additions & 36 deletions ogr/ogrsf_frmts/gml/gmlreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,41 +115,18 @@ GMLReader::GMLReader(
bool bUseExpatParserPreferably,
bool bInvertAxisOrderIfLatLong, bool bConsiderEPSGAsURN,
GMLSwapCoordinatesEnum eSwapCoordinates, bool bGetSecondaryGeometryOption)
: m_bClassListLocked(false), m_nClassCount(0), m_papoClass(nullptr),
m_bLookForClassAtAnyLevel(false), m_pszFilename(nullptr),
#ifndef HAVE_XERCES
bUseExpatReader(true),
#else
bUseExpatReader(false),
#endif
m_poGMLHandler(nullptr),
#ifdef HAVE_XERCES
m_poSAXReader(nullptr), m_poCompleteFeature(nullptr),
m_GMLInputSource(nullptr), m_bEOF(false), m_bXercesInitialized(false),
#endif
#ifdef HAVE_EXPAT
oParser(nullptr), ppoFeatureTab(nullptr), nFeatureTabLength(0),
nFeatureTabIndex(0), nFeatureTabAlloc(0), pabyBuf(nullptr),
#endif
fpGML(nullptr), m_bReadStarted(false), m_poState(nullptr),
m_poRecycledState(nullptr), m_bStopParsing(false),
// Experimental. Not publicly advertized. See commented doc in
: // Experimental. Not publicly advertized. See commented doc in
// drv_gml.html
m_bFetchAllGeometries(
CPLTestBool(CPLGetConfigOption("GML_FETCH_ALL_GEOMETRIES", "NO"))),
m_bInvertAxisOrderIfLatLong(bInvertAxisOrderIfLatLong),
m_bConsiderEPSGAsURN(bConsiderEPSGAsURN),
m_eSwapCoordinates(eSwapCoordinates),
m_bGetSecondaryGeometryOption(bGetSecondaryGeometryOption),
m_pszGlobalSRSName(nullptr), m_bCanUseGlobalSRSName(false),
m_pszFilteredClassName(nullptr), m_nFilteredClassIndex(-1),
m_nHasSequentialLayers(-1),
// Must be in synced in OGR_G_CreateFromGML(), OGRGMLLayer::OGRGMLLayer(),
// and GMLReader::GMLReader().
m_bFaceHoleNegative(
CPLTestBool(CPLGetConfigOption("GML_FACE_HOLE_NEGATIVE", "NO"))),
m_bSetWidthFlag(true), m_bReportAllAttributes(false),
m_bIsWFSJointLayer(false), m_bEmptyAsNull(true)
CPLTestBool(CPLGetConfigOption("GML_FACE_HOLE_NEGATIVE", "NO")))
{
#ifndef HAVE_XERCES
#else
Expand Down Expand Up @@ -539,11 +516,12 @@ GMLFeature *GMLReader::NextFeatureExpat()
{
// Defer emission of the error message until we have to return
// nullptr
m_osErrorMessage.Printf("XML parsing of GML file failed : %s "
"at line %d, column %d",
XML_ErrorString(XML_GetErrorCode(oParser)),
(int)XML_GetCurrentLineNumber(oParser),
(int)XML_GetCurrentColumnNumber(oParser));
m_osErrorMessage.Printf(
"XML parsing of GML file failed : %s "
"at line %d, column %d",
XML_ErrorString(XML_GetErrorCode(oParser)),
static_cast<int>(XML_GetCurrentLineNumber(oParser)),
static_cast<int>(XML_GetCurrentColumnNumber(oParser)));
m_bStopParsing = true;
}
if (!m_bStopParsing)
Expand Down Expand Up @@ -717,19 +695,19 @@ int GMLReader::GetFeatureElementIndex(const char *pszElement,
}

// Begin of CSW SearchResults.
else if (nElementLength == (int)strlen("BriefRecord") &&
else if (nElementLength == static_cast<int>(strlen("BriefRecord")) &&
nLenLast == strlen("SearchResults") &&
strcmp(pszElement, "BriefRecord") == 0 &&
strcmp(pszLast, "SearchResults") == 0)
{
}
else if (nElementLength == (int)strlen("SummaryRecord") &&
else if (nElementLength == static_cast<int>(strlen("SummaryRecord")) &&
nLenLast == strlen("SearchResults") &&
strcmp(pszElement, "SummaryRecord") == 0 &&
strcmp(pszLast, "SearchResults") == 0)
{
}
else if (nElementLength == (int)strlen("Record") &&
else if (nElementLength == static_cast<int>(strlen("Record")) &&
nLenLast == strlen("SearchResults") &&
strcmp(pszElement, "Record") == 0 &&
strcmp(pszLast, "SearchResults") == 0)
Expand Down Expand Up @@ -779,7 +757,8 @@ int GMLReader::GetFeatureElementIndex(const char *pszElement,
// otherwise, find a class with the desired element name.
for (int i = 0; i < m_nClassCount; i++)
{
if (nElementLength == (int)m_papoClass[i]->GetElementNameLen() &&
if (nElementLength ==
static_cast<int>(m_papoClass[i]->GetElementNameLen()) &&
memcmp(pszElement, m_papoClass[i]->GetElementName(),
nElementLength) == 0)
return i;
Expand Down Expand Up @@ -908,8 +887,8 @@ void GMLReader::PopState()
if (nFeatureTabLength >= nFeatureTabAlloc)
{
nFeatureTabAlloc = nFeatureTabLength * 4 / 3 + 16;
ppoFeatureTab = (GMLFeature **)CPLRealloc(
ppoFeatureTab, sizeof(GMLFeature *) * (nFeatureTabAlloc));
ppoFeatureTab = static_cast<GMLFeature **>(CPLRealloc(
ppoFeatureTab, sizeof(GMLFeature *) * (nFeatureTabAlloc)));
}
ppoFeatureTab[nFeatureTabLength] = m_poState->m_poFeature;
nFeatureTabLength++;
Expand Down
37 changes: 23 additions & 14 deletions ogr/ogrsf_frmts/gml/gmlreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,19 @@ typedef struct

class CPL_DLL GMLPropertyDefn
{
char *m_pszName;
GMLPropertyType m_eType;
int m_nWidth;
int m_nPrecision;
char *m_pszSrcElement;
size_t m_nSrcElementLen;
char *m_pszCondition;
bool m_bNullable;
char *m_pszName = nullptr;
GMLPropertyType m_eType = GMLPT_Untyped;
int m_nWidth = 0;
int m_nPrecision = 0;
char *m_pszSrcElement = nullptr;
size_t m_nSrcElementLen = 0;
char *m_pszCondition = nullptr;
bool m_bNullable = true;
bool m_bUnique = false;
std::string m_osDocumentation{};

CPL_DISALLOW_COPY_ASSIGN(GMLPropertyDefn)

public:
explicit GMLPropertyDefn(const char *pszName,
const char *pszSrcElement = nullptr);
Expand Down Expand Up @@ -196,15 +198,17 @@ class CPL_DLL GMLPropertyDefn

class CPL_DLL GMLGeometryPropertyDefn
{
char *m_pszName;
char *m_pszSrcElement;
char *m_pszName = nullptr;
char *m_pszSrcElement = nullptr;
OGRwkbGeometryType m_nGeometryType = wkbUnknown;
int m_nAttributeIndex;
bool m_bNullable;
const int m_nAttributeIndex = -1;
const bool m_bNullable = true;
bool m_bSRSNameConsistent = true;
std::string m_osSRSName{};
OGRGeomCoordinatePrecision m_oCoordPrecision{};

CPL_DISALLOW_COPY_ASSIGN(GMLGeometryPropertyDefn)

public:
GMLGeometryPropertyDefn(const char *pszName, const char *pszSrcElement,
OGRwkbGeometryType nType, int nAttributeIndex,
Expand Down Expand Up @@ -265,6 +269,7 @@ class CPL_DLL GMLGeometryPropertyDefn
/************************************************************************/
/* GMLFeatureClass */
/************************************************************************/

class CPL_DLL GMLFeatureClass
{
char *m_pszName;
Expand All @@ -273,8 +278,8 @@ class CPL_DLL GMLFeatureClass
int n_nElementNameLen;
int m_nPropertyCount;
GMLPropertyDefn **m_papoProperty;
std::map<CPLString, int> m_oMapPropertyNameToIndex;
std::map<CPLString, int> m_oMapPropertySrcElementToIndex;
std::map<CPLString, int> m_oMapPropertyNameToIndex{};
std::map<CPLString, int> m_oMapPropertySrcElementToIndex{};

int m_nGeometryPropertyCount;
GMLGeometryPropertyDefn **m_papoGeometryProperty;
Expand All @@ -297,6 +302,8 @@ class CPL_DLL GMLFeatureClass
bool m_bIsConsistentSingleGeomElemPath = true;
std::string m_osSingleGeomElemPath{};

CPL_DISALLOW_COPY_ASSIGN(GMLFeatureClass)

public:
explicit GMLFeatureClass(const char *pszName = "");
~GMLFeatureClass();
Expand Down Expand Up @@ -419,6 +426,8 @@ class CPL_DLL GMLFeature

CPLXMLNode *m_psBoundedByGeometry = nullptr;

CPL_DISALLOW_COPY_ASSIGN(GMLFeature)

public:
explicit GMLFeature(GMLFeatureClass *);
~GMLFeature();
Expand Down
Loading

0 comments on commit 113b677

Please sign in to comment.