COMMON: Fix incorrect use of assert() macro
The assert() macro may be compiled to be empty. In that case, its arguments are *NOT* evaluated. Hence, things like assert(doSomething()) must not be used whenever doSomething() has important side effects. Also document BufferedWriteStream::flushBuffer() and explain why it exists parallel to BufferedWriteStream::flush(). svn-id: r54322
This commit is contained in:
parent
bac018a3aa
commit
4707b610fc
2 changed files with 18 additions and 13 deletions
|
@ -331,7 +331,8 @@ BufferedWriteStream::BufferedWriteStream(WriteStream *parentStream, uint32 bufSi
|
|||
}
|
||||
|
||||
BufferedWriteStream::~BufferedWriteStream() {
|
||||
assert(flush());
|
||||
const bool flushResult = flushBuffer();
|
||||
assert(flushResult);
|
||||
|
||||
if (_disposeParentStream)
|
||||
delete _parentStream;
|
||||
|
@ -345,20 +346,20 @@ uint32 BufferedWriteStream::write(const void *dataPtr, uint32 dataSize) {
|
|||
memcpy(_buf + _pos, dataPtr, dataSize);
|
||||
_pos += dataSize;
|
||||
} else if (_bufSize >= dataSize) { // check if we can flush the buffer and load the data
|
||||
// flush the buffer
|
||||
assert(flushBuffer());
|
||||
const bool flushResult = flushBuffer();
|
||||
assert(flushResult);
|
||||
memcpy(_buf, dataPtr, dataSize);
|
||||
_pos += dataSize;
|
||||
} else { // too big for our buffer
|
||||
// flush the buffer
|
||||
assert(flushBuffer());
|
||||
const bool flushResult = flushBuffer();
|
||||
assert(flushResult);
|
||||
return _parentStream->write(dataPtr, dataSize);
|
||||
}
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
bool BufferedWriteStream::flushBuffer() {
|
||||
uint32 bytesToWrite = _pos;
|
||||
const uint32 bytesToWrite = _pos;
|
||||
|
||||
if (bytesToWrite) {
|
||||
_pos = 0;
|
||||
|
@ -368,10 +369,6 @@ bool BufferedWriteStream::flushBuffer() {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool BufferedWriteStream::flush() {
|
||||
return flushBuffer();
|
||||
}
|
||||
|
||||
bool MemoryWriteStreamDynamic::seek(int32 offs, int whence) {
|
||||
// Pre-Condition
|
||||
assert(_pos <= _size);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue