This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

buffer: fix signedness compiler warnings

  • Loading branch information...
bnoordhuis committed Mar 30, 2012
1 parent 0f0557d commit b82b4f2993b5feaa51ce8edce60d945a34b88d26
Showing with 19 additions and 20 deletions.
  1. +18 −19 src/node_buffer.cc
  2. +1 −1 src/node_buffer.h
View
@@ -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);
View
@@ -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;

0 comments on commit b82b4f2

Please sign in to comment.