Merge branch 'vla' of https://github.com/CendioOssman/tigervnc
diff --git a/.travis.yml b/.travis.yml
index 74878fc..ceafcbb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,5 +16,5 @@
- popd
script:
- - cmake . && make
+ - cmake -DCMAKE_BUILD_TYPE=Debug . && make
- cd java && cmake . && make
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4fb3360..f87fc25 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -76,8 +76,8 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wformat=2")
# Make sure we catch these issues whilst developing
IF(CMAKE_BUILD_TYPE MATCHES Debug)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=vla")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=vla")
ENDIF()
option(ENABLE_ASAN "Enable address sanitizer support" OFF)
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;
diff --git a/tests/encperf.cxx b/tests/encperf.cxx
index 4e7038f..733d55b 100644
--- a/tests/encperf.cxx
+++ b/tests/encperf.cxx
@@ -423,8 +423,9 @@
}
int runCount = count;
- struct stats runs[runCount];
- double values[runCount], dev[runCount];
+ struct stats *runs = new struct stats[runCount];
+ double *values = new double[runCount];
+ double *dev = new double[runCount];
double median, meddev;
if (fn == NULL) {
diff --git a/vncviewer/gettext.h b/vncviewer/gettext.h
index ac4d7d5..768a699 100644
--- a/vncviewer/gettext.h
+++ b/vncviewer/gettext.h
@@ -1,24 +1,26 @@
/* Convenience header for conditional use of GNU <libintl.h>.
- Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2011 Free Software Foundation, Inc.
+ Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2018 Free Software
+ Foundation, Inc.
- This program is free software: you can redistribute it and/or modify
+ This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <https://www.gnu.org/licenses/>. */
#ifndef _LIBGETTEXT_H
#define _LIBGETTEXT_H 1
-/* NLS can be disabled through the configure --disable-nls option. */
-#if ENABLE_NLS
+/* NLS can be disabled through the configure --disable-nls option
+ or through "#define ENABLE NLS 0" before including this file. */
+#if defined ENABLE_NLS && ENABLE_NLS
/* Get declarations of GNU message catalog functions. */
# include <libintl.h>
@@ -182,8 +184,9 @@
#include <string.h>
-#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
- /* || __STDC_VERSION__ >= 199901L */ )
+#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__ && !defined __cplusplus) \
+ /* || __STDC_VERSION__ == 199901L
+ || (__STDC_VERSION__ >= 201112L && !defined __STDC_NO_VLA__) */ )
# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
#else
# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
@@ -224,15 +227,17 @@
if (msg_ctxt_id != NULL)
#endif
{
+ int found_translation;
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcgettext (domain, msg_ctxt_id, category);
+ found_translation = (translation != msg_ctxt_id);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
- if (translation != msg_ctxt_id)
+ if (found_translation)
return translation;
}
return msgid;
@@ -270,15 +275,17 @@
if (msg_ctxt_id != NULL)
#endif
{
+ int found_translation;
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
+ found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
- if (!(translation == msg_ctxt_id || translation == msgid_plural))
+ if (found_translation)
return translation;
}
return (n == 1 ? msgid : msgid_plural);
diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx
index 94cc1b0..8427818 100644
--- a/vncviewer/parameters.cxx
+++ b/vncviewer/parameters.cxx
@@ -325,9 +325,10 @@
static bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* hKey) {
- DWORD buffersize = 256;
- WCHAR value[destSize];
+ const DWORD buffersize = 256;
wchar_t name[buffersize];
+ WCHAR* value;
+ DWORD valuesize;
unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize);
if (size >= buffersize) {
@@ -335,8 +336,11 @@
return false;
}
- LONG res = RegQueryValueExW(*hKey, name, 0, NULL, (LPBYTE)value, &buffersize);
+ value = new WCHAR[destSize];
+ valuesize = destSize;
+ LONG res = RegQueryValueExW(*hKey, name, 0, NULL, (LPBYTE)value, &valuesize);
if (res != ERROR_SUCCESS){
+ delete [] value;
if (res == ERROR_FILE_NOT_FOUND) {
// The value does not exist, defaults will be used.
} else {
@@ -346,18 +350,19 @@
return false;
}
- char utf8val[destSize];
- size = fl_utf8fromwc(utf8val, sizeof(utf8val), value, wcslen(value)+1);
- if (size >= sizeof(utf8val)) {
+ char* utf8val = new char[destSize];
+ size = fl_utf8fromwc(utf8val, destSize, value, wcslen(value)+1);
+ delete [] value;
+ if (size >= destSize) {
+ delete [] utf8val;
vlog.error(_("The parameter %s was too large to read from the registry"), _name);
return false;
}
- const char *ret = utf8val;
- if(decodeValue(ret, dest, destSize))
- return true;
- else
- return false;
+ bool ret = decodeValue(utf8val, dest, destSize);
+ delete [] utf8val;
+
+ return ret;
}