From 03a991bc7aae8849871c8215d3732f431f2f6219 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin <vadim@wxwidgets.org> Date: Fri, 26 Sep 2003 18:15:09 +0000 Subject: [PATCH] always return length of the string, *not* size of the buffer from wxMBConv_win32::MB<->WC(), as documented (fixes bug reported in patch 789039) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23938 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/strconv.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index dd7e60edfb..6621f29859 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -1137,9 +1137,10 @@ public: buf ? n : 0 // size of output buffer ); - // note that it returns # of written chars for buf != NULL and *size* - // of the needed buffer for buf == NULL - return len ? (buf ? len : len - 1) : (size_t)-1; + // note that it returns count of written chars for buf != NULL and size + // of the needed buffer for buf == NULL so in either case the length of + // the string (which never includes the terminating NUL) is one less + return len ? len - 1 : (size_t)-1; } size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const @@ -1156,8 +1157,8 @@ public: NULL // [out] was it used? ); - // see the comment above! - return len ? (buf ? len : len - 1) : (size_t)-1; + // see the comment above for the reason of "len - 1" + return len ? len - 1 : (size_t)-1; } bool IsOk() const -- 2.47.2