Remove variable length arrays
These are not allowed in C++, and have been made optional in C11.
So let's just get rid of them and any issues they may cause.
diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx
index 1d359d2..e42546d 100644
--- a/common/rfb/CMsgReader.cxx
+++ b/common/rfb/CMsgReader.cxx
@@ -210,7 +210,7 @@
if (width > maxCursorSize || height > maxCursorSize)
throw Exception("Too big cursor");
- rdr::U8 buf[width*height*4];
+ rdr::U8Array rgba(width*height*4);
if (width * height > 0) {
rdr::U8 pr, pg, pb;
@@ -235,7 +235,7 @@
is->readBytes(mask.buf, mask_len);
int maskBytesPerRow = (width+7)/8;
- out = buf;
+ out = rgba.buf;
for (y = 0;y < height;y++) {
for (x = 0;x < width;x++) {
int byte = y * maskBytesPerRow + x / 8;
@@ -261,7 +261,7 @@
}
}
- handler->setCursor(width, height, hotspot, buf);
+ handler->setCursor(width, height, hotspot, rgba.buf);
}
void CMsgReader::readSetCursor(int width, int height, const Point& hotspot)
@@ -275,7 +275,7 @@
rdr::U8Array mask(mask_len);
int x, y;
- rdr::U8 buf[width*height*4];
+ rdr::U8Array rgba(width*height*4);
rdr::U8* in;
rdr::U8* out;
@@ -284,7 +284,7 @@
int maskBytesPerRow = (width+7)/8;
in = data.buf;
- out = buf;
+ out = rgba.buf;
for (y = 0;y < height;y++) {
for (x = 0;x < width;x++) {
int byte = y * maskBytesPerRow + x / 8;
@@ -302,7 +302,7 @@
}
}
- handler->setCursor(width, height, hotspot, buf);
+ handler->setCursor(width, height, hotspot, rgba.buf);
}
void CMsgReader::readSetCursorWithAlpha(int width, int height, const Point& hotspot)
diff --git a/common/rfb/Cursor.cxx b/common/rfb/Cursor.cxx
index 99df82d..d0feaa5 100644
--- a/common/rfb/Cursor.cxx
+++ b/common/rfb/Cursor.cxx
@@ -76,7 +76,7 @@
}
// Floyd-Steinberg dithering
-static void dither(int width, int height, int* data)
+static void dither(int width, int height, rdr::U16* data)
{
for (int y = 0; y < height; y++) {
for (int x_ = 0; x_ < width; x_++) {
@@ -122,31 +122,33 @@
rdr::U8* Cursor::getBitmap() const
{
// First step is converting to luminance
- int luminance[width()*height()];
- int *lum_ptr = luminance;
+ rdr::U16Array luminance(width()*height());
+ rdr::U16 *lum_ptr = luminance.buf;
const rdr::U8 *data_ptr = data;
for (int y = 0; y < height(); y++) {
for (int x = 0; x < width(); x++) {
- // Use BT.709 coefficients for grayscale
- *lum_ptr = 0;
- *lum_ptr += (int)srgb_to_lin(data_ptr[0]) * 6947; // 0.2126
- *lum_ptr += (int)srgb_to_lin(data_ptr[1]) * 23436; // 0.7152
- *lum_ptr += (int)srgb_to_lin(data_ptr[2]) * 2366; // 0.0722
- *lum_ptr /= 32768;
+ rdr::U32 lum;
- lum_ptr++;
+ // Use BT.709 coefficients for grayscale
+ lum = 0;
+ lum += (rdr::U32)srgb_to_lin(data_ptr[0]) * 6947; // 0.2126
+ lum += (rdr::U32)srgb_to_lin(data_ptr[1]) * 23436; // 0.7152
+ lum += (rdr::U32)srgb_to_lin(data_ptr[2]) * 2366; // 0.0722
+ lum /= 32768;
+
+ *lum_ptr++ = lum;
data_ptr += 4;
}
}
// Then diterhing
- dither(width(), height(), luminance);
+ dither(width(), height(), luminance.buf);
// Then conversion to a bit mask
rdr::U8Array source((width()+7)/8*height());
memset(source.buf, 0, (width()+7)/8*height());
int maskBytesPerRow = (width() + 7) / 8;
- lum_ptr = luminance;
+ lum_ptr = luminance.buf;
data_ptr = data;
for (int y = 0; y < height(); y++) {
for (int x = 0; x < width(); x++) {
@@ -165,25 +167,24 @@
rdr::U8* Cursor::getMask() const
{
// First step is converting to integer array
- int alpha[width()*height()];
- int *alpha_ptr = alpha;
+ rdr::U16Array alpha(width()*height());
+ rdr::U16 *alpha_ptr = alpha.buf;
const rdr::U8 *data_ptr = data;
for (int y = 0; y < height(); y++) {
for (int x = 0; x < width(); x++) {
- *alpha_ptr = (int)data_ptr[3] * 65535 / 255;
- alpha_ptr++;
+ *alpha_ptr++ = (rdr::U32)data_ptr[3] * 65535 / 255;
data_ptr += 4;
}
}
// Then diterhing
- dither(width(), height(), alpha);
+ dither(width(), height(), alpha.buf);
// Then conversion to a bit mask
rdr::U8Array mask((width()+7)/8*height());
memset(mask.buf, 0, (width()+7)/8*height());
int maskBytesPerRow = (width() + 7) / 8;
- alpha_ptr = alpha;
+ alpha_ptr = alpha.buf;
data_ptr = data;
for (int y = 0; y < height(); y++) {
for (int x = 0; x < width(); x++) {
diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx
index cc786f5..c547053 100644
--- a/common/rfb/TightDecoder.cxx
+++ b/common/rfb/TightDecoder.cxx
@@ -266,15 +266,16 @@
buflen -= 1;
if (pf.is888()) {
- rdr::U8 tightPalette[palSize * 3];
+ size_t len = palSize * 3;
+ rdr::U8Array tightPalette(len);
- assert(buflen >= sizeof(tightPalette));
+ assert(buflen >= sizeof(len));
- memcpy(tightPalette, bufptr, sizeof(tightPalette));
- bufptr += sizeof(tightPalette);
- buflen -= sizeof(tightPalette);
+ memcpy(tightPalette.buf, bufptr, len);
+ bufptr += len;
+ buflen -= len;
- pf.bufferFromRGB(palette, tightPalette, palSize);
+ pf.bufferFromRGB(palette, tightPalette.buf, palSize);
} else {
size_t len;