From a6ed278608ac63345678c05d66f534b34e40cba7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 13 Apr 2009 17:49:56 +0000 Subject: [PATCH] better check for conversion failure in OutputString(); use wxScopedCharBuffer::length() instead of strlen() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/xml/xml.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/xml/xml.cpp b/src/xml/xml.cpp index 0f5e61d83c..a37225c3dd 100644 --- a/src/xml/xml.cpp +++ b/src/xml/xml.cpp @@ -783,12 +783,18 @@ bool OutputString(wxOutputStream& stream, #if wxUSE_UNICODE wxUnusedVar(convMem); + if ( !convFile ) + convFile = &wxConvUTF8; - const wxWX2MBbuf buf(str.mb_str(*(convFile ? convFile : &wxConvUTF8))); - if ( !buf ) + const wxScopedCharBuffer buf(str.mb_str(*convFile)); + if ( !buf.length() ) + { + // conversion failed, can't write this string in an XML file in this + // (presumably non-UTF-8) encoding return false; + } - stream.Write(buf, strlen(buf)); + stream.Write(buf, buf.length()); #else // !wxUSE_UNICODE if ( convFile && convMem ) { -- 2.45.2