[Haiku-commits] r28918 - in haiku/trunk: headers/private/net src/kits/network/libnetapi
Stephan Aßmus
superstippi at gmx.de
Sat Jan 17 14:41:42 CET 2009
bga at BerliOS schrieb:
> Author: bga
> Date: 2009-01-17 14:30:21 +0100 (Sat, 17 Jan 2009)
> New Revision: 28918
> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=28918&view=rev
>
> Added:
> haiku/trunk/headers/private/net/DynamicBuffer.h
> haiku/trunk/src/kits/network/libnetapi/DynamicBuffer.cpp
> Log:
> - Simple dynamic buffer class implementation.
> - Will be used by the new (R5 compatible) NetBuffer class.
[...]
> +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 (fBuffer != NULL) {
> + fBufferSize = _initialSize;
> + fInit = B_OK;
> + }
> + }
> +}
[...]
> +status_t
> +DynamicBuffer::_GrowToFit(size_t _size)
> +{
> + if (_size <= fBufferSize - fDataEnd)
> + return B_OK;
> +
> + size_t newSize = (fBufferSize + _size) * 2;
> +
> + unsigned char* newBuffer = new unsigned char[newSize];
> + if (newBuffer == NULL)
> + return B_NO_MEMORY;
These checks for allocation failure do not work. new will throw
std::bad_alloc in case of failure. Instead, you need to use "new
(std::nothrow)" and then you can check the result against NULL.
While I am at it, I hope you don't mind if I mention a slight coding
style violation: The method parameters are not prepended with an
underscore in Haiku code.
Best regards,
-Stephan
More information about the Haiku-commits
mailing list