Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ext/nio4r/bytebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,16 @@ static size_t NIO_ByteBuffer_memsize(const void *data)

static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
{
int requested_capacity;
struct NIO_ByteBuffer *buffer;
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);

buffer->capacity = NUM2INT(capacity);
requested_capacity = NUM2INT(capacity);
if (requested_capacity < 0) {
rb_raise(rb_eArgError, "negative capacity given");
}

buffer->capacity = requested_capacity;
buffer->buffer = xmalloc(buffer->capacity);

NIO_ByteBuffer_clear(self);
Expand Down