-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 write* silently sets 0 instead of failing for wrong values #1161
Comments
I think io.js should just check if the argument is a number instead of casting everything to number(or |
Related: #2668 This is because we auto coerce the value like so: Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
value = +value; I did this to improve performance, but forgot about the passing of non-numeric values. Was only considering out of range numeric values. So current functionality doesn't match documentation. The probable best solution is to put the assert checks above the value coercion. We'll work on this in the aforementioned issue. |
On second thought I'm inclined to say that documentation should be updated. Would better read like so:
Basically, it should follow the same coercion rules as |
Per nodejs#1161, when the buf.write*() methods are given anything other than what they expect, indicate that the behavior is unspecified. Fixes: nodejs#1161
Repro:
According to this: https://iojs.org/api/buffer.html#buffer_buf_writeint32le_value_offset_noassert, the last three writes should be failed, because value is not a valid integer.
The text was updated successfully, but these errors were encountered: