Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

buf.fill(null) behavior #8469

Closed
tonistiigi opened this issue Sep 29, 2014 · 3 comments
Closed

buf.fill(null) behavior #8469

tonistiigi opened this issue Sep 29, 2014 · 3 comments

Comments

@tonistiigi
Copy link

I had some old code that used buf.fill(null) for clearing up buffer contents. Looking at the docs I don't see it mentioned anywhere so I'm not sure if this is something I just came up or picked up from some sample code.

Anyway this used to work in v0.8 and v0.10 but doesn't work in v0.11. I bisected it to this change 4b40358 and because the commit message only mentions strings, I think the null behavior change may be unintentional.

So its something that is not documented/supported but has a potential to break old code.

Do you think this is worth to change the behavior to match old versions. Or should the function return an error for such input?

I could probably provide a PR.

/cc @trevnorris

@trevnorris
Copy link

Thanks for reporting this. It uncovered a critical bug where buf.fill('') (i.e. passing an empty string) causes Node to hang indefinitely. I'll have patch for this shortly.

trevnorris added a commit that referenced this issue Sep 30, 2014
Running fill() with an empty string would cause Node to hang
indefinitely. Now it will return without having operated on the buffer.

User facing function has been pulled into JS to perform all initial
value checks and coercions. The C++ method has been placed on the
"internal" object.

Coerced non-string values to numbers to match v0.10 support.

Simplified logic and changed a couple variable names.

Added tests for fill() and moved them all to the beginning of
buffer-test.js since many other tests depend on fill() working properly.

Fixes: #8469
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
@trevnorris
Copy link

Fixed in 57ed3da. Thanks again for reporting this.

@tonistiigi
Copy link
Author

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants