Skip to content

Commit f89e386

Browse files
[Backport branch-7-6] Fix most of remaining Coverity scan warnings with high priority (#6307)
1 parent b128dac commit f89e386

File tree

8 files changed

+31
-18
lines changed

8 files changed

+31
-18
lines changed

mapcontext.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,6 @@ int msLoadMapContextGeneral(mapObj *map, CPLXMLNode *psGeneral,
811811
int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion,
812812
char *filename, int unique_layer_names)
813813
{
814-
char *pszProj=NULL;
815814
char *pszValue;
816815
const char *pszHash;
817816
char *pszName=NULL;
@@ -970,7 +969,7 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion,
970969
pszHash = msLookupHashTable(&(layer->metadata), "wms_srs");
971970
if(((pszHash == NULL) || (strcasecmp(pszHash, "") == 0)) &&
972971
map->projection.numargs != 0) {
973-
pszProj = map->projection.args[map->projection.numargs-1];
972+
char* pszProj = map->projection.args[map->projection.numargs-1];
974973

975974
if(pszProj != NULL) {
976975
if(strncasecmp(pszProj, "AUTO:", 5) == 0) {
@@ -987,6 +986,7 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion,
987986
pszProj);
988987
}
989988
}
989+
msFree(pszProj);
990990
}
991991
}
992992

mapcpl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ void *msGetSymbol( const char * pszLibrary, const char * pszSymbolName )
195195
return NULL;
196196
}
197197

198+
/* We accept leakage of pLibrary */
199+
/* coverity[leaked_storage] */
198200
return( pSymbol );
199201
}
200202

mapfile.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,12 +1933,8 @@ char* msWriteLabelToString(labelObj *label)
19331933

19341934
void msInitExpression(expressionObj *exp)
19351935
{
1936+
memset(exp, 0, sizeof(*exp));
19361937
exp->type = MS_STRING;
1937-
exp->string = NULL;
1938-
exp->native_string = NULL;
1939-
exp->compiled = MS_FALSE;
1940-
exp->flags = 0;
1941-
exp->tokens = exp->curtoken = NULL;
19421938
}
19431939

19441940
void msFreeExpressionTokens(expressionObj *exp)

mapogcsld.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4716,8 +4716,8 @@ char *msSLDGetAttributeNameOrValue(char *pszExpression,
47164716
} else
47174717
pszAttributeName[iValue++] = pszExpression[i];
47184718
}
4719-
pszAttributeName[iValue] = '\0';
47204719
}
4720+
pszAttributeName[iValue] = '\0';
47214721
}
47224722
msFreeCharArray(aszValues, nTokens);
47234723
} else if (bOneCharCompare == 0) {
@@ -4744,8 +4744,8 @@ char *msSLDGetAttributeNameOrValue(char *pszExpression,
47444744
} else
47454745
pszAttributeName[iValue++] = pszExpression[i];
47464746
}
4747-
pszAttributeName[iValue] = '\0';
47484747
}
4748+
pszAttributeName[iValue] = '\0';
47494749
}
47504750

47514751
/* -------------------------------------------------------------------- */

mapogcsos.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,16 +2931,22 @@ int msSOSParseRequest(mapObj *map, cgiRequestObj *request, sosParamsObj *sospara
29312931
if (psXPathTmp)
29322932
sosparams->pszRequest = msStrdup("GetCapabilities");
29332933

2934+
xmlXPathFreeObject(psXPathTmp);
2935+
29342936
psXPathTmp = msLibXml2GetXPath(doc, context, (xmlChar *)"/sos:DescribeSensor");
29352937

29362938
if (psXPathTmp)
29372939
sosparams->pszRequest = msStrdup("DescribeSensor");
29382940

2941+
xmlXPathFreeObject(psXPathTmp);
2942+
29392943
psXPathTmp = msLibXml2GetXPath(doc, context, (xmlChar *)"/sos:GetObservation");
29402944

29412945
if (psXPathTmp)
29422946
sosparams->pszRequest = msStrdup("GetObservation");
29432947

2948+
xmlXPathFreeObject(psXPathTmp);
2949+
29442950
psXPathTmp = msLibXml2GetXPath(doc, context, (xmlChar *)"/sos:DescribeObservationType");
29452951

29462952
if (psXPathTmp)

mapogr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,7 +3080,10 @@ int msOGRFileReadTile( layerObj *layer, msOGRFileInfo *psInfo,
30803080

30813081
#ifndef IGNORE_MISSING_DATA
30823082
if( psTileInfo == NULL && targetTile == -1 )
3083+
{
3084+
msFree(pszSRS);
30833085
goto NextFile;
3086+
}
30843087
#endif
30853088

30863089
if( psTileInfo == NULL )

mapstring.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ int msLayerEncodeShapeAttributes( layerObj *layer, shapeObj *shape) {
21842184
iconv_t cd = NULL;
21852185
const char *inp;
21862186
char *outp, *out = NULL;
2187-
size_t len, bufsize, bufleft, iconv_status;
2187+
size_t len, bufsize, bufleft;
21882188
int i;
21892189

21902190
if( !layer->encoding || !*layer->encoding || !strcasecmp(layer->encoding, "UTF-8"))
@@ -2198,6 +2198,7 @@ int msLayerEncodeShapeAttributes( layerObj *layer, shapeObj *shape) {
21982198
}
21992199

22002200
for(i=0;i <shape->numvalues; i++) {
2201+
int failedIconv = FALSE;
22012202
if(!shape->values[i] || (len = strlen(shape->values[i]))==0) {
22022203
continue; /* Nothing to do */
22032204
}
@@ -2210,15 +2211,18 @@ int msLayerEncodeShapeAttributes( layerObj *layer, shapeObj *shape) {
22102211
outp = out;
22112212

22122213
bufleft = bufsize;
2213-
iconv_status = -1;
22142214

22152215
while (len > 0) {
2216-
iconv_status = iconv(cd, (char**)&inp, &len, &outp, &bufleft);
2217-
if(iconv_status == -1) {
2218-
msFree(out);
2219-
continue; /* silently ignore failed conversions */
2216+
const size_t iconv_status = iconv(cd, (char**)&inp, &len, &outp, &bufleft);
2217+
if(iconv_status == (size_t)(-1)) {
2218+
failedIconv = TRUE;
2219+
break;
22202220
}
22212221
}
2222+
if( failedIconv ) {
2223+
msFree(out);
2224+
continue; /* silently ignore failed conversions */
2225+
}
22222226
out[bufsize - bufleft] = '\0';
22232227
msFree(shape->values[i]);
22242228
shape->values[i] = out;

mapwfs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5179,10 +5179,12 @@ int msWFSParseRequest(mapObj *map, cgiRequestObj *request, owsRequestObj *ows_re
51795179
}
51805180
/* these are unsupported requests. Just set the */
51815181
/* request value and return; */
5182-
else if (msWFSGetIndexUnsupportedOperation(psOperation->pszValue) >= 0) {
5182+
else {
51835183
int idx = msWFSGetIndexUnsupportedOperation(psOperation->pszValue);
5184-
wfsparams->pszRequest = msStrdup(wfsUnsupportedOperations[idx]);
5185-
break;
5184+
if( idx >= 0 ) {
5185+
wfsparams->pszRequest = msStrdup(wfsUnsupportedOperations[idx]);
5186+
break;
5187+
}
51865188
}
51875189
}
51885190
}

0 commit comments

Comments
 (0)