diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-03-30 16:49:40 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-03-30 16:52:38 +0400 |
commit | b82b4f2993b5feaa51ce8edce60d945a34b88d26 (patch) | |
tree | cc5ec6bea53dfb284a3a3fcf5c4ba8e525597c69 | |
parent | 0f0557d78dfa3d4f92daf4558570384ce73b0953 (diff) |
buffer: fix signedness compiler warnings
-rw-r--r-- | src/node_buffer.cc | 37 | ||||
-rw-r--r-- | 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 26d7eebcbc6..7253662d606 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -406,12 +406,11 @@ Handle<Value> Buffer::Copy(const Arguments &args) { } Local<Object> 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<Value> 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<Value> Buffer::AsciiWrite(const Arguments &args) { } Local<String> 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<Value> 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<Value> Buffer::BinaryWrite(const Arguments &args) { } Local<String> 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<Value> 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 c36f20b2f04..38c1e2d29c1 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<v8::FunctionTemplate> constructor_template; |