diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-03-30 14:49:40 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-03-30 14:52:38 +0200 |
commit | b82b4f2993b5feaa51ce8edce60d945a34b88d26 (patch) | |
tree | cc5ec6bea53dfb284a3a3fcf5c4ba8e525597c69 /src/node_buffer.cc | |
parent | 0f0557d78dfa3d4f92daf4558570384ce73b0953 (diff) | |
download | node-b82b4f2993b5feaa51ce8edce60d945a34b88d26.tar.gz |
buffer: fix signedness compiler warnings
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r-- | src/node_buffer.cc | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 26d7eebcb..7253662d6 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); |