diff --git a/mapagg.cpp b/mapagg.cpp index 035647e84f..661461b48c 100755 --- a/mapagg.cpp +++ b/mapagg.cpp @@ -281,9 +281,6 @@ template const mapserver::trans_affine& mtx, PathStorage& path) { - FT_Vector v_last; - FT_Vector v_control; - FT_Vector v_start; double x1, y1, x2, y2, x3, y3; FT_Vector* point; @@ -303,10 +300,9 @@ template last = outline.contours[n]; limit = outline.points + last; - v_start = outline.points[first]; - v_last = outline.points[last]; + FT_Vector v_start = outline.points[first]; - v_control = v_start; + FT_Vector v_control = v_start; point = outline.points + first; tags = outline.tags + first; @@ -318,6 +314,8 @@ template // check first point to determine origin if( tag == FT_CURVE_TAG_CONIC) { + const FT_Vector v_last = outline.points[last]; + // first point is conic control. Yes, this happens. if(FT_CURVE_TAG(outline.tags[last]) == FT_CURVE_TAG_ON) { @@ -332,8 +330,6 @@ template // for closure v_start.x = (v_start.x + v_last.x) / 2; v_start.y = (v_start.y + v_last.y) / 2; - - v_last = v_start; } point--; tags--; diff --git a/mapcluster.c b/mapcluster.c index 953d946215..548b0e74ed 100644 --- a/mapcluster.c +++ b/mapcluster.c @@ -1386,7 +1386,8 @@ int msClusterLayerClose(layerObj *layer) #ifndef USE_CLUSTER_EXTERNAL /* switch back to the source layer vtable */ - msInitializeVirtualTable(layer); + if( msInitializeVirtualTable(layer) != MS_SUCCESS ) + return MS_FAILURE; #endif return MS_SUCCESS; diff --git a/mapcrypto.c b/mapcrypto.c index 0e665c947a..cc7dd308dc 100644 --- a/mapcrypto.c +++ b/mapcrypto.c @@ -193,7 +193,10 @@ int msGenerateEncryptionKey(unsigned char *k) srand( (unsigned int) time( NULL )); for(i=0; iconnectiontype == MS_WMS) { #ifdef USE_WMS_LYR if(MS_RENDERER_PLUGIN(image->format) || MS_RENDERER_RAWDATA(image->format)) + { + assert(pasOWSReqInfo); status = msDrawWMSLayerLow(map->layerorder[i], pasOWSReqInfo, numOWSRequests, map, lp, image); + } #else status = MS_FAILURE; diff --git a/mapkmlrenderer.h b/mapkmlrenderer.h index d4425b6d0e..8a442c7f5a 100644 --- a/mapkmlrenderer.h +++ b/mapkmlrenderer.h @@ -41,73 +41,73 @@ class KmlRenderer { private: - const char *pszLayerDescMetadata; /*if the kml_description is set*/ - char **papszLayerIncludeItems; - int nIncludeItems; - char **papszLayerExcludeItems; - int nExcludeItems; - const char *pszLayerNameAttributeMetadata; + const char *pszLayerDescMetadata = nullptr; /*if the kml_description is set*/ + char **papszLayerIncludeItems = nullptr; + int nIncludeItems = 0; + char **papszLayerExcludeItems = nullptr; + int nExcludeItems = 0; + const char *pszLayerNameAttributeMetadata = nullptr; protected: // map properties - int Width, Height; - rectObj MapExtent; - double MapCellsize; - colorObj BgColor; - char MapPath[MS_MAXPATHLEN]; + int Width = 0, Height = 0; + rectObj MapExtent = {0,0,0,0}; + double MapCellsize = 0; + colorObj BgColor = {0,0,0,0}; + char MapPath[MS_MAXPATHLEN] = {0}; // xml nodes pointers - xmlDocPtr XmlDoc; - xmlNodePtr DocNode; - xmlNodePtr LayerNode; - xmlNodePtr GroundOverlayNode; - - xmlNodePtr PlacemarkNode; - xmlNodePtr GeomNode; - xmlNodePtr DescriptionNode; - - int CurrentShapeIndex; - int CurrentDrawnShapeIndex; - char *CurrentShapeName; - char **Items; - int NumItems; - int DumpAttributes; + xmlDocPtr XmlDoc = nullptr; + xmlNodePtr DocNode = nullptr; + xmlNodePtr LayerNode = nullptr; + xmlNodePtr GroundOverlayNode = nullptr; + + xmlNodePtr PlacemarkNode = nullptr; + xmlNodePtr GeomNode = nullptr; + xmlNodePtr DescriptionNode = nullptr; + + int CurrentShapeIndex = 0; + int CurrentDrawnShapeIndex = 0; + char *CurrentShapeName = nullptr; + char **Items = nullptr; + int NumItems = 0; + int DumpAttributes = 0; // placemark symbology - hashTableObj *StyleHashTable; + hashTableObj *StyleHashTable = nullptr; - colorObj LabelColor; - strokeStyleObj *LineStyle; - int numLineStyle; - colorObj PolygonColor; + colorObj LabelColor = {0,0,0,0}; + strokeStyleObj *LineStyle = nullptr; + int numLineStyle = 0; + colorObj PolygonColor = {0,0,0,0}; - char SymbolName[128]; - char SymbolUrl[128]; + char SymbolName[128] = {0}; + char SymbolUrl[128] = {0}; enum { NumSymbologyFlag = 4}; - char SymbologyFlag[NumSymbologyFlag]; + char SymbologyFlag[NumSymbologyFlag] = {0,0,0,0}; enum symbFlagsEnum { Label, Line, Polygon, Symbol }; - int FirstLayer; + int FirstLayer = 0; - mapObj *map; - layerObj *currentLayer; + mapObj *map = nullptr; + layerObj *currentLayer = nullptr; - int AltitudeMode; - int Tessellate; - int Extrude; + int AltitudeMode = 0; + int Tessellate = 0; + int Extrude = 0; enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute }; /**True if elevation is taken from a feature attribute*/ - bool mElevationFromAttribute; + bool mElevationFromAttribute = false; /**Attribute index of elevation (or -1 if elevation is not attribute driven*/ - int mElevationAttributeIndex; - double mCurrentElevationValue; + int mElevationAttributeIndex = 0; + double mCurrentElevationValue = 0; - outputFormatObj *aggFormat; + outputFormatObj *aggFormat = nullptr; protected: diff --git a/maplayer.c b/maplayer.c index 33fb05eadb..4a56db0dfa 100644 --- a/maplayer.c +++ b/maplayer.c @@ -1174,7 +1174,7 @@ int msLayerGetFeatureStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* if (layer->styleitem && layer->styleitemindex >=0) { stylestring = msStrdup(shape->values[layer->styleitemindex]); } - else if (strncasecmp(layer->styleitem,"javascript://",13) == 0) { + else if (layer->styleitem && strncasecmp(layer->styleitem,"javascript://",13) == 0) { #ifdef USE_V8_MAPSCRIPT char *filename = layer->styleitem+13; diff --git a/mapogcsos.c b/mapogcsos.c index b8302b4893..875875c0e7 100644 --- a/mapogcsos.c +++ b/mapogcsos.c @@ -284,7 +284,7 @@ void msSOSAddPropertyNode(xmlNsPtr psNsSwe, xmlNsPtr psNsXLink, xmlNodePtr psPar pszValue = msOWSLookupMetadata(&(lp->metadata), "S", "observedproperty_name"); if (pszValue) - psNode = xmlNewTextChild(psCompNode, psNsGml, + (void) xmlNewTextChild(psCompNode, psNsGml, BAD_CAST "name", BAD_CAST pszValue); /* add components */ diff --git a/mappostgis.cpp b/mappostgis.cpp index f33f721a49..b16ee2587c 100644 --- a/mappostgis.cpp +++ b/mappostgis.cpp @@ -347,6 +347,8 @@ wkbSkipGeometry(wkbObj *w) } case WKB_POLYGON: { const int nrings = wkbReadInt(w); + if( nrings > (int)((w->size - (w->ptr - w->wkb)) / 4) ) + return; for ( int i = 0; i < nrings; i++ ) { const int npoints = wkbReadInt(w); w->ptr += npoints * nCoordDim * sizeof(double); diff --git a/mapprimitive.c b/mapprimitive.c index 9468f03a5f..50b4365e22 100644 --- a/mapprimitive.c +++ b/mapprimitive.c @@ -333,7 +333,7 @@ int msAddPointToLine(lineObj *line, pointObj *point ) return MS_SUCCESS; } -int msAddLine(shapeObj *p, lineObj *new_line) +int msAddLine(shapeObj *p, const lineObj *new_line) { lineObj lineCopy; @@ -341,7 +341,8 @@ int msAddLine(shapeObj *p, lineObj *new_line) lineCopy.point = (pointObj *) malloc(new_line->numpoints*sizeof(pointObj)); MS_CHECK_ALLOC(lineCopy.point, new_line->numpoints*sizeof(pointObj), MS_FAILURE); - memcpy( lineCopy.point, new_line->point, sizeof(pointObj) * new_line->numpoints ); + if( new_line->point ) + memcpy( lineCopy.point, new_line->point, sizeof(pointObj) * new_line->numpoints ); // cppcheck-suppress memleak return msAddLineDirectly( p, &lineCopy ); diff --git a/mapquantization.c b/mapquantization.c index 68a57e75c3..407a641eb5 100644 --- a/mapquantization.c +++ b/mapquantization.c @@ -495,10 +495,10 @@ mediancut( acolorhist_vector achv, int colors, int sum, unsigned char maxval, in register long r = 0, g = 0, b = 0, a = 0, sum = 0; for ( i = 0; i < clrs; ++i ) { - r += PAM_GETR( achv[indx + i].acolor ) * achv[indx + i].value; - g += PAM_GETG( achv[indx + i].acolor ) * achv[indx + i].value; - b += PAM_GETB( achv[indx + i].acolor ) * achv[indx + i].value; - a += PAM_GETA( achv[indx + i].acolor ) * achv[indx + i].value; + r += (long)PAM_GETR( achv[indx + i].acolor ) * achv[indx + i].value; + g += (long)PAM_GETG( achv[indx + i].acolor ) * achv[indx + i].value; + b += (long)PAM_GETB( achv[indx + i].acolor ) * achv[indx + i].value; + a += (long)PAM_GETA( achv[indx + i].acolor ) * achv[indx + i].value; sum += achv[indx + i].value; } if(sum>0) { diff --git a/mapquery.c b/mapquery.c index 5110240220..8798825408 100644 --- a/mapquery.c +++ b/mapquery.c @@ -30,6 +30,8 @@ #include "mapserver.h" #include "mapows.h" +#include "limits.h" + /* This object is used by the various mapQueryXXXXX() functions. It stores * the total amount of shapes and their RAM footprint, when they are cached * in the resultCacheObj* of layers. This is the total number accross all queried @@ -290,7 +292,7 @@ static int loadQueryResults(mapObj *map, FILE *stream) { int i, j, k, n=0; - if(1 != fread(&n, sizeof(int), 1, stream)) { + if(1 != fread(&n, sizeof(int), 1, stream) || n > INT_MAX - 1) { msSetError(MS_MISCERR,"failed to read query count from query file stream", "loadQueryResults()"); return MS_FAILURE; } @@ -445,7 +447,8 @@ static int loadQueryParams(mapObj *map, FILE *stream) if(fscanf(stream, "%d\n", &numlines) != 1) goto parse_error; for(i=0; i INT_MAX / (int)sizeof(pointObj)) goto parse_error; line.numpoints = numpoints; line.point = (pointObj *) msSmallMalloc(line.numpoints*sizeof(pointObj)); diff --git a/mapserv.c b/mapserv.c index 288af3af47..b32f1ae4f7 100644 --- a/mapserv.c +++ b/mapserv.c @@ -195,6 +195,7 @@ int main(int argc, char *argv[]) } else if( strncmp(argv[iArg], "QUERY_STRING=", 13) == 0 ) { /* Debugging hook... pass "QUERY_STRING=..." on the command-line */ putenv( "REQUEST_METHOD=GET" ); + /* coverity[tainted_string] */ putenv( argv[iArg] ); } else if (strcmp(argv[iArg], "--h") == 0 || strcmp(argv[iArg], "--help") == 0) { printf("Usage: mapserv [--help] [-v] [-nh] [QUERY_STRING=value]\n"); diff --git a/mapserver.h b/mapserver.h index c003a03bf1..a22b12b508 100755 --- a/mapserver.h +++ b/mapserver.h @@ -2443,7 +2443,7 @@ extern "C" { MS_DLL_EXPORT int WARN_UNUSED msLineLabelPath(mapObj *map, imageObj *img, lineObj *p, textSymbolObj *ts, struct line_lengths *ll, struct label_follow_result *lfr, labelObj *lbl); MS_DLL_EXPORT int WARN_UNUSED msLineLabelPoint(mapObj *map, lineObj *p, textSymbolObj *ts, struct line_lengths *ll, struct label_auto_result *lar, labelObj *lbl, double resolutionfactor); MS_DLL_EXPORT int msPolygonLabelPoint(shapeObj *p, pointObj *lp, double min_dimension); - MS_DLL_EXPORT int msAddLine(shapeObj *p, lineObj *new_line); + MS_DLL_EXPORT int msAddLine(shapeObj *p, const lineObj *new_line); MS_DLL_EXPORT int msAddLineDirectly(shapeObj *p, lineObj *new_line); MS_DLL_EXPORT int msAddPointToLine(lineObj *line, pointObj *point ); MS_DLL_EXPORT double msGetPolygonArea(shapeObj *p); diff --git a/mapshape.c b/mapshape.c index 468b37f2e3..ab4c8522d8 100644 --- a/mapshape.c +++ b/mapshape.c @@ -1351,7 +1351,7 @@ void msSHPReadShape( SHPHandle psSHP, int hEntity, shapeObj *shape ) shape->line[i].numpoints = nPoints - psSHP->panParts[i]; else shape->line[i].numpoints = psSHP->panParts[i+1] - psSHP->panParts[i]; - if (shape->line[i].numpoints <= 0) { + if (shape->line[i].numpoints <= 0 || shape->line[i].numpoints > nPoints) { msSetError(MS_SHPERR, "Corrupted .shp file : shape %d, shape->line[%d].numpoints=%d", "msSHPReadShape()", hEntity, i, shape->line[i].numpoints); while(--i >= 0) diff --git a/maptemplate.c b/maptemplate.c index 6dc667a290..9cd1713d95 100644 --- a/maptemplate.c +++ b/maptemplate.c @@ -27,6 +27,8 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#define NEED_IGNORE_RET_VAL + #include "maptemplate.h" #include "maphash.h" #include "mapserver.h" @@ -719,7 +721,7 @@ int processIfTag(char **pszInstr, hashTableObj *ht, int bLastPass) pszPatIn = findTag(pszTmp+1, "if"); pszPatOut = strstr(pszTmp+1, "[/if]"); - } while (pszTmp != NULL && nInst > 0); + } while (nInst > 0); /* get the then string (if expression is true) */ if(getInlineTag("if", pszStart, &pszThen) != MS_SUCCESS) { @@ -790,9 +792,7 @@ int processIfTag(char **pszInstr, hashTableObj *ht, int bLastPass) return MS_FAILURE; } - if(pszIfTag) - free(pszIfTag); - + free(pszIfTag); pszIfTag = NULL; } @@ -3094,17 +3094,31 @@ char *generateLegendTemplate(mapservObj *mapserv) /* open template */ if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath, mapserv->map->legend.template), "r")) == NULL) { msSetError(MS_IOERR, "Error while opening template file.", "generateLegendTemplate()"); - if(pszResult) - free(pszResult); + free(pszResult); pszResult=NULL; goto error; } fseek(stream, 0, SEEK_END); - length = ftell(stream); + long lengthLong = ftell(stream); rewind(stream); + if( lengthLong < 0 || lengthLong > INT_MAX - 1 ) + { + msSetError(MS_IOERR, "Too large template file.", "generateLegendTemplate()"); + free(pszResult); + pszResult=NULL; + goto error; + } + length = (int)lengthLong; - file = (char*)msSmallMalloc(length + 1); + file = (char*)malloc(length + 1); + if( file == NULL ) + { + msSetError(MS_IOERR, "Cannot allocate memory for template file.", "generateLegendTemplate()"); + free(pszResult); + pszResult=NULL; + goto error; + } /* * Read all the template file @@ -4889,7 +4903,7 @@ char *msProcessQueryTemplate(mapObj *map, int bGenerateImages, char **names, cha msGenerateImages(mapserv, MS_TRUE, MS_FALSE); mapserv->sendheaders = MS_FALSE; - msReturnTemplateQuery(mapserv, mapserv->map->web.queryformat, &pszBuffer); + IGNORE_RET_VAL(msReturnTemplateQuery(mapserv, mapserv->map->web.queryformat, &pszBuffer)); mapserv->map = NULL; mapserv->request->ParamNames = mapserv->request->ParamValues = NULL; diff --git a/maptree.c b/maptree.c index 70a4664bfb..c4386f3492 100644 --- a/maptree.c +++ b/maptree.c @@ -31,7 +31,7 @@ #include "mapserver.h" #include "maptree.h" - +#include /* -------------------------------------------------------------------- */ /* If the following is 0.5, nodes will be split in half. If it */ @@ -491,10 +491,13 @@ static void searchDiskTreeNode(SHPTreeHandle disktree, rectObj aoi, ms_bitarray if( fread( &numshapes, 4, 1, disktree->fp ) != 1 ) goto error; if ( disktree->needswap ) SwapWord ( 4, &numshapes ); + if( numshapes < 0 || numshapes > INT_MAX / 4 ) + goto error; if(!msRectOverlap(&rect, &aoi)) { /* skip rest of this node and sub-nodes */ offset += numshapes*sizeof(ms_int32) + sizeof(ms_int32); - fseek(disktree->fp, offset, SEEK_CUR); + if( fseek(disktree->fp, offset, SEEK_CUR) < 0 ) + goto error; return; } if(numshapes > 0) { @@ -597,6 +600,11 @@ treeNodeObj *readTreeNode( SHPTreeHandle disktree ) return NULL; } if ( disktree->needswap ) SwapWord ( 4, &node->numshapes ); + if ( node->numshapes < 0 || node->numshapes > INT_MAX / 4 ) + { + free(node); + return NULL; + } if( node->numshapes > 0 ) node->ids = (ms_int32 *)msSmallMalloc(sizeof(ms_int32)*node->numshapes); res = fread( node->ids, node->numshapes*4, 1, disktree->fp ); diff --git a/mapuvraster.c b/mapuvraster.c index 7dcfc77d57..1b724396fd 100644 --- a/mapuvraster.c +++ b/mapuvraster.c @@ -509,6 +509,8 @@ int msUVRASTERLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) if( CSLFetchNameValue( layer->processing, "UV_SPACING" ) != NULL ) { spacing = atoi(CSLFetchNameValue( layer->processing, "UV_SPACING" )); + if( spacing == 0 ) + spacing = 32; } width = (int)(layer->map->width/spacing); diff --git a/mapwfs11.cpp b/mapwfs11.cpp index 4b59b02c4d..34580f71ee 100644 --- a/mapwfs11.cpp +++ b/mapwfs11.cpp @@ -37,6 +37,8 @@ #include +template inline void IGNORE_RET_VAL(T) {} + /************************************************************************/ /* msWFSException11() */ /************************************************************************/ @@ -158,7 +160,7 @@ xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws, if(value) { n = strlen(value)+strlen(lp->name)+1+1; - valueToFree = (char *) msSmallMalloc(sizeof(char*)*n); + valueToFree = (char *) msSmallMalloc(n); snprintf(valueToFree, n, "%s:%s", value, lp->name); psNode = xmlNewTextChild(psRootNode, NULL, BAD_CAST "Name", BAD_CAST valueToFree); @@ -207,15 +209,15 @@ xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws, tokens = msStringSplit(valueToFree, ' ', &n); if (tokens && n > 0) { if( nWFSVersion == OWS_1_1_0 ) - psNode = xmlNewTextChild(psRootNode, NULL, BAD_CAST "DefaultSRS", BAD_CAST tokens[0]); + IGNORE_RET_VAL(xmlNewTextChild(psRootNode, NULL, BAD_CAST "DefaultSRS", BAD_CAST tokens[0])); else - psNode = xmlNewTextChild(psRootNode, NULL, BAD_CAST "DefaultCRS", BAD_CAST tokens[0]); + IGNORE_RET_VAL(xmlNewTextChild(psRootNode, NULL, BAD_CAST "DefaultCRS", BAD_CAST tokens[0])); for (i=1; i struct point_base { typedef T value_type; - T x,y; - point_base() {} + T x = 0,y = 0; + point_base() = default; point_base(T x_, T y_) : x(x_), y(y_) {} }; typedef point_base point_i; //-----point_i diff --git a/renderers/agg/include/agg_color_rgba.h b/renderers/agg/include/agg_color_rgba.h index a980414930..3a22def350 100644 --- a/renderers/agg/include/agg_color_rgba.h +++ b/renderers/agg/include/agg_color_rgba.h @@ -234,13 +234,13 @@ namespace mapserver typedef rgba8 self_type; - value_type r; - value_type g; - value_type b; - value_type a; + value_type r = 0; + value_type g = 0; + value_type b = 0; + value_type a = 0; //-------------------------------------------------------------------- - rgba8() {} + rgba8() = default; //-------------------------------------------------------------------- rgba8(unsigned r_, unsigned g_, unsigned b_, unsigned a_=base_mask) : diff --git a/renderers/agg/include/agg_conv_adaptor_vcgen.h b/renderers/agg/include/agg_conv_adaptor_vcgen.h index 44bc5c0f6b..4e5ab584ff 100644 --- a/renderers/agg/include/agg_conv_adaptor_vcgen.h +++ b/renderers/agg/include/agg_conv_adaptor_vcgen.h @@ -75,9 +75,9 @@ namespace mapserver Generator m_generator; Markers m_markers; status m_status; - unsigned m_last_cmd; - double m_start_x; - double m_start_y; + unsigned m_last_cmd = 0; + double m_start_x = 0; + double m_start_y = 0; }; diff --git a/renderers/agg/include/agg_curves.h b/renderers/agg/include/agg_curves.h index 6573591ff0..e6b2c251eb 100644 --- a/renderers/agg/include/agg_curves.h +++ b/renderers/agg/include/agg_curves.h @@ -35,13 +35,11 @@ namespace mapserver class curve3_inc { public: - curve3_inc() : - m_num_steps(0), m_step(0), m_scale(1.0) { } + curve3_inc() = default; curve3_inc(double x1, double y1, double x2, double y2, - double x3, double y3) : - m_num_steps(0), m_step(0), m_scale(1.0) + double x3, double y3) { init(x1, y1, x2, y2, x3, y3); } @@ -67,23 +65,23 @@ namespace mapserver unsigned vertex(double* x, double* y); private: - int m_num_steps; - int m_step; - double m_scale; - double m_start_x; - double m_start_y; - double m_end_x; - double m_end_y; - double m_fx; - double m_fy; - double m_dfx; - double m_dfy; - double m_ddfx; - double m_ddfy; - double m_saved_fx; - double m_saved_fy; - double m_saved_dfx; - double m_saved_dfy; + int m_num_steps = 0; + int m_step = 0; + double m_scale = 1; + double m_start_x = 0; + double m_start_y = 0; + double m_end_x = 0; + double m_end_y = 0; + double m_fx = 0; + double m_fy = 0; + double m_dfx = 0; + double m_dfy = 0; + double m_ddfx = 0; + double m_ddfy = 0; + double m_saved_fx = 0; + double m_saved_fy = 0; + double m_saved_dfx = 0; + double m_saved_dfy = 0; }; @@ -94,18 +92,11 @@ namespace mapserver class curve3_div { public: - curve3_div() : - m_approximation_scale(1.0), - m_angle_tolerance(0.0), - m_count(0) - {} + curve3_div() = default; curve3_div(double x1, double y1, double x2, double y2, - double x3, double y3) : - m_approximation_scale(1.0), - m_angle_tolerance(0.0), - m_count(0) + double x3, double y3) { init(x1, y1, x2, y2, x3, y3); } @@ -150,10 +141,10 @@ namespace mapserver double x3, double y3, unsigned level); - double m_approximation_scale; - double m_distance_tolerance_square; - double m_angle_tolerance; - unsigned m_count; + double m_approximation_scale = 1.0; + double m_distance_tolerance_square = 0; + double m_angle_tolerance = 0; + unsigned m_count = 0; pod_bvector m_points; }; @@ -194,20 +185,17 @@ namespace mapserver class curve4_inc { public: - curve4_inc() : - m_num_steps(0), m_step(0), m_scale(1.0) { } + curve4_inc() = default; curve4_inc(double x1, double y1, double x2, double y2, double x3, double y3, - double x4, double y4) : - m_num_steps(0), m_step(0), m_scale(1.0) + double x4, double y4) { init(x1, y1, x2, y2, x3, y3, x4, y4); } - curve4_inc(const curve4_points& cp) : - m_num_steps(0), m_step(0), m_scale(1.0) + curve4_inc(const curve4_points& cp) { init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); } @@ -239,27 +227,27 @@ namespace mapserver unsigned vertex(double* x, double* y); private: - int m_num_steps; - int m_step; - double m_scale; - double m_start_x; - double m_start_y; - double m_end_x; - double m_end_y; - double m_fx; - double m_fy; - double m_dfx; - double m_dfy; - double m_ddfx; - double m_ddfy; - double m_dddfx; - double m_dddfy; - double m_saved_fx; - double m_saved_fy; - double m_saved_dfx; - double m_saved_dfy; - double m_saved_ddfx; - double m_saved_ddfy; + int m_num_steps = 0; + int m_step = 0; + double m_scale = 1.0; + double m_start_x = 0.0; + double m_start_y = 0.0; + double m_end_x = 0.0; + double m_end_y = 0.0; + double m_fx = 0.0; + double m_fy = 0.0; + double m_dfx = 0.0; + double m_dfy = 0.0; + double m_ddfx = 0.0; + double m_ddfy = 0.0; + double m_dddfx = 0.0; + double m_dddfy = 0.0; + double m_saved_fx = 0.0; + double m_saved_fy = 0.0; + double m_saved_dfx = 0.0; + double m_saved_dfy = 0.0; + double m_saved_ddfx = 0.0; + double m_saved_ddfy = 0.0; }; @@ -374,29 +362,17 @@ namespace mapserver class curve4_div { public: - curve4_div() : - m_approximation_scale(1.0), - m_angle_tolerance(0.0), - m_cusp_limit(0.0), - m_count(0) - {} + curve4_div() = default; curve4_div(double x1, double y1, double x2, double y2, double x3, double y3, - double x4, double y4) : - m_approximation_scale(1.0), - m_angle_tolerance(0.0), - m_cusp_limit(0.0), - m_count(0) + double x4, double y4) { init(x1, y1, x2, y2, x3, y3, x4, y4); } - curve4_div(const curve4_points& cp) : - m_approximation_scale(1.0), - m_angle_tolerance(0.0), - m_count(0) + curve4_div(const curve4_points& cp) { init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); } @@ -461,11 +437,11 @@ namespace mapserver double x4, double y4, unsigned level); - double m_approximation_scale; - double m_distance_tolerance_square; - double m_angle_tolerance; - double m_cusp_limit; - unsigned m_count; + double m_approximation_scale = 1.0; + double m_distance_tolerance_square = 0.0; + double m_angle_tolerance = 0.0; + double m_cusp_limit = 0.0; + unsigned m_count = 0; pod_bvector m_points; }; diff --git a/renderers/agg/include/agg_dda_line.h b/renderers/agg/include/agg_dda_line.h index c9a8d7bd48..07494053db 100644 --- a/renderers/agg/include/agg_dda_line.h +++ b/renderers/agg/include/agg_dda_line.h @@ -89,7 +89,7 @@ namespace mapserver enum save_size_e { save_size = 2 }; //-------------------------------------------------------------------- - dda2_line_interpolator() {} + dda2_line_interpolator() = default; //-------------------------------------------- Forward-adjusted line dda2_line_interpolator(int y1, int y2, int count) : @@ -200,11 +200,11 @@ namespace mapserver int y() const { return m_y; } private: - int m_cnt; - int m_lft; - int m_rem; - int m_mod; - int m_y; + int m_cnt = 0; + int m_lft = 0; + int m_rem = 0; + int m_mod = 0; + int m_y = 0; }; diff --git a/renderers/agg/include/agg_font_cache_manager.h b/renderers/agg/include/agg_font_cache_manager.h index dd644ca4f5..9e3f1f4898 100644 --- a/renderers/agg/include/agg_font_cache_manager.h +++ b/renderers/agg/include/agg_font_cache_manager.h @@ -392,8 +392,8 @@ namespace mapserver font_cache_pool m_fonts; font_engine_type& m_engine; int m_change_stamp; - double m_dx; - double m_dy; + double m_dx = 0; + double m_dy = 0; const glyph_cache* m_prev_glyph; const glyph_cache* m_last_glyph; path_adaptor_type m_path_adaptor; diff --git a/renderers/agg/include/agg_image_accessors.h b/renderers/agg/include/agg_image_accessors.h index b358721532..f1b44c5ed7 100644 --- a/renderers/agg/include/agg_image_accessors.h +++ b/renderers/agg/include/agg_image_accessors.h @@ -237,7 +237,7 @@ namespace mapserver typedef typename pixfmt_type::value_type value_type; enum pix_width_e { pix_width = pixfmt_type::pix_width }; - image_accessor_wrap() {} + image_accessor_wrap() = default; explicit image_accessor_wrap(const pixfmt_type& pixf) : m_pixf(&pixf), m_wrap_x(pixf.width()), @@ -269,11 +269,11 @@ namespace mapserver } private: - const pixfmt_type* m_pixf; - const int8u* m_row_ptr; - int m_x; - WrapX m_wrap_x; - WrapY m_wrap_y; + const pixfmt_type* m_pixf = nullptr; + const int8u* m_row_ptr = nullptr; + int m_x = 0; + WrapX m_wrap_x = 0; + WrapY m_wrap_y = 0; }; diff --git a/renderers/agg/include/agg_line_aa_basics.h b/renderers/agg/include/agg_line_aa_basics.h index ef53ad374f..48dafcc4c7 100644 --- a/renderers/agg/include/agg_line_aa_basics.h +++ b/renderers/agg/include/agg_line_aa_basics.h @@ -81,7 +81,7 @@ namespace mapserver struct line_parameters { //--------------------------------------------------------------------- - line_parameters() {} + line_parameters() = default; line_parameters(int x1_, int y1_, int x2_, int y2_, int len_) : x1(x1_), y1(y1_), x2(x2_), y2(y2_), dx(abs(x2_ - x1_)), @@ -135,11 +135,11 @@ namespace mapserver } //--------------------------------------------------------------------- - int x1, y1, x2, y2, dx, dy, sx, sy; - bool vertical; - int inc; - int len; - int octant; + int x1 = 0, y1 = 0, x2 = 0, y2 = 0, dx = 0, dy = 0, sx = 0, sy = 0; + bool vertical = false; + int inc = 0; + int len = 0; + int octant = 0; //--------------------------------------------------------------------- static const int8u s_orthogonal_quadrant[8]; diff --git a/renderers/agg/include/agg_path_storage.h b/renderers/agg/include/agg_path_storage.h index 1fc9cf96a0..bbf0f850b4 100644 --- a/renderers/agg/include/agg_path_storage.h +++ b/renderers/agg/include/agg_path_storage.h @@ -16,6 +16,7 @@ #ifndef AGG_PATH_STORAGE_INCLUDED #define AGG_PATH_STORAGE_INCLUDED +#include #include #include #include "agg_math.h" @@ -312,6 +313,7 @@ namespace mapserver m_coord_blocks, m_max_blocks * sizeof(T*)); + assert(m_cmd_blocks); memcpy(new_cmds, m_cmd_blocks, m_max_blocks * sizeof(unsigned char*)); @@ -322,6 +324,7 @@ namespace mapserver m_cmd_blocks = new_cmds; m_max_blocks += block_pool; } + assert(m_coord_blocks); m_coord_blocks[nb] = pod_allocator::allocate(block_size * 2 + block_size / (sizeof(T) / sizeof(unsigned char))); diff --git a/renderers/agg/include/agg_path_storage_integer.h b/renderers/agg/include/agg_path_storage_integer.h index cd8e004a61..c2498ed207 100644 --- a/renderers/agg/include/agg_path_storage_integer.h +++ b/renderers/agg/include/agg_path_storage_integer.h @@ -38,8 +38,8 @@ namespace mapserver coord_scale = 1 << coord_shift }; - T x,y; - vertex_integer() {} + T x = 0,y = 0; + vertex_integer() = default; vertex_integer(T x_, T y_, unsigned flag) : x(((x_ << 1) & ~1) | (flag & 1)), y(((y_ << 1) & ~1) | (flag >> 1)) {} diff --git a/renderers/agg/include/agg_rasterizer_outline_aa.h b/renderers/agg/include/agg_rasterizer_outline_aa.h index 5b21d2008b..5f1deff35b 100644 --- a/renderers/agg/include/agg_rasterizer_outline_aa.h +++ b/renderers/agg/include/agg_rasterizer_outline_aa.h @@ -33,15 +33,14 @@ namespace mapserver // the distance between the last and the first points struct line_aa_vertex { - int x; - int y; - int len; + int x = 0; + int y = 0; + int len = 0; - line_aa_vertex() {} + line_aa_vertex() = default; line_aa_vertex(int x_, int y_) : x(x_), - y(y_), - len(0) + y(y_) { } diff --git a/renderers/agg/include/agg_rasterizer_scanline_aa.h b/renderers/agg/include/agg_rasterizer_scanline_aa.h index c002569ad9..68ace5f245 100644 --- a/renderers/agg/include/agg_rasterizer_scanline_aa.h +++ b/renderers/agg/include/agg_rasterizer_scanline_aa.h @@ -306,7 +306,7 @@ namespace mapserver coord_type m_start_x; coord_type m_start_y; unsigned m_status; - int m_scan_y; + int m_scan_y = 0; }; diff --git a/renderers/agg/include/agg_renderer_outline_image.h b/renderers/agg/include/agg_renderer_outline_image.h index 577e311eed..fd05bb36de 100644 --- a/renderers/agg/include/agg_renderer_outline_image.h +++ b/renderers/agg/include/agg_renderer_outline_image.h @@ -782,7 +782,7 @@ namespace mapserver dda2_line_interpolator m_li; distance_interpolator4 m_di; renderer_type& m_ren; - int m_plen; + int m_plen = 0; int m_x; int m_y; int m_old_x; diff --git a/renderers/agg/include/agg_scanline_bin.h b/renderers/agg/include/agg_scanline_bin.h index afba7f0045..6fd1d78961 100644 --- a/renderers/agg/include/agg_scanline_bin.h +++ b/renderers/agg/include/agg_scanline_bin.h @@ -134,7 +134,7 @@ namespace mapserver const scanline_bin operator = (const scanline_bin&); int m_last_x; - int m_y; + int m_y = 0; pod_array m_spans; span* m_cur_span; }; diff --git a/renderers/agg/include/agg_scanline_p.h b/renderers/agg/include/agg_scanline_p.h index d490d53a1d..7dd7dc04bc 100644 --- a/renderers/agg/include/agg_scanline_p.h +++ b/renderers/agg/include/agg_scanline_p.h @@ -164,7 +164,7 @@ namespace mapserver const self_type& operator = (const self_type&); int m_last_x; - int m_y; + int m_y = 0; pod_array m_covers; cover_type* m_cover_ptr; pod_array m_spans; diff --git a/renderers/agg/include/agg_scanline_storage_aa.h b/renderers/agg/include/agg_scanline_storage_aa.h index 7b0e3d17db..f6c67fa9e2 100644 --- a/renderers/agg/include/agg_scanline_storage_aa.h +++ b/renderers/agg/include/agg_scanline_storage_aa.h @@ -607,7 +607,7 @@ namespace mapserver //----------------------------------------------------------------- - embedded_scanline() : m_ptr(0), m_y(0), m_num_spans(0) {} + embedded_scanline() = default; //----------------------------------------------------------------- void reset(int, int) {} @@ -639,10 +639,10 @@ namespace mapserver } private: - const int8u* m_ptr; - int m_y; - unsigned m_num_spans; - int m_dx; + const int8u* m_ptr = nullptr; + int m_y = 0; + unsigned m_num_spans = 0; + int m_dx = 0; }; diff --git a/renderers/agg/include/agg_scanline_storage_bin.h b/renderers/agg/include/agg_scanline_storage_bin.h index 43ba9d82a6..bdb570c651 100644 --- a/renderers/agg/include/agg_scanline_storage_bin.h +++ b/renderers/agg/include/agg_scanline_storage_bin.h @@ -399,7 +399,7 @@ namespace mapserver //---------------------------------------------------------------- - embedded_scanline() : m_ptr(0), m_y(0), m_num_spans(0) {} + embedded_scanline() = default; //---------------------------------------------------------------- void reset(int, int) {} @@ -431,10 +431,10 @@ namespace mapserver } private: - const int8u* m_ptr; - int m_y; - unsigned m_num_spans; - int m_dx; + const int8u* m_ptr = nullptr; + int m_y = 0; + unsigned m_num_spans = 0; + int m_dx = 0; }; diff --git a/renderers/agg/include/agg_scanline_u.h b/renderers/agg/include/agg_scanline_u.h index 897615bfe5..f6ca58a4ff 100644 --- a/renderers/agg/include/agg_scanline_u.h +++ b/renderers/agg/include/agg_scanline_u.h @@ -228,7 +228,7 @@ namespace mapserver private: int m_min_x; int m_last_x; - int m_y; + int m_y = 0; pod_array m_covers; pod_array m_spans; span* m_cur_span; diff --git a/renderers/agg/include/agg_vcgen_contour.h b/renderers/agg/include/agg_vcgen_contour.h index 1bd5dc103a..0c3e4c7ab1 100644 --- a/renderers/agg/include/agg_vcgen_contour.h +++ b/renderers/agg/include/agg_vcgen_contour.h @@ -83,7 +83,7 @@ namespace mapserver coord_storage m_out_vertices; status_e m_status; unsigned m_src_vertex; - unsigned m_out_vertex; + unsigned m_out_vertex = 0; unsigned m_closed; unsigned m_orientation; bool m_auto_detect; diff --git a/renderers/agg/include/agg_vcgen_dash.h b/renderers/agg/include/agg_vcgen_dash.h index 7f1d15ce62..dcaad00c66 100644 --- a/renderers/agg/include/agg_vcgen_dash.h +++ b/renderers/agg/include/agg_vcgen_dash.h @@ -77,9 +77,9 @@ namespace mapserver double m_shorten; double m_curr_dash_start; unsigned m_curr_dash; - double m_curr_rest; - const vertex_dist* m_v1; - const vertex_dist* m_v2; + double m_curr_rest = 0; + const vertex_dist* m_v1 = nullptr; + const vertex_dist* m_v2 = nullptr; vertex_storage m_src_vertices; unsigned m_closed; diff --git a/renderers/agg/include/agg_vcgen_stroke.h b/renderers/agg/include/agg_vcgen_stroke.h index 8544d94e17..88344ef4a6 100644 --- a/renderers/agg/include/agg_vcgen_stroke.h +++ b/renderers/agg/include/agg_vcgen_stroke.h @@ -91,7 +91,7 @@ namespace mapserver double m_shorten; unsigned m_closed; status_e m_status; - status_e m_prev_status; + status_e m_prev_status = initial; unsigned m_src_vertex; unsigned m_out_vertex; }; diff --git a/renderers/agg/include/agg_vertex_sequence.h b/renderers/agg/include/agg_vertex_sequence.h index 9a3c69d134..9f53af0328 100644 --- a/renderers/agg/include/agg_vertex_sequence.h +++ b/renderers/agg/include/agg_vertex_sequence.h @@ -130,15 +130,14 @@ namespace mapserver // and 0.0 if it's a polyline. struct vertex_dist { - double x; - double y; - double dist; + double x = 0; + double y = 0; + double dist = 0; - vertex_dist() {} + vertex_dist() = default; vertex_dist(double x_, double y_) : x(x_), - y(y_), - dist(0.0) + y(y_) { } diff --git a/renderers/agg/include/clipper.hpp b/renderers/agg/include/clipper.hpp index 76cdc21d7d..7faf965119 100644 --- a/renderers/agg/include/clipper.hpp +++ b/renderers/agg/include/clipper.hpp @@ -218,14 +218,14 @@ class Clipper : public virtual ClipperBase PolyOutList m_PolyOuts; JoinList m_Joins; HorzJoinList m_HorizJoins; - ClipType m_ClipType; + ClipType m_ClipType = ctIntersection; Scanbeam *m_Scanbeam; TEdge *m_ActiveEdges; TEdge *m_SortedEdges; IntersectNode *m_IntersectNodes; bool m_ExecuteLocked; - PolyFillType m_ClipFillType; - PolyFillType m_SubjFillType; + PolyFillType m_ClipFillType = pftEvenOdd; + PolyFillType m_SubjFillType = pftEvenOdd; bool m_ReverseOutput; void DisposeScanbeamList(); void SetWindingCount(TEdge& edge); diff --git a/renderers/agg/src/agg_font_freetype.cpp b/renderers/agg/src/agg_font_freetype.cpp index 1875e7aa12..1308869d24 100644 --- a/renderers/agg/src/agg_font_freetype.cpp +++ b/renderers/agg/src/agg_font_freetype.cpp @@ -150,9 +150,6 @@ namespace mapserver { typedef typename PathStorage::value_type value_type; - FT_Vector v_last; - FT_Vector v_control; - FT_Vector v_start; double x1, y1, x2, y2, x3, y3; FT_Vector* point; @@ -172,10 +169,9 @@ namespace mapserver last = outline.contours[n]; limit = outline.points + last; - v_start = outline.points[first]; - v_last = outline.points[last]; + FT_Vector v_start = outline.points[first]; - v_control = v_start; + FT_Vector v_control = v_start; point = outline.points + first; tags = outline.tags + first; @@ -187,6 +183,8 @@ namespace mapserver // check first point to determine origin if( tag == FT_CURVE_TAG_CONIC) { + const FT_Vector v_last = outline.points[last]; + // first point is conic control. Yes, this happens. if(FT_CURVE_TAG(outline.tags[last]) == FT_CURVE_TAG_ON) { @@ -201,8 +199,6 @@ namespace mapserver // for closure v_start.x = (v_start.x + v_last.x) / 2; v_start.y = (v_start.y + v_last.y) / 2; - - v_last = v_start; } point--; tags--; diff --git a/renderers/agg/src/clipper.cpp b/renderers/agg/src/clipper.cpp index 5a7e40597e..8433f95f97 100644 --- a/renderers/agg/src/clipper.cpp +++ b/renderers/agg/src/clipper.cpp @@ -39,6 +39,7 @@ *******************************************************************************/ #include "../include/clipper.hpp" +#include #include #include #include @@ -842,7 +843,7 @@ bool ClipperBase::AddPolygon( const Polygon &pg, PolyType polyType) if (j == len-1 || j < 2) break; len = j +1; } - if (len < 3) return false; + // if (len < 3) return false; //create a new edge array ... TEdge *edges = new TEdge [len]; @@ -919,6 +920,7 @@ TEdge* ClipperBase::AddBoundsToLML(TEdge *e) // but break on horizontal minima if approaching from their left. // This ensures 'local minima' are always on the left of horizontals. if (e->next->ytop < e->ytop && e->next->xbot > e->prev->xbot) break; + // coverity[copy_paste_error] if (e->xtop != e->prev->xbot) SwapX(*e); e->nextInLML = e->prev; } @@ -2256,6 +2258,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) //ok, so far it looks like we're still in range of the horizontal edge if ( e->xcurr == horzEdge->xtop && !eMaxPair ) { + assert(horzEdge->nextInLML); if (SlopesEqual(*e, *horzEdge->nextInLML, m_UseFullRange)) { //if output polygons share an edge, they'll need joining later ... @@ -2317,9 +2320,12 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) } else { + assert(eMaxPair); if ( horzEdge->outIdx >= 0 ) + { IntersectEdges( horzEdge, eMaxPair, - IntPoint(horzEdge->xtop, horzEdge->ycurr), ipBoth); + IntPoint(horzEdge->xtop, horzEdge->ycurr), ipBoth); + } if (eMaxPair->outIdx >= 0) throw clipperException("ProcessHorizontal error"); DeleteFromAEL(eMaxPair); DeleteFromAEL(horzEdge); @@ -3064,10 +3070,10 @@ class PolyOffsetBuilder { private: Polygons m_p; - Polygon* m_curr_poly; + Polygon* m_curr_poly = nullptr; std::vector normals; - double m_delta, m_RMin, m_R; - size_t m_i, m_j, m_k; + double m_delta, m_RMin, m_R = 0; + size_t m_i, m_j = 0, m_k = 0; static const int buffLength = 128; JoinType m_jointype; diff --git a/shp2img.c b/shp2img.c index 508ff38e9b..6054ea17ae 100644 --- a/shp2img.c +++ b/shp2img.c @@ -30,7 +30,7 @@ #include "mapserver.h" #include "maptime.h" - +#include "limits.h" int main(int argc, char *argv[]) { @@ -52,6 +52,11 @@ int main(int argc, char *argv[]) for(i=1; i INT_MAX - 1 ) + { + printf("Invalid number of iterations"); + return 1; + } printf("We will draw %d times...\n", iterations); continue; } diff --git a/shptreetst.c b/shptreetst.c index 997d5f2914..258040cbda 100644 --- a/shptreetst.c +++ b/shptreetst.c @@ -148,6 +148,11 @@ int main( int argc, char ** argv ) rect.maxx = atof (argv[4]); rect.maxy = atof (argv[5]); } else { + if( node == NULL ) + { + printf("node == NULL"); + return 1; + } printf ("using last read box as a search \n"); rect.minx = node->rect.minx; rect.miny = node->rect.miny;