Browse Source

buffer: fix signedness compiler warnings

v0.9.1-release
Ben Noordhuis 13 years ago
parent
commit
b82b4f2993
  1. 33
      src/node_buffer.cc
  2. 2
      src/node_buffer.h

33
src/node_buffer.cc

@ -406,12 +406,11 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
} }
Local<Object> target = args[0]->ToObject(); Local<Object> target = args[0]->ToObject();
char *target_data = Buffer::Data(target); char* target_data = Buffer::Data(target);
ssize_t target_length = Buffer::Length(target); size_t target_length = Buffer::Length(target);
size_t target_start = args[1]->Uint32Value();
ssize_t target_start = args[1]->Int32Value(); size_t source_start = args[2]->Uint32Value();
ssize_t source_start = args[2]->Int32Value(); size_t source_end = args[3]->IsUint32() ? args[3]->Uint32Value()
ssize_t source_end = args[3]->IsInt32() ? args[3]->Int32Value()
: source->length_; : source->length_;
if (source_end < source_start) { if (source_end < source_start) {
@ -424,26 +423,25 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
return scope.Close(Integer::New(0)); 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( return ThrowException(Exception::Error(String::New(
"targetStart out of bounds"))); "targetStart out of bounds")));
} }
if (source_start < 0 || source_start >= source->length_) { if (source_start >= source->length_) {
return ThrowException(Exception::Error(String::New( return ThrowException(Exception::Error(String::New(
"sourceStart out of bounds"))); "sourceStart out of bounds")));
} }
if (source_end < 0 || source_end > source->length_) { if (source_end > source->length_) {
return ThrowException(Exception::Error(String::New( return ThrowException(Exception::Error(String::New(
"sourceEnd out of bounds"))); "sourceEnd out of bounds")));
} }
ssize_t to_copy = MIN(MIN(source_end - source_start, size_t to_copy = MIN(MIN(source_end - source_start,
target_length - target_start), target_length - target_start),
source->length_ - source_start); source->length_ - source_start);
// need to use slightly slower memmove is the ranges might overlap // need to use slightly slower memmove is the ranges might overlap
memmove((void *)(target_data + target_start), memmove((void *)(target_data + target_start),
(const void*)(source->data_ + source_start), (const void*)(source->data_ + source_start),
@ -551,17 +549,17 @@ Handle<Value> Buffer::AsciiWrite(const Arguments &args) {
} }
Local<String> s = args[0]->ToString(); Local<String> s = args[0]->ToString();
size_t length = s->Length();
size_t offset = args[1]->Int32Value(); 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( return ThrowException(Exception::TypeError(String::New(
"Offset is out of bounds"))); "Offset is out of bounds")));
} }
size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
: args[2]->Uint32Value(); : 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; char *p = buffer->data_ + offset;
@ -590,10 +588,11 @@ Handle<Value> Buffer::Base64Write(const Arguments &args) {
} }
String::AsciiValue s(args[0]); String::AsciiValue s(args[0]);
size_t length = s.length();
size_t offset = args[1]->Int32Value(); size_t offset = args[1]->Int32Value();
size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
: args[2]->Uint32Value(); : 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_) { if (max_length && offset >= buffer->length_) {
return ThrowException(Exception::TypeError(String::New( return ThrowException(Exception::TypeError(String::New(
@ -653,7 +652,7 @@ Handle<Value> Buffer::BinaryWrite(const Arguments &args) {
} }
Local<String> s = args[0]->ToString(); Local<String> s = args[0]->ToString();
size_t length = s->Length();
size_t offset = args[1]->Int32Value(); size_t offset = args[1]->Int32Value();
if (s->Length() > 0 && offset >= buffer->length_) { 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 size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
: args[2]->Uint32Value(); : 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); int written = DecodeWrite(p, max_length, s, BINARY);

2
src/node_buffer.h

@ -66,7 +66,7 @@ namespace node {
class NODE_EXTERN Buffer: public ObjectWrap { class NODE_EXTERN Buffer: public ObjectWrap {
public: public:
// mirrors deps/v8/src/objects.h // mirrors deps/v8/src/objects.h
static const int kMaxLength = 0x3fffffff; static const unsigned int kMaxLength = 0x3fffffff;
static v8::Persistent<v8::FunctionTemplate> constructor_template; static v8::Persistent<v8::FunctionTemplate> constructor_template;

Loading…
Cancel
Save