Skip to content

Commit d54797d

Browse files
committed
treewide: fix result type of BitmapBytePad() to size_t
sizes can't have negative numbers, so use the size_t here. Also having to fix up lots of callers. Signed-off-by: Enrico Weigelt, metux IT consult <[email protected]>
1 parent a3eab2e commit d54797d

File tree

14 files changed

+37
-36
lines changed

14 files changed

+37
-36
lines changed

Xext/panoramiXprocs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,6 @@ PanoramiXGetImage(ClientPtr client)
19941994
int x, y, w, h, format, rc;
19951995
Mask plane = 0, planemask;
19961996
int linesDone, nlines, linesPerBuf;
1997-
long widthBytesLine;
19981997

19991998
REQUEST(xGetImageReq);
20001999

@@ -2066,6 +2065,8 @@ PanoramiXGetImage(ClientPtr client)
20662065
});
20672066

20682067
size_t length;
2068+
size_t widthBytesLine;
2069+
20692070
if (format == ZPixmap) {
20702071
widthBytesLine = PixmapBytePad(w, pDraw->depth);
20712072
length = widthBytesLine * h;

dix/cursor.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static void
156156
CheckForEmptyMask(CursorBitsPtr bits)
157157
{
158158
unsigned char *msk = bits->mask;
159-
int n = BitmapBytePad(bits->width) * bits->height;
159+
size_t n = BitmapBytePad(bits->width) * bits->height;
160160

161161
bits->emptyMask = FALSE;
162162
while (n--)
@@ -366,10 +366,9 @@ AllocGlyphCursor(Font source, unsigned short sourceChar, Font mask, unsigned sho
366366
return BadValue;
367367
}
368368
if (!maskfont) {
369-
long n;
370369
unsigned char *mskptr;
371370

372-
n = BitmapBytePad(cm.width) * (long) cm.height;
371+
size_t n = BitmapBytePad(cm.width) * (long) cm.height;
373372
mskptr = mskbits = calloc(1, n);
374373
if (!mskptr)
375374
return BadAlloc;

dix/dispatch.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,14 +2162,15 @@ ProcPutImage(ClientPtr client)
21622162
{
21632163
GCPtr pGC;
21642164
DrawablePtr pDraw;
2165-
long length; /* length of scanline server padded */
2166-
long lengthProto; /* length of scanline protocol padded */
21672165
char *tmpImage;
21682166

21692167
REQUEST(xPutImageReq);
21702168

21712169
REQUEST_AT_LEAST_SIZE(xPutImageReq);
21722170
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
2171+
2172+
size_t length; /* length of scanline server padded */
2173+
21732174
if (stuff->format == XYBitmap) {
21742175
if ((stuff->depth != 1) ||
21752176
(stuff->leftPad >= (unsigned int) screenInfo.bitmapScanlinePad))
@@ -2194,7 +2195,7 @@ ProcPutImage(ClientPtr client)
21942195
}
21952196

21962197
tmpImage = (char *) &stuff[1];
2197-
lengthProto = length;
2198+
size_t lengthProto = length; /* length of scanline protocol padded */
21982199

21992200
if (stuff->height != 0 && lengthProto >= (INT32_MAX / stuff->height))
22002201
return BadLength;
@@ -2225,7 +2226,6 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
22252226

22262227
/* coordinates relative to the bounding drawable */
22272228
int relx, rely;
2228-
long widthBytesLine, length;
22292229
Mask plane = 0;
22302230
RegionPtr pVisibleRegion = NULL;
22312231

@@ -2295,6 +2295,8 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
22952295
return BadMatch;
22962296

22972297
rep.depth = pDraw->depth;
2298+
2299+
size_t widthBytesLine, length;
22982300
if (format == ZPixmap) {
22992301
widthBytesLine = PixmapBytePad(width, pDraw->depth);
23002302
length = widthBytesLine * height;
@@ -3092,7 +3094,6 @@ ProcCreateCursor(ClientPtr client)
30923094
PixmapPtr msk;
30933095
unsigned char *srcbits;
30943096
unsigned short width, height;
3095-
long n;
30963097
CursorMetricRec cm;
30973098
int rc;
30983099

@@ -3137,7 +3138,8 @@ ProcCreateCursor(ClientPtr client)
31373138
srcbits = calloc(BitmapBytePad(width), height);
31383139
if (!srcbits)
31393140
return BadAlloc;
3140-
n = BitmapBytePad(width) * height;
3141+
3142+
size_t n = BitmapBytePad(width) * height;
31413143

31423144
unsigned char *mskbits = calloc(1, n);
31433145
if (!mskbits) {

dix/window.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ MakeRootTile(WindowPtr pWin)
503503
ScreenPtr pScreen = pWin->drawable.pScreen;
504504
GCPtr pGC;
505505
unsigned char back[128];
506-
int len = BitmapBytePad(sizeof(long));
507506
unsigned char *to;
508507

509508
pWin->background.pixmap = (*pScreen->CreatePixmap) (pScreen, 4, 4,
@@ -530,6 +529,7 @@ MakeRootTile(WindowPtr pWin)
530529
= (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb;
531530
to = back;
532531

532+
size_t len = BitmapBytePad(sizeof(long));
533533
for (int i = 4; i > 0; i--, from++)
534534
for (int j = len; j > 0; j--)
535535
*to++ = *from;

fb/fbimage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fbPutImage(DrawablePtr pDrawable,
3434
{
3535
FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
3636
unsigned long i;
37-
FbStride srcStride;
37+
size_t srcStride;
3838
FbStip *src = (FbStip *) pImage;
3939

4040
x += pDrawable->x;
@@ -211,7 +211,7 @@ fbGetImage(DrawablePtr pDrawable,
211211
int srcBpp;
212212
int srcXoff, srcYoff;
213213
FbStip *dst;
214-
FbStride dstStride;
214+
size_t dstStride;
215215

216216
/*
217217
* XFree86 DDX empties the root borderClip when the VT is

hw/xnest/Cursor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
6262
Pixmap const mask = xcb_generate_id(xnestUpstreamInfo.conn);
6363
xcb_create_pixmap(xnestUpstreamInfo.conn, 1, mask, winId, pCursor->bits->width, pCursor->bits->height);
6464

65-
int const pixmap_len = BitmapBytePad(pCursor->bits->width) * pCursor->bits->height;
65+
size_t const pixmap_len = BitmapBytePad(pCursor->bits->width) * pCursor->bits->height;
6666

6767
xcb_put_image(xnestUpstreamInfo.conn,
6868
XCB_IMAGE_FORMAT_XY_BITMAP,

hw/xnest/GCOps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ xnestPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
106106
y,
107107
leftPad,
108108
depth,
109-
(format == XCB_IMAGE_FORMAT_Z_PIXMAP ? PixmapBytePad(w, depth)
110-
: BitmapBytePad(w + leftPad)) * h,
109+
(format == XCB_IMAGE_FORMAT_Z_PIXMAP ? (unsigned)PixmapBytePad(w, depth)
110+
: BitmapBytePad((unsigned)(w + leftPad))) * (unsigned)h,
111111
(uint8_t*)pImage);
112112
}
113113

hw/xnest/Pixmap.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ RegionPtr
9494
xnestPixmapToRegion(PixmapPtr pPixmap)
9595
{
9696
register RegionPtr pReg, pTmpReg;
97-
register int x, y;
9897
unsigned long previousPixel, currentPixel;
9998
BoxRec Box = { 0, 0, 0, 0 };
10099
Bool overlap;
@@ -139,13 +138,13 @@ xnestPixmapToRegion(PixmapPtr pPixmap)
139138
}
140139

141140
uint8_t *image_data = xcb_get_image_data(reply);
142-
for (y = 0; y < pPixmap->drawable.height; y++) {
141+
for (size_t y = 0; y < pPixmap->drawable.height; y++) {
143142
Box.y1 = y;
144143
Box.y2 = y + 1;
145144
previousPixel = 0L;
146-
const int line_start = BitmapBytePad(pPixmap->drawable.width) * y;
145+
const size_t line_start = BitmapBytePad(pPixmap->drawable.width) * y;
147146

148-
for (x = 0; x < pPixmap->drawable.width; x++) {
147+
for (size_t x = 0; x < pPixmap->drawable.width; x++) {
149148
currentPixel = ((image_data[line_start + (x/8)]) >> (x % 8)) & 1;
150149
if (previousPixel != currentPixel) {
151150
if (previousPixel == 0L) {

hw/xnest/xcb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ uint32_t xnest_create_bitmap_from_data(
9696
uint32_t gc = xcb_generate_id(xnestUpstreamInfo.conn);
9797
xcb_create_gc(conn, gc, pix, 0, NULL);
9898

99-
const int leftPad = 0;
99+
const size_t leftPad = 0;
100100

101101
xcb_put_image(conn,
102102
XYPixmap,
@@ -108,7 +108,7 @@ uint32_t xnest_create_bitmap_from_data(
108108
0 /* dst_y */,
109109
leftPad,
110110
1 /* depth */,
111-
BitmapBytePad(width + leftPad) * height,
111+
BitmapBytePad((size_t)(width + leftPad)) * (size_t)height,
112112
(uint8_t*)data);
113113

114114
xcb_free_gc(conn, gc);
@@ -138,7 +138,7 @@ uint32_t xnest_create_pixmap_from_bitmap_data(
138138

139139
xcb_aux_change_gc(conn, gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, &gcv);
140140

141-
const int leftPad = 0;
141+
const size_t leftPad = 0;
142142
xcb_put_image(conn,
143143
XYBitmap,
144144
pix,
@@ -149,7 +149,7 @@ uint32_t xnest_create_pixmap_from_bitmap_data(
149149
0 /* dst_y */,
150150
leftPad,
151151
1 /* depth */,
152-
BitmapBytePad(width + leftPad) * height,
152+
BitmapBytePad((size_t)(width + leftPad)) * (size_t)height,
153153
(uint8_t*)data);
154154

155155
xcb_free_gc(conn, gc);

hw/xwin/wincursor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen)
207207
for (y = 0; y < nCY; ++y)
208208
for (x = 0; x < xmax; ++x) {
209209
int nWinPix = bits_to_bytes(pScreenPriv->cursor.sm_cx) * y + x;
210-
int nXPix = BitmapBytePad(pCursor->bits->width) * y + x;
210+
size_t nPix = BitmapBytePad(pCursor->bits->width) * y + x;
211211

212212
pAnd[nWinPix] = 0;
213213
if (fReverse)
@@ -222,7 +222,7 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen)
222222
for (y = 0; y < nCY; ++y)
223223
for (x = 0; x < xmax; ++x) {
224224
int nWinPix = bits_to_bytes(pScreenPriv->cursor.sm_cx) * y + x;
225-
int nXPix = BitmapBytePad(pCursor->bits->width) * y + x;
225+
size_t nPix = BitmapBytePad(pCursor->bits->width) * y + x;
226226

227227
unsigned char mask = pCursor->bits->mask[nXPix];
228228

@@ -318,7 +318,7 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen)
318318
bit = pAnd[nWinPix];
319319
bit = bit & (1 << (7 - (x & 7)));
320320
if (!bit) { /* Within the cursor mask? */
321-
int nXPix =
321+
size_t nXPix =
322322
BitmapBytePad(pCursor->bits->width) * y +
323323
(x / 8);
324324
bit =

0 commit comments

Comments
 (0)