@@ -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
0 commit comments