buffer: standardize array index check

ParseArrayIndex() was requesting a Uint32Value(), but assigning it to an
in32_t. This caused slight differences in error message reported in edge
cases of argument parsing. Fixed by getting the IntegerValue() before
checking if the value is < 0. Added test of API that was affected.

PR-URL: https://github.com/nodejs/node/pull/6084
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Trevor Norris authored and Myles Borins committed 2016-04-20 16:24:21 -07:00
1 parent 440d1172fd
commit d44540f5af
2 files changed
+7 -1

No files matched your search

+1 -1
View File
@@ -167,7 +167,7 @@ inline MUST_USE_RESULT bool ParseArrayIndex(v8::Local<v8::Value> arg,
return true;
}
int32_t tmp_i = arg->Uint32Value();
int64_t tmp_i = arg->IntegerValue();
if (tmp_i < 0)
return false;
+6
View File
@@ -1429,3 +1429,9 @@ assert.equal(Buffer.prototype.parent, undefined);
assert.equal(Buffer.prototype.offset, undefined);
assert.equal(SlowBuffer.prototype.parent, undefined);
assert.equal(SlowBuffer.prototype.offset, undefined);
// Test that ParseArrayIndex handles full uint32
assert.throws(function() {
Buffer.from(new ArrayBuffer(0), -1 >>> 0);
}, /RangeError: 'offset' is out of bounds/);