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

buffer copy with overlapping regions #8857

Closed
redchair123 opened this issue Dec 10, 2014 · 3 comments
Closed

buffer copy with overlapping regions #8857

redchair123 opened this issue Dec 10, 2014 · 3 comments

Comments

@redchair123
Copy link

The documentation merely says:

The source and target regions can be overlapped.

What is the expected behavior in this case? Experimentally, the line buf.copy(buf, targetStart, sourceStart, sourceEnd) appears to be roughly equivalent to for(var i = sourceEnd - sourceStart; i > 0; --i) buf[targetStart + i - 1] = buf[sourceStart + i - 1];, but the documentation is unclear.

@jasnell
Copy link
Member

jasnell commented Dec 12, 2014

Unfortunately looking at the source doesn't make this one any clearer. Definitely appears to be a straightforward documentation bug. The expected behavior is just that buf1[sourceStart...sourceEnd] is copied to buf1[targetStart...n], where n depends on a number of factors. The sentence about regions being overlapped just adds unnecessary confusion.

@bjouhier
Copy link

@jasnell
Copy link
Member

jasnell commented Dec 13, 2014

Ah yes... completely overlooked that one the first time through. It would definitely be a good thing to call that out a bit more explicitly in the docs then.

jasnell added a commit to jasnell/node-joyent that referenced this issue Dec 16, 2014

Verified

This commit was signed with the committer’s verified signature. The key has expired.
phansch Phil Hansch
jasnell added a commit to jasnell/node-joyent that referenced this issue Dec 16, 2014
jasnell added a commit to jasnell/node-joyent that referenced this issue Dec 17, 2014
Improve documentation for buffer.toString and buffer.copy per issues
nodejs#8859 and
nodejs#8857.
jasnell added a commit to jasnell/node-joyent that referenced this issue Dec 19, 2014
Improvements to document for buffer.toString and buffer.copy per issues
nodejs#8859 and
nodejs#8857

(rebased and on joyent/v0.10 and improved slightly)
tjfontaine pushed a commit that referenced this issue Dec 22, 2014
Better wording for start and end parameters, also document .length
should be considered readonly.

RE: #8857, #8859, #8913
PR: #8910
PR-URL: #8910

Signed-off-by: Timothy J Fontaine <[email protected]>
jasnell added a commit to jasnell/node-joyent that referenced this issue Jan 5, 2015
Better wording for start and end parameters, also document .length
should be considered readonly.

RE: nodejs#8857, nodejs#8859, nodejs#8913
PR: nodejs#8910
PR-URL: nodejs#8910

Signed-off-by: Timothy J Fontaine <[email protected]>
jasnell added a commit to jasnell/node-joyent that referenced this issue Jan 5, 2015
Better wording for start and end parameters, also document .length
should be considered readonly.

RE: nodejs#8857, nodejs#8859, nodejs#8913
PR: nodejs#8910
PR-URL: nodejs#8910

Signed-off-by: Timothy J Fontaine <[email protected]>
@jasnell jasnell closed this as completed Jun 24, 2015
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

4 participants