From 318b518a4dc22ebc0888d256642e398ec92fa222 Mon Sep 17 00:00:00 2001 From: Kurt Schwehr Date: Wed, 17 Aug 2016 16:27:10 +0000 Subject: [PATCH] Combine pointer definition and initialization in ogr. Also: - Localize vars - if(a) b = c; else b = d; -> b = a ? b : d; - Fix formatting - Fit to 80 cols - /* */ -> // - Add const to local vars git-svn-id: https://svn.osgeo.org/gdal/trunk@35136 f0d54148-0727-0410-94bb-9a71ac55c965 --- gdal/ogr/ogr_geocoding.cpp | 3 +- gdal/ogr/ogr_srs_pci.cpp | 11 +-- gdal/ogr/ogr_srs_proj4.cpp | 2 +- gdal/ogr/ogr_srs_validate.cpp | 9 +-- gdal/ogr/ogr_srs_xml.cpp | 69 ++++++---------- gdal/ogr/ogrcompoundcurve.cpp | 16 ++-- gdal/ogr/ogrct.cpp | 26 +++--- gdal/ogr/ogrcurvecollection.cpp | 8 +- gdal/ogr/ogrcurvepolygon.cpp | 4 +- gdal/ogr/ogrfeature.cpp | 19 ++--- gdal/ogr/ogrfeaturedefn.cpp | 4 +- gdal/ogr/ogrfeaturequery.cpp | 30 +++---- gdal/ogr/ogrfeaturestyle.cpp | 123 ++++++++++++----------------- gdal/ogr/ogrgeometry.cpp | 48 +++++------ gdal/ogr/ogrgeometrycollection.cpp | 10 +-- gdal/ogr/ogrgeometryfactory.cpp | 29 +++---- gdal/ogr/ogrlinearring.cpp | 4 +- gdal/ogr/ogrlinestring.cpp | 11 +-- gdal/ogr/ogrmultisurface.cpp | 3 +- gdal/ogr/ogrpgeogeometry.cpp | 20 ++--- gdal/ogr/ogrspatialreference.cpp | 25 +++--- gdal/ogr/swq.cpp | 9 +-- gdal/ogr/swq_expr_node.cpp | 4 +- gdal/ogr/swq_op_general.cpp | 2 +- 24 files changed, 187 insertions(+), 302 deletions(-) diff --git a/gdal/ogr/ogr_geocoding.cpp b/gdal/ogr/ogr_geocoding.cpp index ebd598146eb9..294001c35d4e 100644 --- a/gdal/ogr/ogr_geocoding.cpp +++ b/gdal/ogr/ogr_geocoding.cpp @@ -1284,8 +1284,6 @@ static OGRLayerH OGRGeocodeCommon( OGRGeocodingSessionH hSession, pszCachedResult = OGRGeocodeGetFromCache(hSession, osURL); if( pszCachedResult == NULL ) { - CPLHTTPResult* psResult; - double* pdfLastQueryTime = NULL; if( EQUAL(hSession->pszGeocodingService, "OSM_NOMINATIM") ) pdfLastQueryTime = &dfLastQueryTimeStampOSMNominatim; @@ -1302,6 +1300,7 @@ static OGRLayerH OGRGeocodeCommon( OGRGeocodingSessionH hSession, char** papszHTTPOptions = CSLAddNameValue(NULL, "HEADERS", osHeaders.c_str()); + CPLHTTPResult* psResult = NULL; if( pdfLastQueryTime != NULL ) { CPLMutexHolderD(&hMutex); diff --git a/gdal/ogr/ogr_srs_pci.cpp b/gdal/ogr/ogr_srs_pci.cpp index 0d5f3a6720d8..73bf11df0074 100644 --- a/gdal/ogr/ogr_srs_pci.cpp +++ b/gdal/ogr/ogr_srs_pci.cpp @@ -219,11 +219,10 @@ OGRErr OGRSpatialReference::importFromPCI( const char *pszProj, /* D-02 or D109. */ /* -------------------------------------------------------------------- */ char szEarthModel[5]; - const char *pszEM; int bIsNAD27 = FALSE; strcpy( szEarthModel, "" ); - pszEM = pszProj + strlen(pszProj) - 1; + const char *pszEM = pszProj + strlen(pszProj) - 1; while( pszEM != pszProj ) { if( *pszEM == 'e' || *pszEM == 'E' || *pszEM == 'd' || *pszEM == 'D' ) @@ -1304,12 +1303,8 @@ OGRErr OGRSpatialReference::exportToPCI( char **ppszProj, char **ppszUnits, /* -------------------------------------------------------------------- */ /* Translate the linear units. */ /* -------------------------------------------------------------------- */ - const char *pszUnits; - - if( STARTS_WITH_CI(szProj, "LONG/LAT") ) - pszUnits = "DEGREE"; - else - pszUnits = "METRE"; + const char *pszUnits = + STARTS_WITH_CI(szProj, "LONG/LAT") ? "DEGREE" : "METRE"; /* -------------------------------------------------------------------- */ /* Report results. */ diff --git a/gdal/ogr/ogr_srs_proj4.cpp b/gdal/ogr/ogr_srs_proj4.cpp index a9d4dd130283..8e1d690ecfde 100644 --- a/gdal/ogr/ogr_srs_proj4.cpp +++ b/gdal/ogr/ogr_srs_proj4.cpp @@ -1376,7 +1376,7 @@ OGRErr OGRSpatialReference::importFromProj4( const char * pszProj4 ) /* Preserve authority (for example IGNF) */ /* -------------------------------------------------------------------- */ const char *pszINIT = CSLFetchNameValue(papszNV,"init"); - const char *pszColumn; + const char *pszColumn = NULL; if( pszINIT != NULL && (pszColumn = strchr(pszINIT, ':')) != NULL && GetRoot()->FindChild( "AUTHORITY" ) < 0 ) { diff --git a/gdal/ogr/ogr_srs_validate.cpp b/gdal/ogr/ogr_srs_validate.cpp index f6af794c6495..d89fc7775b12 100644 --- a/gdal/ogr/ogr_srs_validate.cpp +++ b/gdal/ogr/ogr_srs_validate.cpp @@ -1229,12 +1229,11 @@ OGRErr OGRSpatialReference::ValidateProjection(OGR_SRSNode *poRoot) /* -------------------------------------------------------------------- */ /* Find the matching group in the proj and parms table. */ /* -------------------------------------------------------------------- */ - const char *pszProjection; - int iOffset; + const char *pszProjection = + poPROJCS->GetNode("PROJECTION")->GetChild(0)->GetValue(); - pszProjection = poPROJCS->GetNode("PROJECTION")->GetChild(0)->GetValue(); - - for( iOffset = 0; + int iOffset = 0; // Used after for. + for( ; papszProjWithParms[iOffset] != NULL && !EQUAL(papszProjWithParms[iOffset],pszProjection); ) { diff --git a/gdal/ogr/ogr_srs_xml.cpp b/gdal/ogr/ogr_srs_xml.cpp index 847b04c73e3e..0384ca4e6fc0 100644 --- a/gdal/ogr/ogr_srs_xml.cpp +++ b/gdal/ogr/ogr_srs_xml.cpp @@ -237,13 +237,12 @@ static void addGMLId( CPLXMLNode *psParent ) static CPLMutex *hGMLIdMutex = NULL; CPLMutexHolderD( &hGMLIdMutex ); - /* CPLXMLNode *psId; */ static int nNextGMLId = 1; char szIdText[40]; snprintf( szIdText, sizeof(szIdText), "ogrcrs%d", nNextGMLId++ ); - /* psId = */ + // CPLXMLNode *psId = CPLCreateXMLNode( CPLCreateXMLNode( psParent, CXT_Attribute, "gml:id" ), CXT_Text, szIdText ); @@ -260,15 +259,13 @@ static CPLXMLNode *exportAuthorityToXML( const OGR_SRSNode *poAuthParent, int bUseSubName = TRUE ) { - const OGR_SRSNode *poAuthority; - /* -------------------------------------------------------------------- */ /* Get authority node from parent. */ /* -------------------------------------------------------------------- */ if( poAuthParent->FindChild( "AUTHORITY" ) == -1 ) return NULL; - poAuthority = poAuthParent->GetChild( + const OGR_SRSNode *poAuthority = poAuthParent->GetChild( poAuthParent->FindChild( "AUTHORITY" )); /* -------------------------------------------------------------------- */ @@ -303,12 +300,9 @@ static void addProjArg( const OGRSpatialReference *poSRS, CPLXMLNode *psBase, /* -------------------------------------------------------------------- */ /* Handle the UOM. */ /* -------------------------------------------------------------------- */ - const char *pszUOMValue; - - if( EQUAL(pszMeasureType,"Angular") ) - pszUOMValue = "urn:ogc:def:uom:EPSG::9102"; - else - pszUOMValue = "urn:ogc:def:uom:EPSG::9001"; + const char *pszUOMValue = EQUAL(pszMeasureType, "Angular") + ? "urn:ogc:def:uom:EPSG::9102" + : "urn:ogc:def:uom:EPSG::9001"; CPLXMLNode *psValue = CPLCreateXMLNode( psNode, CXT_Element, "gml:value" ); @@ -758,7 +752,6 @@ static void importXMLUnits( CPLXMLNode *psSrcXML, const char *pszClass, { const char *pszUnitName, *pszUnitsPer; OGR_SRSNode *poNode = poSRS->GetAttrNode( pszTarget ); - OGR_SRSNode *poUnits; CPLAssert( EQUAL(pszClass,"AngularUnit") || EQUAL(pszClass,"LinearUnit") ); @@ -788,6 +781,7 @@ static void importXMLUnits( CPLXMLNode *psSrcXML, const char *pszClass, goto DefaultTarget; } + OGR_SRSNode *poUnits = NULL; if( poNode->FindChild("UNIT") != -1 ) { poUnits = poNode->GetChild( poNode->FindChild( "UNIT" ) ); @@ -963,9 +957,7 @@ static double getProjectionParm( CPLXMLNode *psRootNode, double dfDefault ) { - CPLXMLNode *psUsesParameter; - - for( psUsesParameter = psRootNode->psChild; + for( CPLXMLNode *psUsesParameter = psRootNode->psChild; psUsesParameter != NULL; psUsesParameter = psUsesParameter->psNext ) { @@ -1005,18 +997,15 @@ static double getNormalizedValue( CPLXMLNode *psNode, const char *pszPath, double dfDefault ) { - CPLXMLNode *psTargetNode; - CPLXMLNode *psValueNode; - - if( pszPath == NULL || strlen(pszPath) == 0 ) - psTargetNode = psNode; - else - psTargetNode = CPLGetXMLNode( psNode, pszPath ); + CPLXMLNode *psTargetNode = pszPath == NULL || strlen(pszPath) == 0 + ? psNode + : CPLGetXMLNode( psNode, pszPath ); if( psTargetNode == NULL ) return dfDefault; - for( psValueNode = psTargetNode->psChild; + CPLXMLNode *psValueNode = psTargetNode->psChild; // Used after for. + for( ; psValueNode != NULL && psValueNode->eType != CXT_Text; psValueNode = psValueNode->psNext ) {} @@ -1049,9 +1038,8 @@ static OGRErr importGeogCSFromXML( OGRSpatialReference *poSRS, /* If we don't seem to have a detailed coordinate system */ /* definition, check if we can define based on an EPSG code. */ /* -------------------------------------------------------------------- */ - CPLXMLNode *psDatum; - - psDatum = CPLGetXMLNode( psCRS, "usesGeodeticDatum.GeodeticDatum" ); + CPLXMLNode *psDatum = + CPLGetXMLNode( psCRS, "usesGeodeticDatum.GeodeticDatum" ); if( psDatum == NULL ) { @@ -1078,9 +1066,7 @@ static OGRErr importGeogCSFromXML( OGRSpatialReference *poSRS, /* -------------------------------------------------------------------- */ /* Get ellipsoid information. */ /* -------------------------------------------------------------------- */ - CPLXMLNode *psE; - - psE = CPLGetXMLNode( psDatum, "usesEllipsoid.Ellipsoid" ); + CPLXMLNode *psE = CPLGetXMLNode( psDatum, "usesEllipsoid.Ellipsoid" ); pszEllipsoidName = CPLGetXMLValue( psE, "ellipsoidName", "Unnamed Ellipsoid" ); @@ -1101,9 +1087,8 @@ static OGRErr importGeogCSFromXML( OGRSpatialReference *poSRS, /* -------------------------------------------------------------------- */ /* Get the prime meridian. */ /* -------------------------------------------------------------------- */ - CPLXMLNode *psPM; - - psPM = CPLGetXMLNode( psDatum, "usesPrimeMeridian.PrimeMeridian" ); + CPLXMLNode *psPM = + CPLGetXMLNode( psDatum, "usesPrimeMeridian.PrimeMeridian" ); if( psPM == NULL ) { pszPMName = "Greenwich"; @@ -1130,10 +1115,9 @@ static OGRErr importGeogCSFromXML( OGRSpatialReference *poSRS, /* at this time. */ /* -------------------------------------------------------------------- */ #ifdef notdef - CPLXMLNode *psAxis; - - psAxis = CPLGetXMLNode( psGeo2DCRS, - "EllipsoidalCoordinateSystem.CoordinateAxis" ); + CPLXMLNode *psAxis = + CPLGetXMLNode( psGeo2DCRS, + "EllipsoidalCoordinateSystem.CoordinateAxis" ); importXMLUnits( psAxis, "AngularUnit", poSRS, "GEOGCS" ); #endif @@ -1161,9 +1145,6 @@ static OGRErr importProjCSFromXML( OGRSpatialReference *poSRS, CPLXMLNode *psCRS ) { - CPLXMLNode *psSubXML; - OGRErr eErr; - /* -------------------------------------------------------------------- */ /* Setup the PROJCS node with a name. */ /* -------------------------------------------------------------------- */ @@ -1189,7 +1170,8 @@ static OGRErr importProjCSFromXML( OGRSpatialReference *poSRS, /* Try to set the GEOGCS info. */ /* -------------------------------------------------------------------- */ - psSubXML = CPLGetXMLNode( psCRS, "baseCRS.GeographicCRS" ); + OGRErr eErr = OGRERR_NONE; + CPLXMLNode *psSubXML = CPLGetXMLNode( psCRS, "baseCRS.GeographicCRS" ); if( psSubXML != NULL ) { eErr = importGeogCSFromXML( poSRS, psSubXML ); @@ -1267,15 +1249,12 @@ static OGRErr importProjCSFromXML( OGRSpatialReference *poSRS, OGRErr OGRSpatialReference::importFromXML( const char *pszXML ) { - CPLXMLNode *psTree; - OGRErr eErr = OGRERR_UNSUPPORTED_SRS; - this->Clear(); /* -------------------------------------------------------------------- */ /* Parse the XML. */ /* -------------------------------------------------------------------- */ - psTree = CPLParseXMLString( pszXML ); + CPLXMLNode *psTree = CPLParseXMLString( pszXML ); if( psTree == NULL ) return OGRERR_CORRUPT_DATA; @@ -1287,6 +1266,8 @@ OGRErr OGRSpatialReference::importFromXML( const char *pszXML ) /* root elements as there is sometimes prefix stuff like */ /* . */ /* -------------------------------------------------------------------- */ + OGRErr eErr = OGRERR_UNSUPPORTED_SRS; + for( CPLXMLNode* psNode = psTree; psNode != NULL; psNode = psNode->psNext ) { if( EQUAL(psNode->pszValue,"GeographicCRS") ) diff --git a/gdal/ogr/ogrcompoundcurve.cpp b/gdal/ogr/ogrcompoundcurve.cpp index d88b62eb46c9..b3afd54a4470 100644 --- a/gdal/ogr/ogrcompoundcurve.cpp +++ b/gdal/ogr/ogrcompoundcurve.cpp @@ -215,9 +215,7 @@ OGRErr OGRCompoundCurve::exportToWkt( char ** ppszDstText, OGRGeometry *OGRCompoundCurve::clone() const { - OGRCompoundCurve *poNewCC; - - poNewCC = new OGRCompoundCurve; + OGRCompoundCurve *poNewCC = new OGRCompoundCurve; poNewCC->assignSpatialReference( getSpatialReference() ); poNewCC->flags = flags; @@ -341,11 +339,9 @@ OGRLineString* OGRCompoundCurve::CurveToLineInternal(double dfMaxAngleStepSizeDe const char* const* papszOptions, int bIsLinearRing) const { - OGRLineString* poLine; - if( bIsLinearRing ) - poLine = new OGRLinearRing(); - else - poLine = new OGRLineString(); + OGRLineString* const poLine = bIsLinearRing + ? new OGRLinearRing() + : new OGRLineString(); poLine->assignSpatialReference(getSpatialReference()); for( int iGeom = 0; iGeom < oCC.nCurveCount; iGeom++ ) { @@ -682,8 +678,8 @@ class OGRCompoundCurvePointIterator: public OGRPointIterator public: OGRCompoundCurvePointIterator(const OGRCompoundCurve* poCCIn) : - poCC(poCCIn), iCurCurve(0), poCurveIter(NULL) {} - ~OGRCompoundCurvePointIterator() { delete poCurveIter; } + poCC(poCCIn), iCurCurve(0), poCurveIter(NULL) {} + virtual ~OGRCompoundCurvePointIterator() { delete poCurveIter; } virtual OGRBoolean getNextPoint(OGRPoint* p); }; diff --git a/gdal/ogr/ogrct.cpp b/gdal/ogr/ogrct.cpp index 32a1403972e0..235663dfe145 100644 --- a/gdal/ogr/ogrct.cpp +++ b/gdal/ogr/ogrct.cpp @@ -192,14 +192,13 @@ static bool LoadProjLibrary_unlocked() { static bool bTriedToLoad = false; - const char *pszLibName; if( bTriedToLoad ) - return( pfn_pj_transform != NULL ); + return pfn_pj_transform != NULL; bTriedToLoad = true; - pszLibName = GetProjLibraryName(); + const char *pszLibName = GetProjLibraryName(); #ifdef PROJ_STATIC pfn_pj_init = pj_init; @@ -423,8 +422,6 @@ OGRCreateCoordinateTransformation( OGRSpatialReference *poSource, OGRSpatialReference *poTarget ) { - OGRProj4CT *poCT; - if( pfn_pj_init == NULL && !LoadProjLibrary() ) { CPLError( CE_Failure, CPLE_NotSupported, @@ -434,7 +431,7 @@ OGRCreateCoordinateTransformation( OGRSpatialReference *poSource, return NULL; } - poCT = new OGRProj4CT(); + OGRProj4CT *poCT = new OGRProj4CT(); if( !poCT->Initialize( poSource, poTarget ) ) { @@ -636,8 +633,6 @@ int OGRProj4CT::InitializeNoLock( OGRSpatialReference * poSourceIn, /* -------------------------------------------------------------------- */ /* Preliminary logic to setup wrapping. */ /* -------------------------------------------------------------------- */ - const char *pszCENTER_LONG; - if( CPLGetConfigOption( "CENTER_LONG", NULL ) != NULL ) { bSourceWrap = true; @@ -647,7 +642,8 @@ int OGRProj4CT::InitializeNoLock( OGRSpatialReference * poSourceIn, CPLDebug( "OGRCT", "Wrap at %g.", dfSourceWrapLong ); } - pszCENTER_LONG = poSRSSource->GetExtension( "GEOGCS", "CENTER_LONG" ); + const char *pszCENTER_LONG = + poSRSSource->GetExtension( "GEOGCS", "CENTER_LONG" ); if( pszCENTER_LONG != NULL ) { dfSourceWrapLong = CPLAtof(pszCENTER_LONG); @@ -736,17 +732,18 @@ int OGRProj4CT::InitializeNoLock( OGRSpatialReference * poSourceIn, strstr(pszDstProj4Defn, "+towgs84") == NULL ) { char* pszDst = strstr(pszSrcProj4Defn, "+towgs84=0,0,0,0,0,0,0 "); - char* pszSrc; if( pszDst != NULL ) { - pszSrc = pszDst + strlen("+towgs84=0,0,0,0,0,0,0 "); + char *pszSrc = pszDst + strlen("+towgs84=0,0,0,0,0,0,0 "); memmove(pszDst, pszSrc, strlen(pszSrc)+1); } else + { memcpy(strstr(pszSrcProj4Defn, "+datum=WGS84"), "+ellps", 6); + } pszDst = strstr(pszDstProj4Defn, "+nadgrids=@null "); - pszSrc = pszDst + strlen("+nadgrids=@null "); + char *pszSrc = pszDst + strlen("+nadgrids=@null "); memmove(pszDst, pszSrc, strlen(pszSrc)+1); pszDst = strstr(pszDstProj4Defn, "+wktext "); @@ -767,17 +764,16 @@ int OGRProj4CT::InitializeNoLock( OGRSpatialReference * poSourceIn, strstr(pszSrcProj4Defn, "+towgs84") == NULL ) { char* pszDst = strstr(pszDstProj4Defn, "+towgs84=0,0,0,0,0,0,0 "); - char* pszSrc; if( pszDst != NULL) { - pszSrc = pszDst + strlen("+towgs84=0,0,0,0,0,0,0 "); + char* pszSrc = pszDst + strlen("+towgs84=0,0,0,0,0,0,0 "); memmove(pszDst, pszSrc, strlen(pszSrc)+1); } else memcpy(strstr(pszDstProj4Defn, "+datum=WGS84"), "+ellps", 6); pszDst = strstr(pszSrcProj4Defn, "+nadgrids=@null "); - pszSrc = pszDst + strlen("+nadgrids=@null "); + char* pszSrc = pszDst + strlen("+nadgrids=@null "); memmove(pszDst, pszSrc, strlen(pszSrc)+1); pszDst = strstr(pszSrcProj4Defn, "+wktext "); diff --git a/gdal/ogr/ogrcurvecollection.cpp b/gdal/ogr/ogrcurvecollection.cpp index ed8c4434330f..2bb054e815e6 100644 --- a/gdal/ogr/ogrcurvecollection.cpp +++ b/gdal/ogr/ogrcurvecollection.cpp @@ -285,10 +285,6 @@ OGRErr OGRCurveCollection::exportToWkt( const OGRGeometry* poGeom, char ** ppszDstText ) const { - char **papszGeoms; - size_t nCumulativeLength = 0; - OGRErr eErr; - if( nCurveCount == 0 ) { CPLString osEmpty; @@ -307,7 +303,9 @@ OGRErr OGRCurveCollection::exportToWkt( const OGRGeometry* poGeom, /* -------------------------------------------------------------------- */ /* Build a list of strings containing the stuff for each Geom. */ /* -------------------------------------------------------------------- */ - papszGeoms = (char **) CPLCalloc(sizeof(char *),nCurveCount); + char **papszGeoms = (char **) CPLCalloc(sizeof(char *),nCurveCount); + OGRErr eErr = OGRERR_NONE; + size_t nCumulativeLength = 0; for( int iGeom = 0; iGeom < nCurveCount; iGeom++ ) { diff --git a/gdal/ogr/ogrcurvepolygon.cpp b/gdal/ogr/ogrcurvepolygon.cpp index 9ab7f3a85571..225d151c9412 100644 --- a/gdal/ogr/ogrcurvepolygon.cpp +++ b/gdal/ogr/ogrcurvepolygon.cpp @@ -105,9 +105,7 @@ OGRCurvePolygon& OGRCurvePolygon::operator=( const OGRCurvePolygon& other ) OGRGeometry *OGRCurvePolygon::clone() const { - OGRCurvePolygon *poNewPolygon; - - poNewPolygon = (OGRCurvePolygon*) + OGRCurvePolygon *poNewPolygon = (OGRCurvePolygon*) OGRGeometryFactory::createGeometry(getGeometryType()); if( poNewPolygon == NULL ) return NULL; diff --git a/gdal/ogr/ogrfeature.cpp b/gdal/ogr/ogrfeature.cpp index 0075f372a191..ff5a4ee5ed22 100644 --- a/gdal/ogr/ogrfeature.cpp +++ b/gdal/ogr/ogrfeature.cpp @@ -2135,12 +2135,12 @@ const char *OGRFeature::GetFieldAsString( int iField ) else if( eType == OFTBinary ) { int nCount = pauFields[iField].Binary.nCount; - char *pszHex; if( nCount > (int) sizeof(szTempBuffer) / 2 - 4 ) nCount = sizeof(szTempBuffer) / 2 - 4; - pszHex = CPLBinaryToHex( nCount, pauFields[iField].Binary.paData ); + char *pszHex = + CPLBinaryToHex( nCount, pauFields[iField].Binary.paData ); memcpy( szTempBuffer, pszHex, 2 * nCount ); szTempBuffer[nCount*2] = '\0'; @@ -4899,10 +4899,7 @@ OGRErr OGRFeature::SetFrom( OGRFeature * poSrcFeature, int bForgiving ) /* -------------------------------------------------------------------- */ /* Retrieve the field ids by name. */ /* -------------------------------------------------------------------- */ - int *panMap; - OGRErr eErr; - - panMap = static_cast( + int *panMap = static_cast( VSI_MALLOC_VERBOSE( sizeof(int) * poSrcFeature->GetFieldCount() ) ); if( panMap == NULL ) return OGRERR_FAILURE; @@ -4923,7 +4920,7 @@ OGRErr OGRFeature::SetFrom( OGRFeature * poSrcFeature, int bForgiving ) } } - eErr = SetFrom( poSrcFeature, panMap, bForgiving ); + const OGRErr eErr = SetFrom( poSrcFeature, panMap, bForgiving ); VSIFree(panMap); @@ -5459,12 +5456,10 @@ OGRErr OGRFeature::RemapFields( OGRFeatureDefn *poNewDefn, int *panRemapSource ) { - OGRField *pauNewFields; - if( poNewDefn == NULL ) poNewDefn = poDefn; - pauNewFields = static_cast( + OGRField *pauNewFields = static_cast( CPLCalloc( poNewDefn->GetFieldCount(), sizeof(OGRField) ) ); for( int iDstField = 0; iDstField < poDefn->GetFieldCount(); iDstField++ ) @@ -5510,12 +5505,10 @@ OGRErr OGRFeature::RemapGeomFields( OGRFeatureDefn *poNewDefn, int *panRemapSource ) { - OGRGeometry** papoNewGeomFields; - if( poNewDefn == NULL ) poNewDefn = poDefn; - papoNewGeomFields = static_cast( + OGRGeometry** papoNewGeomFields = static_cast( CPLCalloc( poNewDefn->GetGeomFieldCount(), sizeof(OGRGeometry*) ) ); for( int iDstField = 0; diff --git a/gdal/ogr/ogrfeaturedefn.cpp b/gdal/ogr/ogrfeaturedefn.cpp index cba6d0b8eaa8..acae6f8f563a 100644 --- a/gdal/ogr/ogrfeaturedefn.cpp +++ b/gdal/ogr/ogrfeaturedefn.cpp @@ -192,9 +192,7 @@ void OGR_FD_Release( OGRFeatureDefnH hDefn ) OGRFeatureDefn *OGRFeatureDefn::Clone() { - OGRFeatureDefn *poCopy; - - poCopy = new OGRFeatureDefn( GetName() ); + OGRFeatureDefn *poCopy = new OGRFeatureDefn( GetName() ); GetFieldCount(); for( int i = 0; i < nFieldCount; i++ ) diff --git a/gdal/ogr/ogrfeaturequery.cpp b/gdal/ogr/ogrfeaturequery.cpp index 06ceb46e9d22..ae8d6b5ff8e8 100644 --- a/gdal/ogr/ogrfeaturequery.cpp +++ b/gdal/ogr/ogrfeaturequery.cpp @@ -90,14 +90,12 @@ OGRErr OGRFeatureQuery::Compile( OGRFeatureDefn *poDefn, /* -------------------------------------------------------------------- */ /* Build list of fields. */ /* -------------------------------------------------------------------- */ - char **papszFieldNames; - swq_field_type *paeFieldTypes; int nFieldCount = poDefn->GetFieldCount() + SPECIAL_FIELD_COUNT + poDefn->GetGeomFieldCount(); - papszFieldNames = (char **) + char **papszFieldNames = (char **) CPLMalloc(sizeof(char *) * nFieldCount ); - paeFieldTypes = (swq_field_type *) + swq_field_type *paeFieldTypes = (swq_field_type *) CPLMalloc(sizeof(swq_field_type) * nFieldCount ); for( int iField = 0; iField < poDefn->GetFieldCount(); iField++ ) @@ -248,10 +246,9 @@ int OGRFeatureQuery::Evaluate( OGRFeature *poFeature ) if( pSWQExpr == NULL ) return FALSE; - swq_expr_node *poResult; - - poResult = ((swq_expr_node *) pSWQExpr)->Evaluate( OGRFeatureFetcher, - (void *) poFeature ); + swq_expr_node *poResult = + ((swq_expr_node *) pSWQExpr)->Evaluate( OGRFeatureFetcher, + (void *) poFeature ); if( poResult == NULL ) return FALSE; @@ -287,8 +284,6 @@ int OGRFeatureQuery::CanUseIndex( OGRLayer *poLayer ) int OGRFeatureQuery::CanUseIndex( swq_expr_node *psExpr, OGRLayer *poLayer ) { - OGRAttrIndex *poIndex; - /* -------------------------------------------------------------------- */ /* Does the expression meet our requirements? */ /* -------------------------------------------------------------------- */ @@ -314,7 +309,8 @@ int OGRFeatureQuery::CanUseIndex( swq_expr_node *psExpr, || poValue->eNodeType != SNT_CONSTANT ) return FALSE; - poIndex = poLayer->GetIndex()->GetFieldIndex( poColumn->field_index ); + OGRAttrIndex *poIndex = + poLayer->GetIndex()->GetFieldIndex( poColumn->field_index ); if( poIndex == NULL ) return FALSE; @@ -497,8 +493,6 @@ GIntBig *OGRFeatureQuery::EvaluateAgainstIndices( swq_expr_node *psExpr, OGRLayer *poLayer, GIntBig& nFIDCount ) { - OGRAttrIndex *poIndex; - /* -------------------------------------------------------------------- */ /* Does the expression meet our requirements? */ /* -------------------------------------------------------------------- */ @@ -540,7 +534,8 @@ GIntBig *OGRFeatureQuery::EvaluateAgainstIndices( swq_expr_node *psExpr, || poValue->eNodeType != SNT_CONSTANT ) return NULL; - poIndex = poLayer->GetIndex()->GetFieldIndex( poColumn->field_index ); + OGRAttrIndex *poIndex = + poLayer->GetIndex()->GetFieldIndex( poColumn->field_index ); if( poIndex == NULL ) return NULL; @@ -548,9 +543,8 @@ GIntBig *OGRFeatureQuery::EvaluateAgainstIndices( swq_expr_node *psExpr, /* OK, we have an index, now we need to query it. */ /* -------------------------------------------------------------------- */ OGRField sValue; - OGRFieldDefn *poFieldDefn; - - poFieldDefn = poLayer->GetLayerDefn()->GetFieldDefn(poColumn->field_index); + OGRFieldDefn *poFieldDefn = + poLayer->GetLayerDefn()->GetFieldDefn(poColumn->field_index); /* -------------------------------------------------------------------- */ /* Handle the case of an IN operation. */ @@ -676,7 +670,7 @@ char **OGRFeatureQuery::FieldCollector( void *pBareOp, /* -------------------------------------------------------------------- */ /* Add the field name into our list if it is not already there. */ /* -------------------------------------------------------------------- */ - const char *pszFieldName; + const char *pszFieldName = NULL; if( op->field_index >= poTargetDefn->GetFieldCount() && op->field_index < poTargetDefn->GetFieldCount() + SPECIAL_FIELD_COUNT) diff --git a/gdal/ogr/ogrfeaturestyle.cpp b/gdal/ogr/ogrfeaturestyle.cpp index 4b22ea94cfe0..8303b0023a12 100644 --- a/gdal/ogr/ogrfeaturestyle.cpp +++ b/gdal/ogr/ogrfeaturestyle.cpp @@ -205,10 +205,11 @@ GBool OGRStyleMgr::SetFeatureStyleString(OGRFeature *poFeature, const char *pszStyleString, GBool bNoMatching) { - const char *pszName; if (poFeature == NULL) return FALSE; + const char *pszName = NULL; + if (pszStyleString == NULL) poFeature->SetStyleString(""); else if (bNoMatching == TRUE) @@ -352,14 +353,9 @@ const char *OGRStyleMgr::GetStyleName(const char *pszStyleString) // SECURITY: The unit and the value for all parameter should be the same, // a text comparison is executed. - const char *pszStyle; - - if (pszStyleString) - pszStyle = pszStyleString; - else - pszStyle = m_pszStyleString; + const char *pszStyle = pszStyleString ? pszStyleString : m_pszStyleString; - if (pszStyle) + if( pszStyle ) { if (m_poDataSetStyleTable) return m_poDataSetStyleTable->GetStyleName(pszStyle); @@ -409,12 +405,7 @@ const char *OGRStyleMgr::GetStyleByName(const char *pszStyleName) GBool OGRStyleMgr::AddStyle(const char *pszStyleName, const char *pszStyleString) { - const char *pszStyle; - - if (pszStyleString) - pszStyle = pszStyleString; - else - pszStyle = m_pszStyleString; + const char *pszStyle = pszStyleString ? pszStyleString : m_pszStyleString; if (m_poDataSetStyleTable) { @@ -492,21 +483,21 @@ const char *OGRStyleMgr::GetStyleString(OGRFeature *poFeature) GBool OGRStyleMgr::AddPart(const char *pszPart) { - char *pszTmp; - if (pszPart) + if( pszPart ) { - if (m_pszStyleString) + if( m_pszStyleString ) { - pszTmp = CPLStrdup(CPLString().Printf("%s;%s",m_pszStyleString, - pszPart)); + char *pszTmp = + CPLStrdup(CPLString().Printf("%s;%s",m_pszStyleString, + pszPart)); CPLFree(m_pszStyleString); m_pszStyleString = pszTmp; } else { - pszTmp= CPLStrdup(CPLString().Printf("%s",pszPart)); - CPLFree(m_pszStyleString); - m_pszStyleString = pszTmp; + char *pszTmp = CPLStrdup(CPLString().Printf("%s",pszPart)); + CPLFree(m_pszStyleString); + m_pszStyleString = pszTmp; } return TRUE; } @@ -531,20 +522,21 @@ GBool OGRStyleMgr::AddPart(const char *pszPart) GBool OGRStyleMgr::AddPart(OGRStyleTool *poStyleTool) { - char *pszTmp; if (poStyleTool && poStyleTool->GetStyleString()) { if (m_pszStyleString) { - pszTmp = CPLStrdup(CPLString().Printf("%s;%s",m_pszStyleString, - poStyleTool->GetStyleString())); + char *pszTmp = + CPLStrdup(CPLString().Printf("%s;%s",m_pszStyleString, + poStyleTool->GetStyleString())); CPLFree(m_pszStyleString); m_pszStyleString = pszTmp; } else { - pszTmp= CPLStrdup(CPLString().Printf("%s", - poStyleTool->GetStyleString())); + char *pszTmp = + CPLStrdup(CPLString().Printf("%s", + poStyleTool->GetStyleString())); CPLFree(m_pszStyleString); m_pszStyleString = pszTmp; } @@ -599,22 +591,19 @@ int OGR_SM_AddPart(OGRStyleMgrH hSM, OGRStyleToolH hST) int OGRStyleMgr::GetPartCount(const char *pszStyleString) { - const char *pszPart; int nPartCount = 1; - const char *pszString; - const char *pszStrTmp; - if (pszStyleString != NULL) - pszString = pszStyleString; - else - pszString = m_pszStyleString; + const char *pszString = pszStyleString != NULL + ? pszStyleString + : m_pszStyleString; if (pszString == NULL) return 0; - pszStrTmp = pszString; + const char *pszStrTmp = pszString; // Search for parts separated by semicolons not counting the possible // semicolon at the and of string. + const char *pszPart = NULL; while ((pszPart = strstr(pszStrTmp, ";")) != NULL && pszPart[1] != '\0') { pszStrTmp = &pszPart[1]; @@ -673,26 +662,20 @@ int OGR_SM_GetPartCount(OGRStyleMgrH hSM, const char *pszStyleString) OGRStyleTool *OGRStyleMgr::GetPart(int nPartId, const char *pszStyleString) { - char **papszStyleString; - const char *pszStyle; - const char *pszString; - OGRStyleTool *poStyleTool = NULL; - - if (pszStyleString) - pszStyle = pszStyleString; - else - pszStyle = m_pszStyleString; + const char *pszStyle = pszStyleString ? pszStyleString : m_pszStyleString; if (pszStyle == NULL) return NULL; - papszStyleString = CSLTokenizeString2(pszStyle, ";", - CSLT_HONOURSTRINGS - | CSLT_PRESERVEQUOTES - | CSLT_PRESERVEESCAPES ); + char **papszStyleString = + CSLTokenizeString2(pszStyle, ";", + CSLT_HONOURSTRINGS + | CSLT_PRESERVEQUOTES + | CSLT_PRESERVEESCAPES ); - pszString = CSLGetField( papszStyleString, nPartId ); + const char *pszString = CSLGetField( papszStyleString, nPartId ); + OGRStyleTool *poStyleTool = NULL; if ( strlen(pszString) > 0 ) { poStyleTool = CreateStyleToolFromStyleString(pszString); @@ -750,7 +733,7 @@ OGRStyleTool *OGRStyleMgr::CreateStyleToolFromStyleString(const char * CSLT_HONOURSTRINGS | CSLT_PRESERVEQUOTES | CSLT_PRESERVEESCAPES ); - OGRStyleTool *poStyleTool; + OGRStyleTool *poStyleTool = NULL; if (CSLCount(papszToken) <2) poStyleTool = NULL; @@ -1610,8 +1593,6 @@ GBool OGRStyleTool::GetRGBFromString(const char *pszColor, int &nRed, int OGRStyleTool::GetSpecificId(const char *pszId, const char *pszWanted) { const char *pszRealWanted = pszWanted; - const char *pszFound; - int nValue = -1; if (pszWanted == NULL || strlen(pszWanted) == 0) pszRealWanted = "ogr-pen"; @@ -1619,6 +1600,8 @@ int OGRStyleTool::GetSpecificId(const char *pszId, const char *pszWanted) if (pszId == NULL) return -1; + int nValue = -1; + const char *pszFound = NULL; if ((pszFound = strstr(pszId, pszRealWanted)) != NULL) { // We found the string, it could be no value after it, use default one @@ -1745,12 +1728,6 @@ GBool OGRStyleTool::Parse(const OGRStyleParamId *pasStyle, OGRStyleValue *pasValue, int nCount) { - char **papszToken; // Token to contains StyleString Type and content - char **papszToken2; // Token that will contains StyleString elements - - - OGRSTUnitId eLastUnit; - if (IsStyleParsed() == TRUE) return TRUE; @@ -1759,12 +1736,14 @@ GBool OGRStyleTool::Parse(const OGRStyleParamId *pasStyle, if (m_pszStyleString == NULL) return FALSE; + // Token to contains StyleString Type and content. // Tokenize the String to get the Type and the content // Example: Type(elem1:val2,elem2:val2) - papszToken = CSLTokenizeString2(m_pszStyleString,"()", - CSLT_HONOURSTRINGS - | CSLT_PRESERVEQUOTES - | CSLT_PRESERVEESCAPES ); + char **papszToken = + CSLTokenizeString2(m_pszStyleString,"()", + CSLT_HONOURSTRINGS + | CSLT_PRESERVEQUOTES + | CSLT_PRESERVEESCAPES ); if (CSLCount(papszToken) > 2 || CSLCount(papszToken) == 0) { @@ -1774,11 +1753,13 @@ GBool OGRStyleTool::Parse(const OGRStyleParamId *pasStyle, return FALSE; } + // Token that will contains StyleString elements. // Tokenize the content of the StyleString to get paired components in it. - papszToken2 = CSLTokenizeString2( papszToken[1], ",", - CSLT_HONOURSTRINGS - | CSLT_PRESERVEQUOTES - | CSLT_PRESERVEESCAPES ); + char **papszToken2 = + CSLTokenizeString2( papszToken[1], ",", + CSLT_HONOURSTRINGS + | CSLT_PRESERVEQUOTES + | CSLT_PRESERVEESCAPES ); // Valid that we have the right StyleString for this feature type. switch (GetType()) @@ -1857,8 +1838,8 @@ GBool OGRStyleTool::Parse(const OGRStyleParamId *pasStyle, //////////////////////////////////////////////////////////////////////// // Save Scale and output Units because the parsing code will alter - // the values - eLastUnit = m_eUnit; + // the values. + OGRSTUnitId eLastUnit = m_eUnit; double dSavedScale = m_dfScale; const int nElements = CSLCount(papszToken2); @@ -1922,12 +1903,10 @@ GBool OGRStyleTool::Parse(const OGRStyleParamId *pasStyle, //! @cond Doxygen_Suppress void OGRStyleTool::SetInternalInputUnitFromParam(char *pszString) { - - char *pszUnit; - if (pszString == NULL) return; - pszUnit = strstr(pszString,"g"); + + char *pszUnit = strstr(pszString,"g"); if (pszUnit) { SetUnit(OGRSTUGround); diff --git a/gdal/ogr/ogrgeometry.cpp b/gdal/ogr/ogrgeometry.cpp index 279be56ae319..0d9c2bc151f1 100644 --- a/gdal/ogr/ogrgeometry.cpp +++ b/gdal/ogr/ogrgeometry.cpp @@ -178,10 +178,6 @@ void OGRGeometry::dumpReadable( FILE * fp, const char * pszPrefix, char** papszO CSLFetchNameValue(papszOptions, "DISPLAY_GEOMETRY"); if (pszDisplayGeometry != NULL && EQUAL(pszDisplayGeometry, "SUMMARY")) { - OGRLineString *poLine; - OGRCurvePolygon *poPoly; - OGRCurve *poRing; - OGRGeometryCollection *poColl; fprintf( fp, "%s%s : ", pszPrefix, getGeometryName() ); switch( getGeometryType() ) { @@ -213,9 +209,11 @@ void OGRGeometry::dumpReadable( FILE * fp, const char * pszPrefix, char** papszO case wkbCircularStringZ: case wkbCircularStringM: case wkbCircularStringZM: - poLine = (OGRLineString*)this; + { + OGRLineString *poLine = (OGRLineString*)this; fprintf( fp, "%d points\n", poLine->getNumPoints() ); break; + } case wkbPolygon: case wkbPolygon25D: case wkbPolygonM: @@ -225,10 +223,9 @@ void OGRGeometry::dumpReadable( FILE * fp, const char * pszPrefix, char** papszO case wkbCurvePolygonM: case wkbCurvePolygonZM: { - int nRings; - poPoly = (OGRCurvePolygon*)this; - poRing = poPoly->getExteriorRingCurve(); - nRings = poPoly->getNumInteriorRings(); + OGRCurvePolygon *poPoly = (OGRCurvePolygon*)this; + OGRCurve *poRing = poPoly->getExteriorRingCurve(); + int nRings = poPoly->getNumInteriorRings(); if (poRing == NULL) fprintf( fp, "empty"); else @@ -309,7 +306,7 @@ void OGRGeometry::dumpReadable( FILE * fp, const char * pszPrefix, char** papszO case wkbMultiSurfaceZM: case wkbGeometryCollectionZM: { - poColl = (OGRGeometryCollection*)this; + OGRGeometryCollection *poColl = (OGRGeometryCollection*)this; fprintf( fp, "%d geometries:\n", poColl->getNumGeometries() ); for ( int ig = 0; ig < poColl->getNumGeometries(); ig++ ) { @@ -590,17 +587,15 @@ OGRErr OGRGeometry::transformTo( OGRSpatialReference *poSR ) #ifdef DISABLE_OGRGEOM_TRANSFORM return OGRERR_FAILURE; #else - OGRCoordinateTransformation *poCT; - OGRErr eErr; - if( getSpatialReference() == NULL || poSR == NULL ) return OGRERR_FAILURE; - poCT = OGRCreateCoordinateTransformation( getSpatialReference(), poSR ); + OGRCoordinateTransformation *poCT = + OGRCreateCoordinateTransformation( getSpatialReference(), poSR ); if( poCT == NULL ) return OGRERR_FAILURE; - eErr = transform( poCT ); + OGRErr eErr = transform( poCT ); delete poCT; @@ -5292,16 +5287,14 @@ OGRGeometry *OGRGeometryFromHexEWKB( const char *pszBytea, int* pnSRID, int bIsPostGIS1_EWKB ) { - GByte *pabyWKB; - int nWKBLength=0; - OGRGeometry *poGeometry; - if( pszBytea == NULL ) return NULL; - pabyWKB = CPLHexToBinary(pszBytea, &nWKBLength); + int nWKBLength = 0; + GByte *pabyWKB = CPLHexToBinary(pszBytea, &nWKBLength); - poGeometry = OGRGeometryFromEWKB(pabyWKB, nWKBLength, pnSRID, bIsPostGIS1_EWKB); + OGRGeometry *poGeometry = + OGRGeometryFromEWKB(pabyWKB, nWKBLength, pnSRID, bIsPostGIS1_EWKB); CPLFree(pabyWKB); @@ -5315,13 +5308,8 @@ OGRGeometry *OGRGeometryFromHexEWKB( const char *pszBytea, int* pnSRID, char* OGRGeometryToHexEWKB( OGRGeometry * poGeometry, int nSRSId, int nPostGISMajor, int nPostGISMinor ) { - GByte *pabyWKB; - char *pszTextBuf; - char *pszTextBufCurrent; - char *pszHex; - int nWkbSize = poGeometry->WkbSize(); - pabyWKB = (GByte *) CPLMalloc(nWkbSize); + GByte *pabyWKB = (GByte *) CPLMalloc(nWkbSize); if( (nPostGISMajor > 2 || (nPostGISMajor == 2 && nPostGISMinor >= 2)) && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint && @@ -5345,11 +5333,11 @@ char* OGRGeometryToHexEWKB( OGRGeometry * poGeometry, int nSRSId, one for a null terminator */ int pszSize = nWkbSize*2 + 8 + 1; - pszTextBuf = (char *) CPLMalloc(pszSize); - pszTextBufCurrent = pszTextBuf; + char *pszTextBuf = (char *) CPLMalloc(pszSize); + char *pszTextBufCurrent = pszTextBuf; /* Convert the 1st byte, which is the endianness flag, to hex. */ - pszHex = CPLBinaryToHex( 1, pabyWKB ); + char *pszHex = CPLBinaryToHex( 1, pabyWKB ); strcpy(pszTextBufCurrent, pszHex ); CPLFree ( pszHex ); pszTextBufCurrent += 2; diff --git a/gdal/ogr/ogrgeometrycollection.cpp b/gdal/ogr/ogrgeometrycollection.cpp index 97fbdbf76b76..0e13e9878ac3 100644 --- a/gdal/ogr/ogrgeometrycollection.cpp +++ b/gdal/ogr/ogrgeometrycollection.cpp @@ -138,9 +138,7 @@ void OGRGeometryCollection::empty() OGRGeometry *OGRGeometryCollection::clone() const { - OGRGeometryCollection *poNewGC; - - poNewGC = (OGRGeometryCollection*) + OGRGeometryCollection *poNewGC = (OGRGeometryCollection*) OGRGeometryFactory::createGeometry(getGeometryType()); if( poNewGC == NULL ) return NULL; @@ -792,7 +790,6 @@ OGRErr OGRGeometryCollection::exportToWktInternal( char ** ppszDstText, const char* pszSkipPrefix ) const { - char **papszGeoms; size_t nCumulativeLength = 0; OGRErr eErr; bool bMustWriteComma = false; @@ -800,7 +797,8 @@ OGRErr OGRGeometryCollection::exportToWktInternal( char ** ppszDstText, /* -------------------------------------------------------------------- */ /* Build a list of strings containing the stuff for each Geom. */ /* -------------------------------------------------------------------- */ - papszGeoms = (nGeomCount) ? (char **) CPLCalloc(sizeof(char *),nGeomCount) : NULL; + char **papszGeoms = + nGeomCount ? (char **) CPLCalloc(sizeof(char *),nGeomCount) : NULL; for( int iGeom = 0; iGeom < nGeomCount; iGeom++ ) { @@ -833,7 +831,7 @@ OGRErr OGRGeometryCollection::exportToWktInternal( char ** ppszDstText, } else if( eWkbVariant != wkbVariantIso ) { - char *substr; + char *substr = NULL; if( (substr = strstr(papszGeoms[iGeom], " Z")) != NULL ) memmove(substr, substr+strlen(" Z"), 1+strlen(substr+strlen(" Z"))); } diff --git a/gdal/ogr/ogrgeometryfactory.cpp b/gdal/ogr/ogrgeometryfactory.cpp index 621031686ed4..e53f741bdd70 100644 --- a/gdal/ogr/ogrgeometryfactory.cpp +++ b/gdal/ogr/ogrgeometryfactory.cpp @@ -85,9 +85,7 @@ OGRErr OGRGeometryFactory::createFromWkb(unsigned char *pabyData, { OGRwkbGeometryType eGeometryType; - int nByteOrder; OGRErr eErr; - OGRGeometry *poGeom; *ppoReturn = NULL; @@ -98,7 +96,7 @@ OGRErr OGRGeometryFactory::createFromWkb(unsigned char *pabyData, /* Get the byte order byte. The extra tests are to work around */ /* bug sin the WKB of DB2 v7.2 as identified by Safe Software. */ /* -------------------------------------------------------------------- */ - nByteOrder = DB2_V72_FIX_BYTE_ORDER(*pabyData); + int nByteOrder = DB2_V72_FIX_BYTE_ORDER(*pabyData); if( nByteOrder != wkbXDR && nByteOrder != wkbNDR ) { CPLDebug( "OGR", @@ -132,7 +130,7 @@ OGRErr OGRGeometryFactory::createFromWkb(unsigned char *pabyData, /* Instantiate a geometry of the appropriate type, and */ /* initialize from the input stream. */ /* -------------------------------------------------------------------- */ - poGeom = createGeometry( eGeometryType ); + OGRGeometry *poGeom = createGeometry( eGeometryType ); if( poGeom == NULL ) return OGRERR_UNSUPPORTED_GEOMETRY_TYPE; @@ -254,7 +252,6 @@ OGRErr OGRGeometryFactory::createFromWkt(char **ppszData, OGRErr eErr; char szToken[OGR_WKT_TOKEN_MAX]; char *pszInput = *ppszData; - OGRGeometry *poGeom; *ppoReturn = NULL; @@ -267,11 +264,11 @@ OGRErr OGRGeometryFactory::createFromWkt(char **ppszData, /* -------------------------------------------------------------------- */ /* Instantiate a geometry of the appropriate type. */ /* -------------------------------------------------------------------- */ + OGRGeometry *poGeom = NULL; if( STARTS_WITH_CI(szToken,"POINT") ) { poGeom = new OGRPoint(); } - else if( STARTS_WITH_CI(szToken,"LINESTRING") ) { poGeom = new OGRLineString(); @@ -967,7 +964,7 @@ OGRGeometry *OGRGeometryFactory::forceToMultiLineString( OGRGeometry *poGeom ) if( eGeomType == wkbPolygon || eGeomType == wkbCurvePolygon ) { OGRMultiLineString *poMP = new OGRMultiLineString(); - OGRPolygon *poPoly; + OGRPolygon *poPoly = NULL; if( eGeomType == wkbPolygon ) poPoly = (OGRPolygon *) poGeom; else @@ -1011,7 +1008,7 @@ OGRGeometry *OGRGeometryFactory::forceToMultiLineString( OGRGeometry *poGeom ) if( eGeomType == wkbMultiPolygon || eGeomType == wkbMultiSurface ) { OGRMultiLineString *poMP = new OGRMultiLineString(); - OGRMultiPolygon *poMPoly; + OGRMultiPolygon *poMPoly = NULL; if( eGeomType == wkbMultiPolygon ) poMPoly = (OGRMultiPolygon *) poGeom; else @@ -1655,8 +1652,8 @@ OGRGeometry* OGRGeometryFactory::organizePolygons( OGRGeometry **papoPolygons, polygons */ bValidTopology = false; #ifdef DEBUG - char* wkt1; - char* wkt2; + char* wkt1 = NULL; + char* wkt2 = NULL; asPolyEx[i].poPolygon->exportToWkt(&wkt1); asPolyEx[j].poPolygon->exportToWkt(&wkt2); CPLDebug( "OGR", @@ -1688,7 +1685,7 @@ OGRGeometry* OGRGeometryFactory::organizePolygons( OGRGeometry **papoPolygons, /* -------------------------------------------------------------------- */ if ( !bValidTopology || bMixedUpGeometries ) { - OGRGeometryCollection* poGC; + OGRGeometryCollection* poGC = NULL; if( bNonPolygon ) poGC = new OGRGeometryCollection(); else if( bHasCurves ) @@ -2526,11 +2523,9 @@ static void CutGeometryOnDateLineAndAddToMulti(OGRGeometryCollection* poMulti, } else { - OGRLineString* poLS; - if (eGeomType == wkbPolygon) - poLS = ((OGRPolygon*)poGeom)->getExteriorRing(); - else - poLS = (OGRLineString*)poGeom; + OGRLineString* poLS = eGeomType == wkbPolygon + ? ((OGRPolygon*)poGeom)->getExteriorRing() + : (OGRLineString*)poGeom; if (poLS) { double dfMaxSmallDiffLong = 0; @@ -4291,7 +4286,7 @@ OGRCurve* OGRGeometryFactory::curveFromLineString(const OGRLineString* poLS, i++ ; } - OGRCurve* poRet; + OGRCurve* poRet = NULL; if( poLSNew != NULL && poLSNew->getNumPoints() < 2 ) { diff --git a/gdal/ogr/ogrlinearring.cpp b/gdal/ogr/ogrlinearring.cpp index cde2a66cb8d9..06bd263643ad 100644 --- a/gdal/ogr/ogrlinearring.cpp +++ b/gdal/ogr/ogrlinearring.cpp @@ -405,9 +405,7 @@ int OGRLinearRing::_WkbSize( int _flags ) const OGRGeometry *OGRLinearRing::clone() const { - OGRLinearRing *poNewLinearRing; - - poNewLinearRing = new OGRLinearRing(); + OGRLinearRing *poNewLinearRing = new OGRLinearRing(); poNewLinearRing->assignSpatialReference( getSpatialReference() ); poNewLinearRing->setPoints( nPointCount, paoPoints, padfZ, padfM ); diff --git a/gdal/ogr/ogrlinestring.cpp b/gdal/ogr/ogrlinestring.cpp index 1f162aff14a4..f578499a970e 100644 --- a/gdal/ogr/ogrlinestring.cpp +++ b/gdal/ogr/ogrlinestring.cpp @@ -123,9 +123,7 @@ void OGRSimpleCurve::flattenTo2D() OGRGeometry *OGRSimpleCurve::clone() const { - OGRSimpleCurve *poCurve; - - poCurve = (OGRSimpleCurve*) + OGRSimpleCurve *poCurve = (OGRSimpleCurve*) OGRGeometryFactory::createGeometry(getGeometryType()); if( poCurve == NULL ) return NULL; @@ -2329,8 +2327,6 @@ OGRErr OGRSimpleCurve::transform( OGRCoordinateTransformation *poCT ) #ifdef DISABLE_OGRGEOM_TRANSFORM return OGRERR_FAILURE; #else - double *xyz; - int *pabSuccess; /* -------------------------------------------------------------------- */ /* Make a copy of the points to operate on, so as to be able to */ @@ -2338,8 +2334,9 @@ OGRErr OGRSimpleCurve::transform( OGRCoordinateTransformation *poCT ) /* or keeping intact the original geometry if only full reprojection */ /* allowed. */ /* -------------------------------------------------------------------- */ - xyz = (double *) VSI_MALLOC_VERBOSE(sizeof(double) * nPointCount * 3); - pabSuccess = (int *) VSI_CALLOC_VERBOSE(sizeof(int), nPointCount); + double *xyz = + (double *) VSI_MALLOC_VERBOSE(sizeof(double) * nPointCount * 3); + int *pabSuccess = (int *) VSI_CALLOC_VERBOSE(sizeof(int), nPointCount); if( xyz == NULL || pabSuccess == NULL ) { VSIFree(xyz); diff --git a/gdal/ogr/ogrmultisurface.cpp b/gdal/ogr/ogrmultisurface.cpp index 0fce45dc35a8..b49b6fe14adb 100644 --- a/gdal/ogr/ogrmultisurface.cpp +++ b/gdal/ogr/ogrmultisurface.cpp @@ -176,14 +176,13 @@ OGRErr OGRMultiSurface::importFromWkt( char ** ppszInput ) do { - /* -------------------------------------------------------------------- */ /* Get the first token, which should be the geometry type. */ /* -------------------------------------------------------------------- */ const char* pszInputBefore = pszInput; pszInput = OGRWktReadToken( pszInput, szToken ); - OGRSurface* poSurface; + OGRSurface* poSurface = NULL; /* -------------------------------------------------------------------- */ /* Do the import. */ diff --git a/gdal/ogr/ogrpgeogeometry.cpp b/gdal/ogr/ogrpgeogeometry.cpp index f231bbd686c7..e6f1fa0869b1 100644 --- a/gdal/ogr/ogrpgeogeometry.cpp +++ b/gdal/ogr/ogrpgeogeometry.cpp @@ -392,11 +392,9 @@ OGRErr OGRWriteToShapeBin( OGRGeometry *poGeom, nParts = poPoly->getNumInteriorRings() + 1; for ( GUInt32 i = 0; i < nParts; i++ ) { - OGRLinearRing *poRing; - if ( i == 0 ) - poRing = poPoly->getExteriorRing(); - else - poRing = poPoly->getInteriorRing(i-1); + OGRLinearRing *poRing = i == 0 + ? poPoly->getExteriorRing() + : poPoly->getInteriorRing(i-1); nPoints += poRing->getNumPoints(); } nShpSize += 16 * nCoordDims; /* xy(z)(m) box */ @@ -456,11 +454,9 @@ OGRErr OGRWriteToShapeBin( OGRGeometry *poGeom, nParts += nRings; for ( int i = 0; i < nRings; i++ ) { - OGRLinearRing *poRing; - if ( i == 0 ) - poRing = poPoly->getExteriorRing(); - else - poRing = poPoly->getInteriorRing(i-1); + OGRLinearRing *poRing = i == 0 + ? poPoly->getExteriorRing() + : poPoly->getInteriorRing(i-1); nPoints += poRing->getNumPoints(); } } @@ -798,7 +794,7 @@ id,WKT for( GUInt32 i = 0; i < nParts; i++ ) { /* Check our Ring and condition it */ - OGRLinearRing *poRing; + OGRLinearRing *poRing = NULL; if ( i == 0 ) { poRing = poPoly->getExteriorRing(); @@ -1046,7 +1042,7 @@ id,WKT for( int j = 0; j < nRings; j++ ) { /* Check our Ring and condition it */ - OGRLinearRing *poRing; + OGRLinearRing *poRing = NULL; if ( j == 0 ) { poRing = poPoly->getExteriorRing(); diff --git a/gdal/ogr/ogrspatialreference.cpp b/gdal/ogr/ogrspatialreference.cpp index b75dd37a0239..f128ea5ac92a 100644 --- a/gdal/ogr/ogrspatialreference.cpp +++ b/gdal/ogr/ogrspatialreference.cpp @@ -2570,7 +2570,7 @@ OGRErr OGRSpatialReference::importFromCRSURL( const char *pszURL ) const char* pszUrlEnd = strstr(pszCur, searchStr); // figure out the next component URL - char* pszComponentUrl; + char* pszComponentUrl = NULL; if( pszUrlEnd ) { @@ -5813,12 +5813,11 @@ OGRErr OGRSpatialReference::SetAuthority( const char *pszTargetKey, /* -------------------------------------------------------------------- */ /* Create a new authority node. */ /* -------------------------------------------------------------------- */ - char szCode[32]; - OGR_SRSNode *poAuthNode; + char szCode[32]; snprintf( szCode, sizeof(szCode), "%d", nCode ); - poAuthNode = new OGR_SRSNode( "AUTHORITY" ); + OGR_SRSNode *poAuthNode = new OGR_SRSNode( "AUTHORITY" ); poAuthNode->AddChild( new OGR_SRSNode( pszAuthority ) ); poAuthNode->AddChild( new OGR_SRSNode( szCode ) ); @@ -5879,12 +5878,9 @@ OGRSpatialReference::GetAuthorityCode( const char *pszTargetKey ) const /* -------------------------------------------------------------------- */ /* Find the node below which the authority should be put. */ /* -------------------------------------------------------------------- */ - const OGR_SRSNode *poNode; - - if( pszTargetKey == NULL ) - poNode = poRoot; - else - poNode= ((OGRSpatialReference *) this)->GetAttrNode( pszTargetKey ); + const OGR_SRSNode *poNode = pszTargetKey == NULL + ? poRoot + : ((OGRSpatialReference *) this)->GetAttrNode( pszTargetKey ); if( poNode == NULL ) return NULL; @@ -7078,12 +7074,9 @@ const char *OGRSpatialReference::GetExtension( const char *pszTargetKey, /* -------------------------------------------------------------------- */ /* Find the target node. */ /* -------------------------------------------------------------------- */ - const OGR_SRSNode *poNode; - - if( pszTargetKey == NULL ) - poNode = poRoot; - else - poNode = const_cast(this)->GetAttrNode( pszTargetKey ); + const OGR_SRSNode *poNode = pszTargetKey == NULL + ? poRoot + : const_cast(this)->GetAttrNode( pszTargetKey ); if( poNode == NULL ) return NULL; diff --git a/gdal/ogr/swq.cpp b/gdal/ogr/swq.cpp index 34e4b2735588..a8b1435f3df6 100644 --- a/gdal/ogr/swq.cpp +++ b/gdal/ogr/swq.cpp @@ -96,8 +96,6 @@ int swqlex( YYSTYPE *ppNode, swq_parse_context *context ) /* -------------------------------------------------------------------- */ if( *pszInput == '"' || *pszInput == '\'' ) { - char *token; - int i_token; char chQuote = *pszInput; bool bFoundEndQuote = false; @@ -105,8 +103,8 @@ int swqlex( YYSTYPE *ppNode, swq_parse_context *context ) pszInput++; - token = (char *) CPLMalloc(strlen(pszInput)+1); - i_token = 0; + char *token = (char *) CPLMalloc(strlen(pszInput)+1); + int i_token = 0; while( *pszInput != '\0' ) { @@ -299,7 +297,6 @@ swq_select_summarize( swq_select *select_info, { swq_col_def *def = select_info->column_defs + dest_column; - swq_summary *summary; /* -------------------------------------------------------------------- */ /* Do various checking. */ @@ -336,7 +333,7 @@ swq_select_summarize( swq_select *select_info, /* -------------------------------------------------------------------- */ /* If distinct processing is on, process that now. */ /* -------------------------------------------------------------------- */ - summary = select_info->column_summary + dest_column; + swq_summary *summary = select_info->column_summary + dest_column; if( def->distinct_flag ) { diff --git a/gdal/ogr/swq_expr_node.cpp b/gdal/ogr/swq_expr_node.cpp index 5bead25cb4e8..8be97fdbffc9 100644 --- a/gdal/ogr/swq_expr_node.cpp +++ b/gdal/ogr/swq_expr_node.cpp @@ -193,9 +193,7 @@ void swq_expr_node::ReverseSubExpressions() { for( int i = 0; i < nSubExprCount / 2; i++ ) { - swq_expr_node *temp; - - temp = papoSubExpr[i]; + swq_expr_node *temp = papoSubExpr[i]; papoSubExpr[i] = papoSubExpr[nSubExprCount - i - 1]; papoSubExpr[nSubExprCount - i - 1] = temp; } diff --git a/gdal/ogr/swq_op_general.cpp b/gdal/ogr/swq_op_general.cpp index 9a734174b7ec..ca4392b883d3 100644 --- a/gdal/ogr/swq_op_general.cpp +++ b/gdal/ogr/swq_op_general.cpp @@ -1310,7 +1310,7 @@ swq_expr_node *SWQCastEvaluator( swq_expr_node *node, { if( poSrcNode->geometry_value != NULL ) { - char* pszWKT; + char* pszWKT = NULL; poSrcNode->geometry_value->exportToWkt(&pszWKT); osRet = pszWKT; CPLFree(pszWKT);