Skip to content

Commit b82b4f2

Browse files
committed
buffer: fix signedness compiler warnings
1 parent 0f0557d commit b82b4f2

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/node_buffer.cc

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,11 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
406406
}
407407

408408
Local<Object> target = args[0]->ToObject();
409-
char *target_data = Buffer::Data(target);
410-
ssize_t target_length = Buffer::Length(target);
411-
412-
ssize_t target_start = args[1]->Int32Value();
413-
ssize_t source_start = args[2]->Int32Value();
414-
ssize_t source_end = args[3]->IsInt32() ? args[3]->Int32Value()
409+
char* target_data = Buffer::Data(target);
410+
size_t target_length = Buffer::Length(target);
411+
size_t target_start = args[1]->Uint32Value();
412+
size_t source_start = args[2]->Uint32Value();
413+
size_t source_end = args[3]->IsUint32() ? args[3]->Uint32Value()
415414
: source->length_;
416415

417416
if (source_end < source_start) {
@@ -424,25 +423,24 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
424423
return scope.Close(Integer::New(0));
425424
}
426425

427-
if (target_start < 0 || target_start >= target_length) {
426+
if (target_start >= target_length) {
428427
return ThrowException(Exception::Error(String::New(
429428
"targetStart out of bounds")));
430429
}
431430

432-
if (source_start < 0 || source_start >= source->length_) {
431+
if (source_start >= source->length_) {
433432
return ThrowException(Exception::Error(String::New(
434433
"sourceStart out of bounds")));
435434
}
436435

437-
if (source_end < 0 || source_end > source->length_) {
436+
if (source_end > source->length_) {
438437
return ThrowException(Exception::Error(String::New(
439438
"sourceEnd out of bounds")));
440439
}
441440

442-
ssize_t to_copy = MIN(MIN(source_end - source_start,
443-
target_length - target_start),
444-
source->length_ - source_start);
445-
441+
size_t to_copy = MIN(MIN(source_end - source_start,
442+
target_length - target_start),
443+
source->length_ - source_start);
446444

447445
// need to use slightly slower memmove is the ranges might overlap
448446
memmove((void *)(target_data + target_start),
@@ -551,17 +549,17 @@ Handle<Value> Buffer::AsciiWrite(const Arguments &args) {
551549
}
552550

553551
Local<String> s = args[0]->ToString();
554-
552+
size_t length = s->Length();
555553
size_t offset = args[1]->Int32Value();
556554

557-
if (s->Length() > 0 && offset >= buffer->length_) {
555+
if (length > 0 && offset >= buffer->length_) {
558556
return ThrowException(Exception::TypeError(String::New(
559557
"Offset is out of bounds")));
560558
}
561559

562560
size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
563561
: args[2]->Uint32Value();
564-
max_length = MIN(s->Length(), MIN(buffer->length_ - offset, max_length));
562+
max_length = MIN(length, MIN(buffer->length_ - offset, max_length));
565563

566564
char *p = buffer->data_ + offset;
567565

@@ -590,10 +588,11 @@ Handle<Value> Buffer::Base64Write(const Arguments &args) {
590588
}
591589

592590
String::AsciiValue s(args[0]);
591+
size_t length = s.length();
593592
size_t offset = args[1]->Int32Value();
594593
size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
595594
: args[2]->Uint32Value();
596-
max_length = MIN(s.length(), MIN(buffer->length_ - offset, max_length));
595+
max_length = MIN(length, MIN(buffer->length_ - offset, max_length));
597596

598597
if (max_length && offset >= buffer->length_) {
599598
return ThrowException(Exception::TypeError(String::New(
@@ -653,7 +652,7 @@ Handle<Value> Buffer::BinaryWrite(const Arguments &args) {
653652
}
654653

655654
Local<String> s = args[0]->ToString();
656-
655+
size_t length = s->Length();
657656
size_t offset = args[1]->Int32Value();
658657

659658
if (s->Length() > 0 && offset >= buffer->length_) {
@@ -665,7 +664,7 @@ Handle<Value> Buffer::BinaryWrite(const Arguments &args) {
665664

666665
size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
667666
: args[2]->Uint32Value();
668-
max_length = MIN(s->Length(), MIN(buffer->length_ - offset, max_length));
667+
max_length = MIN(length, MIN(buffer->length_ - offset, max_length));
669668

670669
int written = DecodeWrite(p, max_length, s, BINARY);
671670

src/node_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace node {
6666
class NODE_EXTERN Buffer: public ObjectWrap {
6767
public:
6868
// mirrors deps/v8/src/objects.h
69-
static const int kMaxLength = 0x3fffffff;
69+
static const unsigned int kMaxLength = 0x3fffffff;
7070

7171
static v8::Persistent<v8::FunctionTemplate> constructor_template;
7272

0 commit comments

Comments
 (0)