Permalink
Browse files

Fixed sizing logic error in ensureSpaceFor()

  • Loading branch information...
1 parent 262e138 commit 3d9339e6fe438262e94199620532e4923cfadac5 @tautologistics committed May 13, 2010
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/redis-client.js
View
@@ -691,7 +691,7 @@ Client.prototype.sendCommand = function () {
// If we know how much space we need, use that + 10%.
// Else double the size of the buffer.
- var bufferLength = Math.max(currentLength * 2, atLeast * 1.1);
+ var bufferLength = Math.max(currentLength * 2, offset + atLeast * 1.1);
var newBuffer = new Buffer(Math.round(bufferLength));
self.requestBuffer.copy(newBuffer, 0, 0, offset); // target, targetStart, srcStart, srcEnd
self.requestBuffer = newBuffer;
@@ -708,14 +708,14 @@ Client.prototype.sendCommand = function () {
for (var i=1; i < argCount; ++i) {
var arg = arguments[i];
if (arg instanceof Buffer) {
- ensureSpaceFor(arg.length + arg.length.toString().length + extrasLength + offset);
+ ensureSpaceFor(arg.length + arg.length.toString().length + extrasLength);
offset += this.requestBuffer.asciiWrite('$' + arg.length + CRLF, offset);
offset += arg.copy(this.requestBuffer, offset, 0); // target, targetStart, srcStart
offset += this.requestBuffer.asciiWrite(CRLF, offset);
} else if (arg.toString) {
var asString = arg.toString();
var serialized = '$' + Buffer.byteLength(asString, "binary") + CRLF + asString + CRLF;
- ensureSpaceFor(Buffer.byteLength(serialized, "binary") + offset);
+ ensureSpaceFor(Buffer.byteLength(serialized, "binary"));
offset += this.requestBuffer.binaryWrite(serialized, offset);
}
}

0 comments on commit 3d9339e

Please sign in to comment.