diff --git a/classobject.c b/classobject.c index ff004fb57e..0878562332 100644 --- a/classobject.c +++ b/classobject.c @@ -151,7 +151,7 @@ int msInsertStyle(classObj *class, styleObj *style, int nStyleIndex) MS_REFCNT_INCR(style); class->numstyles++; return class->numstyles-1; - } else if (nStyleIndex >= 0 && nStyleIndex < class->numstyles) { + } else { /* Move styles existing at the specified nStyleIndex or greater */ /* to a higher nStyleIndex */ for (i=class->numstyles-1; i>=nStyleIndex; i--) { @@ -161,9 +161,6 @@ int msInsertStyle(classObj *class, styleObj *style, int nStyleIndex) MS_REFCNT_INCR(style); class->numstyles++; return nStyleIndex; - } else { - msSetError(MS_CHILDERR, "Invalid nStyleIndex", "insertStyle()"); - return -1; } } diff --git a/layerobject.c b/layerobject.c index 063a3a956f..569e6cf141 100644 --- a/layerobject.c +++ b/layerobject.c @@ -67,7 +67,7 @@ int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) MS_REFCNT_INCR(classobj); layer->numclasses++; return layer->numclasses-1; - } else if (nIndex >= 0 && nIndex < layer->numclasses) { + } else { /* Copy classes existing at the specified nIndex or greater */ /* to an index one higher */ @@ -88,9 +88,6 @@ int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) /* increment number of classes and return */ layer->numclasses++; return nIndex; - } else { - msSetError(MS_CHILDERR, "Invalid index", "msInsertClass()"); - return -1; } } diff --git a/mapcontext.c b/mapcontext.c index 2eaa4d275d..54bfc71527 100644 --- a/mapcontext.c +++ b/mapcontext.c @@ -1148,9 +1148,6 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names) if( psRoot == NULL ) { msSetError( MS_MAPCONTEXTERR, "Invalid XML file (%s)", "msLoadMapContext()", filename ); - if(psRoot != NULL) - CPLDestroyXMLNode(psRoot); - return MS_FAILURE; } diff --git a/mapdebug.c b/mapdebug.c index 2043a99502..dbaabd585c 100644 --- a/mapdebug.c +++ b/mapdebug.c @@ -101,7 +101,7 @@ debugInfoObj *msGetDebugInfoObj() } /* If the link is not already at the head of the list, promote it */ - else if( link != NULL && link->next != NULL ) { + else { debugInfoObj *target = link->next; link->next = link->next->next; diff --git a/mapdrawgdal.c b/mapdrawgdal.c index d7bf8fab01..cfa4dbb7f9 100644 --- a/mapdrawgdal.c +++ b/mapdrawgdal.c @@ -468,7 +468,7 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, hColorMap = GDALGetRasterColorTable( hBand1 ); if( hColorMap != NULL ) hColorMap = GDALCloneColorTable( hColorMap ); - else if( hBand2 == NULL ) { + else { hColorMap = GDALCreateColorTable( GPI_RGB ); isDefaultGreyscale = true; diff --git a/maperror.c b/maperror.c index 65a06797cf..00df40aa0d 100644 --- a/maperror.c +++ b/maperror.c @@ -142,7 +142,7 @@ errorObj *msGetErrorObj() } /* If the link is not already at the head of the list, promote it */ - else if( link != NULL && link->next != NULL ) { + else { te_info_t *target = link->next; link->next = link->next->next; diff --git a/mapgeos.c b/mapgeos.c index 53542d2e69..61259516cb 100644 --- a/mapgeos.c +++ b/mapgeos.c @@ -107,7 +107,7 @@ static GEOSContextHandle_t msGetGeosContextHandle() } /* If the link is not already at the head of the list, promote it */ - else if( link != NULL && link->next != NULL ) { + else { geos_thread_info_t *target = link->next; link->next = link->next->next; diff --git a/mapio.c b/mapio.c index 4327ec6907..8edc49bc87 100644 --- a/mapio.c +++ b/mapio.c @@ -418,7 +418,7 @@ int msIO_vfprintf( FILE *fp, const char *format, va_list ap ) va_list args_copy; int return_val; msIOContext *context; - char workBuf[8000], *largerBuf = NULL; + char workBuf[8000]; #if !defined(HAVE_VSNPRINTF) return_val = vsprintf( workBuf, format, ap); @@ -428,6 +428,8 @@ int msIO_vfprintf( FILE *fp, const char *format, va_list ap ) return -1; } + char* outbuf = workBuf; + #else #ifdef va_copy @@ -436,26 +438,31 @@ int msIO_vfprintf( FILE *fp, const char *format, va_list ap ) args_copy = ap; #endif /* va_copy */ + char* largerBuf = NULL; return_val = vsnprintf( workBuf, sizeof(workBuf), format, ap ); if (return_val == -1 || return_val >= sizeof(workBuf)-1) { return_val = _ms_vsprintf(&largerBuf, format, args_copy ); } va_end(args_copy); -#endif /* HAVE_VSNPRINTF */ - if (return_val < 0) return -1; + char* outbuf = largerBuf?largerBuf:workBuf; + +#endif /* HAVE_VSNPRINTF */ + context = msIO_getHandler( fp ); if( context == NULL ) - return_val = fwrite( largerBuf?largerBuf:workBuf, 1, return_val, fp ); + return_val = fwrite(outbuf , 1, return_val, fp ); else return_val = msIO_contextWrite( context, - largerBuf?largerBuf:workBuf, + outbuf, return_val ); +#if defined(HAVE_VSNPRINTF) msFree(largerBuf); +#endif return return_val; } diff --git a/maplabel.c b/maplabel.c index 6649d57bb0..ea6aac7850 100644 --- a/maplabel.c +++ b/maplabel.c @@ -1100,7 +1100,7 @@ int msInsertLabelStyle(labelObj *label, styleObj *style, int nStyleIndex) MS_REFCNT_INCR(style); label->numstyles++; return label->numstyles-1; - } else if (nStyleIndex >= 0 && nStyleIndex < label->numstyles) { + } else { /* Move styles existing at the specified nStyleIndex or greater */ /* to a higher nStyleIndex */ for (i=label->numstyles-1; i>=nStyleIndex; i--) { @@ -1110,9 +1110,6 @@ int msInsertLabelStyle(labelObj *label, styleObj *style, int nStyleIndex) MS_REFCNT_INCR(style); label->numstyles++; return nStyleIndex; - } else { - msSetError(MS_CHILDERR, "Invalid nStyleIndex", "insertLabelStyle()"); - return -1; } } diff --git a/mapobject.c b/mapobject.c index 48cc8d73dd..355024a3a4 100644 --- a/mapobject.c +++ b/mapobject.c @@ -548,7 +548,7 @@ int msInsertLayer(mapObj *map, layerObj *layer, int nIndex) MS_REFCNT_INCR(layer); map->numlayers++; return map->numlayers-1; - } else if (nIndex >= 0 && nIndex < map->numlayers) { + } else { /* Move existing layers at the specified nIndex or greater */ /* to an index one higher */ int i; @@ -576,9 +576,6 @@ int msInsertLayer(mapObj *map, layerObj *layer, int nIndex) MS_REFCNT_INCR(layer); map->numlayers++; return nIndex; - } else { - msSetError(MS_CHILDERR, "Invalid index", "msInsertLayer()"); - return -1; } } diff --git a/mapogcfilter.cpp b/mapogcfilter.cpp index 0d2c0585f7..54769047a6 100644 --- a/mapogcfilter.cpp +++ b/mapogcfilter.cpp @@ -149,13 +149,11 @@ int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression) char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char *value, int forcecharcter) { - int bIscharacter, bSqlLayer=MS_FALSE; + int bIscharacter; char *pszExpression = NULL, *pszEscapedStr=NULL, *pszTmpExpression=NULL; char **paszElements = NULL, **papszRangeElements=NULL; int numelements,i,nrangeelements; - /* TODO: remove the bSqlLayer checks since we want to write MapServer expressions only. */ - /* double minval, maxval; */ if (lp && item && value) { if (strstr(value, "/") == NULL) { @@ -170,9 +168,7 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char pszTmpExpression = msStringConcatenate(pszTmpExpression, "("); for (i=0; itype = MS_LAYER_RASTER; @@ -961,6 +962,7 @@ int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer, const char* pszUserSty /* Polygon symbolizer */ LOOP_ON_CHILD_ELEMENT(psRoot, psPolygonSymbolizer, "PolygonSymbolizer") { + /* cppcheck-suppress knownConditionTrueFalse */ const int bNewClass = (nSymbolizer == 0); msSLDParsePolygonSymbolizer(psPolygonSymbolizer, psLayer, bNewClass, pszUserStyleName); diff --git a/mapogr.cpp b/mapogr.cpp index b18e9ee187..b4531f4763 100644 --- a/mapogr.cpp +++ b/mapogr.cpp @@ -2332,7 +2332,6 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps filter = msStringConcatenate(filter, ")"); } - bool bOffsetAlreadyAdded = false; // use spatial index if (psInfo->dialect && bIsValidRect ) { if (EQUAL(psInfo->dialect, "PostgreSQL")) { @@ -2429,7 +2428,7 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps select = msStringConcatenate(select, szLimit); } - if ( !bOffsetAlreadyAdded && psInfo->bPaging && layer->startindex > 0 ) { + if ( psInfo->bPaging && layer->startindex > 0 ) { char szOffset[50]; snprintf(szOffset, sizeof(szOffset), " OFFSET %d", layer->startindex-1); select = msStringConcatenate(select, szOffset); diff --git a/mapproject.c b/mapproject.c index 1eea31badc..d81a9a704b 100644 --- a/mapproject.c +++ b/mapproject.c @@ -1620,10 +1620,7 @@ int msProjectLine(projectionObj *in, projectionObj *out, lineObj *line) int msProjectLineEx(reprojectionObj* reprojector, lineObj *line) { - int i, be_careful = 1; - - if( be_careful ) - be_careful = reprojector->out->proj != NULL && + int be_careful = reprojector->out->proj != NULL && msProjIsGeographicCRS(reprojector->out) && !msProjIsGeographicCRS(reprojector->in); @@ -1632,7 +1629,7 @@ int msProjectLineEx(reprojectionObj* reprojector, lineObj *line) startPoint = line->point[0]; - for(i=0; inumpoints; i++) { + for(int i=0; inumpoints; i++) { double dist; thisPoint = line->point[i]; @@ -1658,7 +1655,7 @@ int msProjectLineEx(reprojectionObj* reprojector, lineObj *line) } } } else { - for(i=0; inumpoints; i++) { + for(int i=0; inumpoints; i++) { if( msProjectPointEx(reprojector, &(line->point[i])) == MS_FAILURE ) return MS_FAILURE; } diff --git a/mapshape.c b/mapshape.c index f91bc2c4fd..da987957a3 100644 --- a/mapshape.c +++ b/mapshape.c @@ -212,6 +212,7 @@ SHPHandle msSHPOpen( const char * pszLayer, const char * pszAccess ) /* Establish the byte order on this machine. */ /* -------------------------------------------------------------------- */ i = 1; + /* cppcheck-suppress knownConditionTrueFalse */ if( *((uchar *) &i) == 1 ) bBigEndian = MS_FALSE; else @@ -460,6 +461,7 @@ SHPHandle msSHPCreate( const char * pszLayer, int nShapeType ) /* Establish the byte order on this system. */ /* -------------------------------------------------------------------- */ i = 1; + /* cppcheck-suppress knownConditionTrueFalse */ if( *((uchar *) &i) == 1 ) bBigEndian = MS_FALSE; else diff --git a/mapsymbol.c b/mapsymbol.c index 4c413c141f..e9c5d606ce 100644 --- a/mapsymbol.c +++ b/mapsymbol.c @@ -642,12 +642,10 @@ int msGetCharacterSize(mapObj *map, char* font, int size, char *character, rectO codepoint = msGetGlyphIndex(face,unicode); glyph = msGetGlyphByIndex(face,size,codepoint); if(MS_UNLIKELY(!glyph)) return MS_FAILURE; - if(glyph) { - r->minx = glyph->metrics.minx; - r->maxx = glyph->metrics.maxx; - r->miny = - glyph->metrics.maxy; - r->maxy = - glyph->metrics.miny; - } + r->minx = glyph->metrics.minx; + r->maxx = glyph->metrics.maxx; + r->miny = - glyph->metrics.maxy; + r->maxy = - glyph->metrics.miny; return MS_SUCCESS; } diff --git a/maptemplate.c b/maptemplate.c index abf2bd3c70..22b0a87091 100644 --- a/maptemplate.c +++ b/maptemplate.c @@ -3337,7 +3337,7 @@ char *generateLegendTemplate(mapservObj *mapserv) if(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->group && strcmp(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->group, papszGroups[i]) == 0) { /* for all classes in layer */ - if(legClassHtml) { + for (k=0; kmap, mapserv->map->layerorder[j])->numclasses; k++) { /* process all class tags */ if(!GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->class[k]->name) @@ -3362,7 +3362,7 @@ char *generateLegendTemplate(mapservObj *mapserv) legClassHtmlCopy = NULL; } } - } + } } } diff --git a/maptree.c b/maptree.c index 8f3a434af5..70a4664bfb 100644 --- a/maptree.c +++ b/maptree.c @@ -95,6 +95,7 @@ SHPTreeHandle msSHPDiskTreeOpen(const char * pszTree, int debug) /* Establish the byte order on this machine. */ /* -------------------------------------------------------------------- */ i = 1; + /* cppcheck-suppress knownConditionTrueFalse */ if( *((uchar *) &i) == 1 ) bBigEndian = MS_FALSE; else @@ -763,6 +764,7 @@ int msWriteTree(treeObj *tree, char *filename, int B_order) /* Establish the byte order on this machine. */ /* -------------------------------------------------------------------- */ i = 1; + /* cppcheck-suppress knownConditionTrueFalse */ if( *((uchar *) &i) == 1 ) mtBigEndian = MS_FALSE; else diff --git a/mapunion.cpp b/mapunion.cpp index 0392bf08d4..80af58dbed 100644 --- a/mapunion.cpp +++ b/mapunion.cpp @@ -458,10 +458,7 @@ int msUnionLayerNextShape(layerObj * const layer, shapeObj *shape) if(layerinfo->classIndex < 0 || layerinfo->classIndex >= srclayer->numclasses) { /* this shape is not visible, skip it */ msFreeShape(shape); - if (rv == MS_SUCCESS) - continue; - else - break; + continue; } if(srclayer->styleitem && strcasecmp(srclayer->styleitem, "AUTO") != 0) { /* Generic feature style handling as per RFC-61 */ diff --git a/mapwfslayer.c b/mapwfslayer.c index e5db8c7887..db99ec9a0f 100644 --- a/mapwfslayer.c +++ b/mapwfslayer.c @@ -199,8 +199,7 @@ static wfsParamsObj *msBuildRequestParams(mapObj *map, layerObj *lp, msProjectRect(&(map->projection), &(lp->projection), &bbox); } - if (bbox_ret != NULL) - *bbox_ret = bbox; + *bbox_ret = bbox; return psParams; @@ -302,7 +301,7 @@ static char *msBuildWFSLayerGetURL(mapObj *map, layerObj *lp, rectObj *bbox, char *pszURL = NULL, *pszOnlineResource=NULL; const char *pszTmp; char *pszVersion, *pszService, *pszTypename = NULL; - int bVersionInConnection = 0, bServiceInConnection = 0; + int bVersionInConnection = 0; int bTypenameInConnection = 0; size_t bufferSize = 0; @@ -403,8 +402,7 @@ static char *msBuildWFSLayerGetURL(mapObj *map, layerObj *lp, rectObj *bbox, snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&VERSION=%s", pszVersion); /* SERVICE */ - if (!bServiceInConnection) - snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&SERVICE=%s", pszService); + snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&SERVICE=%s", pszService); /* TYPENAME */ if (!bTypenameInConnection) diff --git a/shptree.c b/shptree.c index 60fe30948a..d23878e8cb 100644 --- a/shptree.c +++ b/shptree.c @@ -82,6 +82,7 @@ int main(int argc, char *argv[]) /* index format */ /* -------------------------------------------------------------------- */ i = 1; + /* cppcheck-suppress knownConditionTrueFalse */ if( *((uchar *) &i) == 1 ) byte_order = MS_NEW_LSB_ORDER; else