From 58faffaa26815e89ecf2be8abfecf290f0fabe94 Mon Sep 17 00:00:00 2001 From: rogerman Date: Fri, 24 Aug 2012 23:04:42 +0000 Subject: [PATCH] xstring.cpp: - Fix potential buffer overruns in FromUtf8() on non-Windows systems. --- desmume/src/utils/ConvertUTF.h | 16 ++++++++++++---- desmume/src/utils/xstring.cpp | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/desmume/src/utils/ConvertUTF.h b/desmume/src/utils/ConvertUTF.h index e26491536..9c51ddac0 100644 --- a/desmume/src/utils/ConvertUTF.h +++ b/desmume/src/utils/ConvertUTF.h @@ -87,10 +87,18 @@ bit mask & shift operations. ------------------------------------------------------------------------ */ -typedef unsigned long UTF32; /* at least 32 bits */ -typedef unsigned short UTF16; /* at least 16 bits */ -typedef unsigned char UTF8; /* typically 8 bits */ -typedef unsigned char Boolean; /* 0 or 1 */ +#if defined(_MSC_VER) + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; +#else + #include +#endif + +typedef uint32_t UTF32; +typedef uint16_t UTF16; +typedef uint8_t UTF8; +typedef uint8_t Boolean; /* 0 or 1 */ /* Some fundamental constants */ #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD diff --git a/desmume/src/utils/xstring.cpp b/desmume/src/utils/xstring.cpp index 96c0a03d0..3afd594e3 100644 --- a/desmume/src/utils/xstring.cpp +++ b/desmume/src/utils/xstring.cpp @@ -645,7 +645,7 @@ namespace UtfConverter const UTF8* sourcestart = reinterpret_cast(utf8string.c_str()); const UTF8* sourceend = sourcestart + widesize; UTF32* targetstart = reinterpret_cast(widestringnative); - UTF32* targetend = targetstart + widesize; + UTF32* targetend = targetstart + widesize+1; ConversionResult res = ConvertUTF8toUTF32(&sourcestart, sourceend, &targetstart, targetend, strictConversion); if (res != conversionOK) {