Xext: shape: fix warning on possible NULL dereference
Try not to rely on deep black magic of calloc(), instead skip the whole part of nrects is zero. | ../Xext/shape.c: In function ‘ProcShapeGetRectangles’: | ../Xext/shape.c:995:24: warning: dereference of possibly-NULL ‘rects’ [CWE-690] [-Wanalyzer-possible-null-dereference] | 995 | rects[i].x = box->x1; | | ~~~~~~~~~~~^~~~~~~~~ Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
		
							parent
							
								
									7a6d2d41bd
								
							
						
					
					
						commit
						c4642f2632
					
				| 
						 | 
				
			
			@ -938,7 +938,7 @@ ProcShapeGetRectangles(ClientPtr client)
 | 
			
		|||
    REQUEST(xShapeGetRectanglesReq);
 | 
			
		||||
    WindowPtr pWin;
 | 
			
		||||
    xShapeGetRectanglesReply rep;
 | 
			
		||||
    xRectangle *rects;
 | 
			
		||||
    xRectangle *rects = NULL;
 | 
			
		||||
    int nrects, i, rc;
 | 
			
		||||
    RegionPtr region;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -991,8 +991,9 @@ ProcShapeGetRectangles(ClientPtr client)
 | 
			
		|||
 | 
			
		||||
        nrects = RegionNumRects(region);
 | 
			
		||||
        box = RegionRects(region);
 | 
			
		||||
        rects = xallocarray(nrects, sizeof(xRectangle));
 | 
			
		||||
        if (!rects && nrects)
 | 
			
		||||
        if (nrects) {
 | 
			
		||||
            rects = calloc(nrects, sizeof(xRectangle));
 | 
			
		||||
            if (!rects)
 | 
			
		||||
                return BadAlloc;
 | 
			
		||||
            for (i = 0; i < nrects; i++, box++) {
 | 
			
		||||
                rects[i].x = box->x1;
 | 
			
		||||
| 
						 | 
				
			
			@ -1001,6 +1002,7 @@ ProcShapeGetRectangles(ClientPtr client)
 | 
			
		|||
                rects[i].height = box->y2 - box->y1;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    rep = (xShapeGetRectanglesReply) {
 | 
			
		||||
        .type = X_Reply,
 | 
			
		||||
        .ordering = YXBanded,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue