Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer.prototype.slice mishandles negative index #721

Open
natevw opened this issue Mar 27, 2015 · 1 comment
Open

Buffer.prototype.slice mishandles negative index #721

natevw opened this issue Mar 27, 2015 · 1 comment

Comments

@natevw
Copy link
Contributor

natevw commented Mar 27, 2015

Script:

var b = new Buffer(256);
for (var i = 0, len = b.length; i < len; ++i) b[i] = i;

var s = b.slice(-8);
console.log(s.length, s);

var s2 = b.slice(-16);
console.log(s2.length);

Expected:

postel:fatfs natevw$ node t_buffer.js 
8 <Buffer f8 f9 fa fb fc fd fe ff>
16

Actual:

postel:fatfs natevw$ tessel run -s t_buffer.js 
TESSEL! Connected to TM-00-02-nnn-nnn-nnn.
WARN Warning. Deploying just this file.
INFO Bundling directory /Users/natevw/Desktop/Clients/Technical_Machine/fatfs
INFO Deploying bundle (3.50 KB)...
INFO Running script...
264 <Buffer 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 ...>
272

So it seems the resulting length is the original plus the negative index, even though https://github.com/tessel/runtime/blob/fb2fcbe624bf7a613d2781cedd06641198ef1122/src/colony/lua/colony-node.lua#L228 looks reasonable at first review.

@natevw
Copy link
Contributor Author

natevw commented Mar 27, 2015

Ah! What's happening is the negative number never even hits that code path, but remains in the untouched sourceStart rather than len [sic…it's really the end not a length anyway…].

natevw added a commit to natevw/fatfs that referenced this issue Mar 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant