]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't unnecessarily NUL-terminate wxCharBuffer contents.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 8 Dec 2012 00:37:17 +0000 (00:37 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 8 Dec 2012 00:37:17 +0000 (00:37 +0000)
wxCharBuffer already initializes the last byte of the buffer it allocates to 0
so there is no need to do it explicitly.

Also don't allocate an extra byte, wxCharBuffer already adds one to the length
passed to it for the trailing NUL.

See #13885.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73141 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/datstrm.cpp
src/common/ffile.cpp
src/common/strconv.cpp
src/html/htmlfilt.cpp

index 607c542647064d4983d1faff61b3501d4c2ed842..cb76a5528ea30e6831e6fe0c8379e33d6d52329b 100644 (file)
@@ -114,11 +114,10 @@ wxString wxDataInputStream::ReadString()
     if ( len > 0 )
     {
 #if wxUSE_UNICODE
-        wxCharBuffer tmp(len + 1);
+        wxCharBuffer tmp(len);
         if ( tmp )
         {
             m_input->Read(tmp.data(), len);
-            tmp.data()[len] = '\0';
             ret = m_conv->cMB2WX(tmp.data());
         }
 #else
index ae196692041bcc9726fc2c5f530a178e5e394841..1d55267348124b85e4edd84dfdc874d194e9b1c9 100644 (file)
@@ -102,7 +102,7 @@ bool wxFFile::ReadAll(wxString *str, const wxMBConv& conv)
 
     clearerr(m_fp);
 
-    wxCharBuffer buf(length + 1);
+    wxCharBuffer buf(length);
 
     // note that real length may be less than file length for text files with DOS EOLs
     // ('\r's get dropped by CRT when reading which means that we have
index 54df1ff70ab2a94495b1257ca22c6a848b94185f..73fe64d1154150c7cd2480b71781831dbeda97b1 100644 (file)
@@ -460,7 +460,6 @@ wxMBConv::cMB2WC(const char *inBuff, size_t inLen, size_t *outLen) const
         // because we want the buffer to always be NUL-terminated, even if the
         // input isn't (as otherwise the caller has no way to know its length)
         wxWCharBuffer wbuf(dstLen);
-        wbuf.data()[dstLen] = L'\0';
         if ( ToWChar(wbuf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
         {
             if ( outLen )
index 0baea696758c1db86b40fa3c0583fb8bdf2396fe..9bd0d753b6c5d545686c151b812eed81fefb45e6 100644 (file)
@@ -154,9 +154,8 @@ wxString wxHtmlFilterHTML::ReadFile(const wxFSFile& file) const
     else
     {
         size_t size = s->GetSize();
-        wxCharBuffer buf( size+1 );
+        wxCharBuffer buf( size );
         s->Read( buf.data(), size );
-        *(buf.data() + size) = 0;
         wxString tmpdoc( buf, wxConvISO8859_1);
 
         wxString charset = wxHtmlParser::ExtractCharsetInformation(tmpdoc);