From 35d764b08c37a42299e79859d16351ffde43af73 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 12 Jun 2001 22:56:40 +0000 Subject: [PATCH] fixed another bug in strconv (Off by one error that did not demonstrate itself in poEdit before because windows native convertion wasn't used due to wxLocale returning cp12xx instead of windows-12xx. MultiByteToWideChar and WideCharToMultiByte return size of needed buffer, not number of output characters. Author of the code didn't know this, hence off by one.) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10557 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/strconv.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index d809945203..8d27a4dd24 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -627,14 +627,18 @@ public: { size_t len = MultiByteToWideChar(CodePage, 0, psz, -1, buf, buf ? n : 0); - return len ? len : (size_t)-1; + //VS: returns # of written chars for buf!=NULL and *size* + // needed buffer for buf==NULL + return len ? (buf ? len : len-1) : (size_t)-1; } size_t WC2MB(char *buf, const wchar_t *psz, size_t n) { size_t len = WideCharToMultiByte(CodePage, 0, psz, -1, buf, buf ? n : 0, NULL, NULL); - return len ? len : (size_t)-1; + //VS: returns # of written chars for buf!=NULL and *size* + // needed buffer for buf==NULL + return len ? (buf ? len : len-1) : (size_t)-1; } bool usable() -- 2.45.2