From ae4b084e77278625703e668686b825f635cd4e00 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 27 Feb 2014 15:46:36 +0000 Subject: [PATCH] Allow passing NULL buffer to wx{,F}File::{Read,Write} when count==0. If the count of bytes to read or write is 0, the buffer pointer value shouldn't matter as it's not used at all anyhow, so relax the assert and allow it to be NULL in this case. Closes #16018. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/ffile.cpp | 6 ++++++ src/common/file.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/common/ffile.cpp b/src/common/ffile.cpp index 0f479565d2..5efeec9f5c 100644 --- a/src/common/ffile.cpp +++ b/src/common/ffile.cpp @@ -125,6 +125,9 @@ bool wxFFile::ReadAll(wxString *str, const wxMBConv& conv) size_t wxFFile::Read(void *pBuf, size_t nCount) { + if ( !nCount ) + return 0; + wxCHECK_MSG( pBuf, 0, wxT("invalid parameter") ); wxCHECK_MSG( IsOpened(), 0, wxT("can't read from closed file") ); @@ -139,6 +142,9 @@ size_t wxFFile::Read(void *pBuf, size_t nCount) size_t wxFFile::Write(const void *pBuf, size_t nCount) { + if ( !nCount ) + return 0; + wxCHECK_MSG( pBuf, 0, wxT("invalid parameter") ); wxCHECK_MSG( IsOpened(), 0, wxT("can't write to closed file") ); diff --git a/src/common/file.cpp b/src/common/file.cpp index b2a5aca736..724da53382 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -325,6 +325,9 @@ bool wxFile::ReadAll(wxString *str, const wxMBConv& conv) // read ssize_t wxFile::Read(void *pBuf, size_t nCount) { + if ( !nCount ) + return 0; + wxCHECK( (pBuf != NULL) && IsOpened(), 0 ); ssize_t iRc = wxRead(m_fd, pBuf, nCount); @@ -341,6 +344,9 @@ ssize_t wxFile::Read(void *pBuf, size_t nCount) // write size_t wxFile::Write(const void *pBuf, size_t nCount) { + if ( !nCount ) + return 0; + wxCHECK( (pBuf != NULL) && IsOpened(), 0 ); ssize_t iRc = wxWrite(m_fd, pBuf, nCount);