From dde95fccca9fffff0da2dc486d639b162115bb9e Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 10 Jan 2023 19:23:50 +0100 Subject: [PATCH] Specify expected array size in arguments The compiler doesn't enforce this, but it at least documents the expected array size. --- common/rfb/util.cxx | 4 ++-- common/rfb/util.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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); -- 2.39.5