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
					
				
							
								
								
									
										20
									
								
								Xext/shape.c
								
								
								
								
							
							
						
						
									
										20
									
								
								Xext/shape.c
								
								
								
								
							| 
						 | 
					@ -938,7 +938,7 @@ ProcShapeGetRectangles(ClientPtr client)
 | 
				
			||||||
    REQUEST(xShapeGetRectanglesReq);
 | 
					    REQUEST(xShapeGetRectanglesReq);
 | 
				
			||||||
    WindowPtr pWin;
 | 
					    WindowPtr pWin;
 | 
				
			||||||
    xShapeGetRectanglesReply rep;
 | 
					    xShapeGetRectanglesReply rep;
 | 
				
			||||||
    xRectangle *rects;
 | 
					    xRectangle *rects = NULL;
 | 
				
			||||||
    int nrects, i, rc;
 | 
					    int nrects, i, rc;
 | 
				
			||||||
    RegionPtr region;
 | 
					    RegionPtr region;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -991,14 +991,16 @@ ProcShapeGetRectangles(ClientPtr client)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        nrects = RegionNumRects(region);
 | 
					        nrects = RegionNumRects(region);
 | 
				
			||||||
        box = RegionRects(region);
 | 
					        box = RegionRects(region);
 | 
				
			||||||
        rects = xallocarray(nrects, sizeof(xRectangle));
 | 
					        if (nrects) {
 | 
				
			||||||
        if (!rects && nrects)
 | 
					            rects = calloc(nrects, sizeof(xRectangle));
 | 
				
			||||||
            return BadAlloc;
 | 
					            if (!rects)
 | 
				
			||||||
        for (i = 0; i < nrects; i++, box++) {
 | 
					                return BadAlloc;
 | 
				
			||||||
            rects[i].x = box->x1;
 | 
					            for (i = 0; i < nrects; i++, box++) {
 | 
				
			||||||
            rects[i].y = box->y1;
 | 
					                rects[i].x = box->x1;
 | 
				
			||||||
            rects[i].width = box->x2 - box->x1;
 | 
					                rects[i].y = box->y1;
 | 
				
			||||||
            rects[i].height = box->y2 - box->y1;
 | 
					                rects[i].width = box->x2 - box->x1;
 | 
				
			||||||
 | 
					                rects[i].height = box->y2 - box->y1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    rep = (xShapeGetRectanglesReply) {
 | 
					    rep = (xShapeGetRectanglesReply) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue