From: Pierre Ossman Date: Tue, 10 Jan 2023 18:23:50 +0000 (+0100) Subject: Specify expected array size in arguments X-Git-Tag: v1.13.90~87^2~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dde95fccca9fffff0da2dc486d639b162115bb9e;p=tigervnc.git Specify expected array size in arguments The compiler doesn't enforce this, but it at least documents the expected array size. --- diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx index cfc694e3..d1ba9200 100644 --- a/common/rfb/util.cxx +++ b/common/rfb/util.cxx @@ -301,7 +301,7 @@ namespace rfb { return buffer; } - size_t ucs4ToUTF8(unsigned src, char* dst) { + size_t ucs4ToUTF8(unsigned src, char dst[5]) { if (src < 0x80) { *dst++ = src; *dst++ = '\0'; @@ -382,7 +382,7 @@ namespace rfb { return consumed; } - size_t ucs4ToUTF16(unsigned src, wchar_t* dst) { + size_t ucs4ToUTF16(unsigned src, wchar_t dst[3]) { if ((src < 0xd800) || ((src >= 0xe000) && (src < 0x10000))) { *dst++ = src; *dst++ = L'\0'; diff --git a/common/rfb/util.h b/common/rfb/util.h index 7f65fa87..e7d716fe 100644 --- a/common/rfb/util.h +++ b/common/rfb/util.h @@ -91,10 +91,10 @@ namespace rfb { // Convertions between various Unicode formats. The returned strings are // always null terminated and must be freed using strFree(). - size_t ucs4ToUTF8(unsigned src, char* dst); + size_t ucs4ToUTF8(unsigned src, char dst[5]); size_t utf8ToUCS4(const char* src, size_t max, unsigned* dst); - size_t ucs4ToUTF16(unsigned src, wchar_t* dst); + size_t ucs4ToUTF16(unsigned src, wchar_t dst[3]); size_t utf16ToUCS4(const wchar_t* src, size_t max, unsigned* dst); char* latin1ToUTF8(const char* src, size_t bytes = (size_t)-1);