diff --git a/src/libvncclient/trle.c b/src/libvncclient/trle.c index cf06c185..3db1a052 100644 --- a/src/libvncclient/trle.c +++ b/src/libvncclient/trle.c @@ -30,6 +30,8 @@ #define REALBPP BPP #endif +#define REALBytesPP ((REALBPP + 7) / 8) + #if !defined(UNCOMP) || UNCOMP == 0 #define HandleTRLE CONCAT2E(HandleTRLE, REALBPP) #elif UNCOMP > 0 @@ -38,7 +40,6 @@ #define HandleTRLE CONCAT3E(HandleTRLE, REALBPP, Up) #endif #define CARDBPP CONCAT3E(uint, BPP, _t) -#define CARDREALBPP CONCAT3E(uint, REALBPP, _t) #if REALBPP != BPP && defined(UNCOMP) && UNCOMP != 0 #if UNCOMP > 0 @@ -53,7 +54,7 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { int x, y, w, h; uint8_t type, last_type = 0; - int min_buffer_size = 16 * 16 * (REALBPP / 8) * 2; + int min_buffer_size = 16 * 16 * REALBytesPP * 2; uint8_t *buffer; CARDBPP palette[128]; int bpp = 0, mask = 0, divider = 0; @@ -93,14 +94,14 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { switch (type) { case 0: { - if (!ReadFromRFBServer(client, (char *)buffer, w * h * REALBPP / 8)) + if (!ReadFromRFBServer(client, (char *)buffer, w * h * REALBytesPP)) return FALSE; #if REALBPP != BPP int i, j; for (j = y * client->width; j < (y + h) * client->width; j += client->width) - for (i = x; i < x + w; i++, buffer += REALBPP / 8) + for (i = x; i < x + w; i++, buffer += REALBytesPP) ((CARDBPP *)client->frameBuffer)[j + i] = UncompressCPixel(buffer); #else client->GotBitmap(client, buffer, x, y, w, h); @@ -109,7 +110,7 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { break; } case 1: { - if (!ReadFromRFBServer(client, (char *)buffer, REALBPP / 8)) + if (!ReadFromRFBServer(client, (char *)buffer, REALBytesPP)) return FALSE; color = UncompressCPixel(buffer); @@ -171,11 +172,11 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { while (j < h) { int color, length, buffer_pos = 0; /* read color */ - if (!ReadFromRFBServer(client, (char*)buffer, REALBPP / 8 + 1)) + if (!ReadFromRFBServer(client, (char*)buffer, REALBytesPP + 1)) return FALSE; color = UncompressCPixel(buffer); - buffer += REALBPP / 8; - buffer_pos += REALBPP / 8; + buffer += REALBytesPP; + buffer_pos += REALBytesPP; /* read run length */ length = 1; while (*buffer == 0xff && buffer_pos < client->raw_buffer_size-1) { @@ -260,11 +261,11 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { bpp = (type > 4 ? 4 : (type > 2 ? 2 : 1)), mask = (1 << bpp) - 1, divider = (8 / bpp); - if (!ReadFromRFBServer(client, (char *)buffer, type * REALBPP / 8)) + if (!ReadFromRFBServer(client, (char *)buffer, type * REALBytesPP)) return FALSE; /* read palette */ - for (i = 0; i < type; i++, buffer += REALBPP / 8) + for (i = 0; i < type; i++, buffer += REALBytesPP) palette[i] = UncompressCPixel(buffer); last_type = type; @@ -272,11 +273,11 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { } else if (type >= 130) { int i; - if (!ReadFromRFBServer(client, (char *)buffer, (type - 128) * REALBPP / 8)) + if (!ReadFromRFBServer(client, (char *)buffer, (type - 128) * REALBytesPP)) return FALSE; /* read palette */ - for (i = 0; i < type - 128; i++, buffer += REALBPP / 8) + for (i = 0; i < type - 128; i++, buffer += REALBytesPP) palette[i] = UncompressCPixel(buffer); last_type = type; @@ -292,7 +293,6 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { } #undef CARDBPP -#undef CARDREALBPP #undef HandleTRLE #undef UncompressCPixel #undef REALBPP diff --git a/src/libvncclient/zrle.c b/src/libvncclient/zrle.c index 6859519f..64fa561f 100644 --- a/src/libvncclient/zrle.c +++ b/src/libvncclient/zrle.c @@ -32,6 +32,8 @@ #define REALBPP BPP #endif +#define REALBytesPP ((REALBPP + 7) / 8) + #if !defined(UNCOMP) || UNCOMP==0 #define HandleZRLE CONCAT2E(HandleZRLE,REALBPP) #define HandleZRLETile CONCAT2E(HandleZRLETile,REALBPP) @@ -43,7 +45,6 @@ #define HandleZRLETile CONCAT3E(HandleZRLETile,REALBPP,Up) #endif #define CARDBPP CONCAT3E(uint,BPP,_t) -#define CARDREALBPP CONCAT3E(uint,REALBPP,_t) #define ENDIAN_LITTLE 0 #define ENDIAN_BIG 1 @@ -87,7 +88,7 @@ HandleZRLE (rfbClient* client, int rx, int ry, int rw, int rh) int remaining; int inflateResult; int toRead; - int min_buffer_size = rw * rh * (REALBPP / 8) * 2; + int min_buffer_size = rw * rh * REALBytesPP * 2; /* First make sure we have a large enough raw buffer to hold the * decompressed data. In practice, with a fixed REALBPP, fixed frame @@ -269,29 +270,29 @@ static int HandleZRLETile(rfbClient* client, #if REALBPP!=BPP int i,j; - if(1+w*h*REALBPP/8>buffer_length) { - rfbClientLog("expected %d bytes, got only %d (%dx%d)\n",1+w*h*REALBPP/8,buffer_length,w,h); + if(1+w*h*REALBytesPP>buffer_length) { + rfbClientLog("expected %d bytes, got only %d (%dx%d)\n",1+w*h*REALBytesPP,buffer_length,w,h); return -3; } for(j=y*client->width; j<(y+h)*client->width; j+=client->width) - for(i=x; iframeBuffer)[j+i] = UncompressCPixel(buffer); #else client->GotBitmap(client, buffer, x, y, w, h); - buffer+=w*h*REALBPP/8; + buffer+=w*h*REALBytesPP; #endif } else if( type == 1 ) /* solid */ { CARDBPP color = UncompressCPixel(buffer); - if(1+REALBPP/8>buffer_length) + if(1+REALBytesPP>buffer_length) return -4; client->GotFillRect(client, x, y, w, h, color); - buffer+=REALBPP/8; + buffer+=REALBytesPP; } else if( type <= 127 ) /* packed Palette */ @@ -302,11 +303,11 @@ static int HandleZRLETile(rfbClient* client, mask=(1<buffer_length) + if(1+type*REALBytesPP+((w+divider-1)/divider)*h>buffer_length) return -5; /* read palette */ - for(i=0; ibuffer_end) + if(buffer+REALBytesPP+1>buffer_end) return -7; color = UncompressCPixel(buffer); - buffer+=REALBPP/8; + buffer+=REALBytesPP; /* read run length */ length=1; while(*buffer==0xff) { @@ -368,11 +369,11 @@ static int HandleZRLETile(rfbClient* client, CARDBPP palette[128]; int i,j; - if(2+(type-128)*REALBPP/8>buffer_length) + if(2+(type-128)*REALBytesPP>buffer_length) return -9; /* read palette */ - for(i=0; i