diff options
author | Pierre Ossman <ossman@cendio.se> | 2018-11-07 21:36:05 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2018-11-07 21:36:05 +0100 |
commit | beb59a43207f3ac411f1812e8a0dad01d9d1ef7a (patch) | |
tree | b7a538c1d32072df900cdbe695ddbc869fb184c6 /vncviewer | |
parent | 6e7f16907db1a0edcca86bcc67dc26003a8dd413 (diff) | |
download | tigervnc-beb59a43207f3ac411f1812e8a0dad01d9d1ef7a.tar.gz tigervnc-beb59a43207f3ac411f1812e8a0dad01d9d1ef7a.zip |
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.
Diffstat (limited to 'vncviewer')
-rw-r--r-- | vncviewer/gettext.h | 2 | ||||
-rw-r--r-- | vncviewer/parameters.cxx | 27 |
2 files changed, 17 insertions, 12 deletions
diff --git a/vncviewer/gettext.h b/vncviewer/gettext.h index 27c754c6..768a6995 100644 --- a/vncviewer/gettext.h +++ b/vncviewer/gettext.h @@ -184,7 +184,7 @@ npgettext_aux (const char *domain, #include <string.h> -#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \ +#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 diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index 51cce3d7..f611fd0b 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -325,9 +325,10 @@ static void setKeyInt(const char *_name, const int _value, HKEY* hKey) { 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 @@ static bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* h 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 @@ static bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* h 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; } |