From 9efe0302c3b89c6b8ff7e4a30d98478edfe84433 Mon Sep 17 00:00:00 2001
From: Robin Dunn <robin@alldunn.com>
Date: Mon, 29 Mar 2004 20:01:16 +0000
Subject: [PATCH] Check that the file successfully loaded, use the length read
 for the conversion.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26470 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 contrib/src/stc/stc.cpp    | 6 ++++--
 contrib/src/stc/stc.cpp.in | 6 ++++--
 src/stc/stc.cpp            | 6 ++++--
 src/stc/stc.cpp.in         | 6 ++++--
 4 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp
index efedc9d763..c3a5c5a725 100644
--- a/contrib/src/stc/stc.cpp
+++ b/contrib/src/stc/stc.cpp
@@ -2549,8 +2549,10 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
 #if wxUSE_UNICODE
             wxMemoryBuffer buffer(len+1);
             success = (file.Read(buffer.GetData(), len) == len);
-            ((char*)buffer.GetData())[len] = 0;
-            contents = wxString(buffer, *wxConvCurrent);
+	    if (success) {
+                ((char*)buffer.GetData())[len] = 0;
+                contents = wxString(buffer, *wxConvCurrent, len);
+            }
 #else
             wxString buffer;
             success = (file.Read(wxStringBuffer(buffer, len), len) == len);
diff --git a/contrib/src/stc/stc.cpp.in b/contrib/src/stc/stc.cpp.in
index 473e08d38e..a859ec1a47 100644
--- a/contrib/src/stc/stc.cpp.in
+++ b/contrib/src/stc/stc.cpp.in
@@ -358,8 +358,10 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
 #if wxUSE_UNICODE
             wxMemoryBuffer buffer(len+1);
             success = (file.Read(buffer.GetData(), len) == len);
-            ((char*)buffer.GetData())[len] = 0;
-            contents = wxString(buffer, *wxConvCurrent);
+	    if (success) {
+                ((char*)buffer.GetData())[len] = 0;
+                contents = wxString(buffer, *wxConvCurrent, len);
+            }
 #else
             wxString buffer;
             success = (file.Read(wxStringBuffer(buffer, len), len) == len);
diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp
index efedc9d763..c3a5c5a725 100644
--- a/src/stc/stc.cpp
+++ b/src/stc/stc.cpp
@@ -2549,8 +2549,10 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
 #if wxUSE_UNICODE
             wxMemoryBuffer buffer(len+1);
             success = (file.Read(buffer.GetData(), len) == len);
-            ((char*)buffer.GetData())[len] = 0;
-            contents = wxString(buffer, *wxConvCurrent);
+	    if (success) {
+                ((char*)buffer.GetData())[len] = 0;
+                contents = wxString(buffer, *wxConvCurrent, len);
+            }
 #else
             wxString buffer;
             success = (file.Read(wxStringBuffer(buffer, len), len) == len);
diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in
index 473e08d38e..a859ec1a47 100644
--- a/src/stc/stc.cpp.in
+++ b/src/stc/stc.cpp.in
@@ -358,8 +358,10 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
 #if wxUSE_UNICODE
             wxMemoryBuffer buffer(len+1);
             success = (file.Read(buffer.GetData(), len) == len);
-            ((char*)buffer.GetData())[len] = 0;
-            contents = wxString(buffer, *wxConvCurrent);
+	    if (success) {
+                ((char*)buffer.GetData())[len] = 0;
+                contents = wxString(buffer, *wxConvCurrent, len);
+            }
 #else
             wxString buffer;
             success = (file.Read(wxStringBuffer(buffer, len), len) == len);
-- 
2.45.2