Skip to content

Commit

Permalink
Fix copy_to_slice to use correct increment var
Browse files Browse the repository at this point in the history
This patch fixes the `copy_to_slice` function, rectifying the logic.
However, the incorrect code does not result in incorrect behavior as the
only case `cnt != src.len()` is during the final iteration, and since
`src.len()` is greater than `cnt` in that case, `off` will be
incremented by too much, but this will still trigger the `off <
dst.len()` condition.

The only danger is `src.len()` could cause an overflow.
  • Loading branch information
carllerche committed Mar 12, 2018
1 parent bd4630a commit ebe5227
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/buf/buf.rs
Expand Up @@ -218,7 +218,7 @@ pub trait Buf {
ptr::copy_nonoverlapping(
src.as_ptr(), dst[off..].as_mut_ptr(), cnt);

off += src.len();
off += cnt;
}

self.advance(cnt);
Expand Down

0 comments on commit ebe5227

Please sign in to comment.