Skip to content

Commit

Permalink
Remove useless checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 21, 2021
1 parent 6dfa31f commit 7ce7752
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 74 deletions.
5 changes: 1 addition & 4 deletions classobject.c
Expand Up @@ -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--) {
Expand All @@ -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;
}
}

Expand Down
5 changes: 1 addition & 4 deletions layerobject.c
Expand Up @@ -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 */
Expand All @@ -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;
}
}

Expand Down
3 changes: 0 additions & 3 deletions mapcontext.c
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion mapdebug.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mapdrawgdal.c
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion maperror.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mapgeos.c
Expand Up @@ -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;
Expand Down
17 changes: 12 additions & 5 deletions mapio.c
Expand Up @@ -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);
Expand All @@ -428,6 +428,8 @@ int msIO_vfprintf( FILE *fp, const char *format, va_list ap )
return -1;
}

char* outbuf = workBuf;

#else

#ifdef va_copy
Expand All @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions maplabel.c
Expand Up @@ -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--) {
Expand All @@ -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;
}
}

Expand Down
5 changes: 1 addition & 4 deletions mapobject.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
26 changes: 5 additions & 21 deletions mapogcfilter.cpp
Expand Up @@ -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) {
Expand All @@ -170,9 +168,7 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char
pszTmpExpression = msStringConcatenate(pszTmpExpression, "(");
for (i=0; i<numelements; i++) {
pszTmpExpression = msStringConcatenate(pszTmpExpression, "(");
if (bSqlLayer)
pszTmpExpression = msStringConcatenate(pszTmpExpression, item);
else {
{
if (bIscharacter)
pszTmpExpression = msStringConcatenate(pszTmpExpression, "\"");
pszTmpExpression = msStringConcatenate(pszTmpExpression, "[");
Expand All @@ -182,9 +178,6 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char
pszTmpExpression = msStringConcatenate(pszTmpExpression, "\"");
}
if (bIscharacter) {
if (bSqlLayer)
pszTmpExpression = msStringConcatenate(pszTmpExpression, " = '");
else
pszTmpExpression = msStringConcatenate(pszTmpExpression, " = \"");
} else
pszTmpExpression = msStringConcatenate(pszTmpExpression, " = ");
Expand All @@ -193,9 +186,6 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char
pszTmpExpression = msStringConcatenate(pszTmpExpression, pszEscapedStr);

if (bIscharacter) {
if (bSqlLayer)
pszTmpExpression = msStringConcatenate(pszTmpExpression, "'");
else
pszTmpExpression = msStringConcatenate(pszTmpExpression, "\"");
}
pszTmpExpression = msStringConcatenate(pszTmpExpression, ")");
Expand Down Expand Up @@ -228,9 +218,7 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char
minval = atof(papszRangeElements[0]);
maxval = atof(papszRangeElements[1]);
*/
if (bSqlLayer)
pszTmpExpression = msStringConcatenate(pszTmpExpression, item);
else {
{
pszTmpExpression = msStringConcatenate(pszTmpExpression, "[");
pszTmpExpression = msStringConcatenate(pszTmpExpression, item);
pszTmpExpression = msStringConcatenate(pszTmpExpression, "]");
Expand All @@ -245,9 +233,7 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char

pszTmpExpression = msStringConcatenate(pszTmpExpression, " AND ");

if (bSqlLayer)
pszTmpExpression = msStringConcatenate(pszTmpExpression, item);
else {
{
pszTmpExpression = msStringConcatenate(pszTmpExpression, "[");
pszTmpExpression = msStringConcatenate(pszTmpExpression, item);
pszTmpExpression = msStringConcatenate(pszTmpExpression, "]");
Expand All @@ -263,9 +249,7 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char
pszTmpExpression = msStringConcatenate(pszTmpExpression, ")");
} else if (nrangeelements == 1) {
pszTmpExpression = msStringConcatenate(pszTmpExpression, "(");
if (bSqlLayer)
pszTmpExpression = msStringConcatenate(pszTmpExpression, item);
else {
{
pszTmpExpression = msStringConcatenate(pszTmpExpression, "[");
pszTmpExpression = msStringConcatenate(pszTmpExpression, item);
pszTmpExpression = msStringConcatenate(pszTmpExpression, "]");
Expand Down
2 changes: 2 additions & 0 deletions mapogcsld.c
Expand Up @@ -952,6 +952,7 @@ int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer, const char* pszUserSty
LOOP_ON_CHILD_ELEMENT(psRoot, psRasterSymbolizer, "RasterSymbolizer")
{
msSLDParseRasterSymbolizer(psRasterSymbolizer, psLayer, pszUserStyleName);
/* cppcheck-suppress knownConditionTrueFalse */
if (nSymbolizer == 0)
{
psLayer->type = MS_LAYER_RASTER;
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions mapogr.cpp
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions mapproject.c
Expand Up @@ -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);

Expand All @@ -1632,7 +1629,7 @@ int msProjectLineEx(reprojectionObj* reprojector, lineObj *line)

startPoint = line->point[0];

for(i=0; i<line->numpoints; i++) {
for(int i=0; i<line->numpoints; i++) {
double dist;

thisPoint = line->point[i];
Expand All @@ -1658,7 +1655,7 @@ int msProjectLineEx(reprojectionObj* reprojector, lineObj *line)
}
}
} else {
for(i=0; i<line->numpoints; i++) {
for(int i=0; i<line->numpoints; i++) {
if( msProjectPointEx(reprojector, &(line->point[i])) == MS_FAILURE )
return MS_FAILURE;
}
Expand Down
2 changes: 2 additions & 0 deletions mapshape.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions mapsymbol.c
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions maptemplate.c
Expand Up @@ -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; k<GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->numclasses; k++) {
/* process all class tags */
if(!GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->class[k]->name)
Expand All @@ -3362,7 +3362,7 @@ char *generateLegendTemplate(mapservObj *mapserv)
legClassHtmlCopy = NULL;
}
}
}

}
}
}
Expand Down
2 changes: 2 additions & 0 deletions maptree.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions mapunion.cpp
Expand Up @@ -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 */
Expand Down

0 comments on commit 7ce7752

Please sign in to comment.