Skip to content

Commit

Permalink
Fixed sizing logic error in ensureSpaceFor()
Browse files Browse the repository at this point in the history
  • Loading branch information
tautologistics committed May 13, 2010
1 parent 262e138 commit 3d9339e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/redis-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 3d9339e

Please sign in to comment.