diff --git a/headers/private/net/DynamicBuffer.h b/headers/private/net/DynamicBuffer.h index 61961214ba..854a92ed7e 100644 --- a/headers/private/net/DynamicBuffer.h +++ b/headers/private/net/DynamicBuffer.h @@ -14,7 +14,7 @@ class DynamicBuffer { public: - DynamicBuffer(size_t _initialSize = 0); + DynamicBuffer(size_t initialSize = 0); ~DynamicBuffer(); // InitCheck() should be called to guarantee the object initialization @@ -23,11 +23,11 @@ public: // Insert data at the end of the buffer. The buffer will be increased to // accomodate the data if needed. - status_t Insert(const void* _data, size_t _size); + status_t Insert(const void* data, size_t size); // Remove data from the start of the buffer. Move the buffer start // pointer to point to the data following it. - status_t Remove(void* _data, size_t _size); + status_t Remove(void* data, size_t size); // Return a pointer to the underlying buffer. Note this will not // necessarily be a pointer to the start of the allocated memory as the @@ -47,7 +47,7 @@ public: void PrintToStream(); private: - status_t _GrowToFit(size_t _size); + status_t _GrowToFit(size_t size); unsigned char* fBuffer; size_t fBufferSize; diff --git a/src/kits/network/libnetapi/DynamicBuffer.cpp b/src/kits/network/libnetapi/DynamicBuffer.cpp index 874f3bc3c3..ba76c7c12f 100644 --- a/src/kits/network/libnetapi/DynamicBuffer.cpp +++ b/src/kits/network/libnetapi/DynamicBuffer.cpp @@ -12,17 +12,17 @@ #include -DynamicBuffer::DynamicBuffer(size_t _initialSize) : +DynamicBuffer::DynamicBuffer(size_t initialSize) : fBuffer(NULL), fBufferSize(0), fDataStart(0), fDataEnd(0), fInit(B_NO_INIT) { - if (_initialSize > 0) { - fBuffer = new unsigned char[_initialSize]; + if (initialSize > 0) { + fBuffer = new (std::nothrow) unsigned char[initialSize]; if (fBuffer != NULL) { - fBufferSize = _initialSize; + fBufferSize = initialSize; fInit = B_OK; } } @@ -46,33 +46,33 @@ DynamicBuffer::InitCheck() const status_t -DynamicBuffer::Insert(const void* _data, size_t _size) +DynamicBuffer::Insert(const void* data, size_t size) { if (fInit != B_OK) return fInit; - status_t result = _GrowToFit(_size); + status_t result = _GrowToFit(size); if (result != B_OK) return result; - memcpy(fBuffer + fDataEnd, _data, _size); - fDataEnd += _size; + memcpy(fBuffer + fDataEnd, data, size); + fDataEnd += size; return B_OK; } status_t -DynamicBuffer::Remove(void* _data, size_t _size) +DynamicBuffer::Remove(void* data, size_t size) { if (fInit != B_OK) return fInit; - if (fDataStart + _size > fDataEnd) + if (fDataStart + size > fDataEnd) return B_BUFFER_OVERFLOW; - memcpy(_data, fBuffer + fDataStart, _size); - fDataStart += _size; + memcpy(_data, fBuffer + fDataStart, size); + fDataStart += size; if (fDataStart == fDataEnd) fDataStart = fDataEnd = 0; @@ -114,14 +114,14 @@ DynamicBuffer::PrintToStream() status_t -DynamicBuffer::_GrowToFit(size_t _size) +DynamicBuffer::_GrowToFit(size_t size) { if (_size <= fBufferSize - fDataEnd) return B_OK; - size_t newSize = (fBufferSize + _size) * 2; + size_t newSize = (fBufferSize + size) * 2; - unsigned char* newBuffer = new unsigned char[newSize]; + unsigned char* newBuffer = new (std::nothrow) unsigned char[newSize]; if (newBuffer == NULL) return B_NO_MEMORY;