From b82b4f2993b5feaa51ce8edce60d945a34b88d26 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 30 Mar 2012 14:49:40 +0200 Subject: [PATCH] buffer: fix signedness compiler warnings --- src/node_buffer.cc | 37 ++++++++++++++++++------------------- src/node_buffer.h | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 26d7eebcbc..7253662d60 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -406,12 +406,11 @@ Handle Buffer::Copy(const Arguments &args) { } Local target = args[0]->ToObject(); - char *target_data = Buffer::Data(target); - ssize_t target_length = Buffer::Length(target); - - ssize_t target_start = args[1]->Int32Value(); - ssize_t source_start = args[2]->Int32Value(); - ssize_t source_end = args[3]->IsInt32() ? args[3]->Int32Value() + char* target_data = Buffer::Data(target); + size_t target_length = Buffer::Length(target); + size_t target_start = args[1]->Uint32Value(); + size_t source_start = args[2]->Uint32Value(); + size_t source_end = args[3]->IsUint32() ? args[3]->Uint32Value() : source->length_; if (source_end < source_start) { @@ -424,25 +423,24 @@ Handle Buffer::Copy(const Arguments &args) { return scope.Close(Integer::New(0)); } - if (target_start < 0 || target_start >= target_length) { + if (target_start >= target_length) { return ThrowException(Exception::Error(String::New( "targetStart out of bounds"))); } - if (source_start < 0 || source_start >= source->length_) { + if (source_start >= source->length_) { return ThrowException(Exception::Error(String::New( "sourceStart out of bounds"))); } - if (source_end < 0 || source_end > source->length_) { + if (source_end > source->length_) { return ThrowException(Exception::Error(String::New( "sourceEnd out of bounds"))); } - ssize_t to_copy = MIN(MIN(source_end - source_start, - target_length - target_start), - source->length_ - source_start); - + size_t to_copy = MIN(MIN(source_end - source_start, + target_length - target_start), + source->length_ - source_start); // need to use slightly slower memmove is the ranges might overlap memmove((void *)(target_data + target_start), @@ -551,17 +549,17 @@ Handle Buffer::AsciiWrite(const Arguments &args) { } Local s = args[0]->ToString(); - + size_t length = s->Length(); size_t offset = args[1]->Int32Value(); - if (s->Length() > 0 && offset >= buffer->length_) { + if (length > 0 && offset >= buffer->length_) { return ThrowException(Exception::TypeError(String::New( "Offset is out of bounds"))); } size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset : args[2]->Uint32Value(); - max_length = MIN(s->Length(), MIN(buffer->length_ - offset, max_length)); + max_length = MIN(length, MIN(buffer->length_ - offset, max_length)); char *p = buffer->data_ + offset; @@ -590,10 +588,11 @@ Handle Buffer::Base64Write(const Arguments &args) { } String::AsciiValue s(args[0]); + size_t length = s.length(); size_t offset = args[1]->Int32Value(); size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset : args[2]->Uint32Value(); - max_length = MIN(s.length(), MIN(buffer->length_ - offset, max_length)); + max_length = MIN(length, MIN(buffer->length_ - offset, max_length)); if (max_length && offset >= buffer->length_) { return ThrowException(Exception::TypeError(String::New( @@ -653,7 +652,7 @@ Handle Buffer::BinaryWrite(const Arguments &args) { } Local s = args[0]->ToString(); - + size_t length = s->Length(); size_t offset = args[1]->Int32Value(); if (s->Length() > 0 && offset >= buffer->length_) { @@ -665,7 +664,7 @@ Handle Buffer::BinaryWrite(const Arguments &args) { size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset : args[2]->Uint32Value(); - max_length = MIN(s->Length(), MIN(buffer->length_ - offset, max_length)); + max_length = MIN(length, MIN(buffer->length_ - offset, max_length)); int written = DecodeWrite(p, max_length, s, BINARY); diff --git a/src/node_buffer.h b/src/node_buffer.h index c36f20b2f0..38c1e2d29c 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -66,7 +66,7 @@ namespace node { class NODE_EXTERN Buffer: public ObjectWrap { public: // mirrors deps/v8/src/objects.h - static const int kMaxLength = 0x3fffffff; + static const unsigned int kMaxLength = 0x3fffffff; static v8::Persistent constructor_template;