Skip to content

Instantly share code, notes, and snippets.

@brapse
Created December 2, 2010 22:25
Show Gist options
  • Select an option

  • Save brapse/726211 to your computer and use it in GitHub Desktop.

Select an option

Save brapse/726211 to your computer and use it in GitHub Desktop.
From 397f328dae32f89c3ab61ac258f40f9a06178ae4 Mon Sep 17 00:00:00 2001
From: Sean Braithwaite <brapse@gmail.com>
Date: Thu, 2 Dec 2010 16:53:16 -0500
Subject: [PATCH] Check buffer length using string length
+ Utf8Length is really slow but has the same semantics in this case
---
src/node_buffer.cc | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index ef74b5a..bc23ed8 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -381,7 +381,7 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
ssize_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),
@@ -406,7 +406,7 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
size_t offset = args[1]->Uint32Value();
- if (s->Utf8Length() > 0 && offset >= buffer->length_) {
+ if (s->Length() > 0 && offset >= buffer->length_) {
return ThrowException(Exception::TypeError(String::New(
"Offset is out of bounds")));
}
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment