From 5a9c6f26abe22ebddb46cfa4cfb86194042c4df6 Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Wed, 14 Dec 2011 00:53:30 +0000 Subject: [PATCH] Fix max size and read-only errors in Write(). - A size of zero is now correctly interpreted as unlimited. - The read-only flag is correctly checked. TBR=henrika@webrtc.org TEST=vie_auto_test (for real this time...) Review URL: http://webrtc-codereview.appspot.com/315007 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1176 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/system_wrappers/interface/file_wrapper.h | 3 ++- src/system_wrappers/source/file_impl.cc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/system_wrappers/interface/file_wrapper.h b/src/system_wrappers/interface/file_wrapper.h index d8112ee6d2..71f945aee9 100644 --- a/src/system_wrappers/interface/file_wrapper.h +++ b/src/system_wrappers/interface/file_wrapper.h @@ -40,7 +40,8 @@ public: virtual int CloseFile() = 0; - // Limits the file size. + // Limits the file size to |bytes|. Writing will fail after the cap + // is hit. Pass zero to use an unlimited size. virtual int SetMaxFileSize(size_t bytes) = 0; // Flush any pending writes. diff --git a/src/system_wrappers/source/file_impl.cc b/src/system_wrappers/source/file_impl.cc index 3fc913707f..c58d419168 100644 --- a/src/system_wrappers/source/file_impl.cc +++ b/src/system_wrappers/source/file_impl.cc @@ -232,7 +232,7 @@ int FileWrapperImpl::WriteText(const char* format, ...) bool FileWrapperImpl::Write(const void* buf, int len) { - if (!_readOnly) + if (_readOnly) { return false; } @@ -240,7 +240,7 @@ bool FileWrapperImpl::Write(const void* buf, int len) if (_id != NULL) { // Check if it's time to stop writing. - if (_sizeInBytes + len > _maxSizeInBytes) + if (_maxSizeInBytes > 0 && (_sizeInBytes + len) > _maxSizeInBytes) { Flush(); return false;