-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Documentation: Unclear if Buffer buf[i] is bounds-checked #11244
Comments
That part of the documentation is a relic from the past when Buffer didn't inherit from Uint8Array. Now it's technically unnecessary since the behavior of Buffer's array index syntax is exactly as described in ECMAScript 2015 spec. Maybe it should be noted that |
@seishun I would argue though that people shouldn't have to look at 2 sets of documentation (Buffer and Uint8Array) just to figure out what the behavior is. That indirection is not particularly user friendly I think. |
@ronkorving I agree that basic information about |
I do think that array-like-access should be documented to say whether it will throw or return undefined when out of bounds. But let's get some more input from others on this. |
The documentation does have the |
PR-URL: nodejs/node#11286 Fixes: nodejs/node#11244 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl>
From the
buf[i]
documentation forBuffer
, it's unclear whether the following code produces undefined behavior due to out-of-bounds access or does nothing:I think this should be documented.
(I assume it's bounds-checked since
console.log(new Buffer('')[1000])
printsundefined
rather than0
, but I haven't checked the source.)The text was updated successfully, but these errors were encountered: