mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
buffer: combine checking range of sourceStart in buf.copy
Merging 2 checking range of sourceStart into 1. Plus, add test case to increase coverage if sourceStart is greater than length of source. PR-URL: https://github.com/nodejs/node/pull/47758 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
528aacab8d
commit
2545019451
3 changed files with 12 additions and 11 deletions
|
@ -222,8 +222,8 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) {
|
|||
sourceStart = 0;
|
||||
} else {
|
||||
sourceStart = toInteger(sourceStart, 0);
|
||||
if (sourceStart < 0)
|
||||
throw new ERR_OUT_OF_RANGE('sourceStart', '>= 0', sourceStart);
|
||||
if (sourceStart < 0 || sourceStart > source.length)
|
||||
throw new ERR_OUT_OF_RANGE('sourceStart', `>= 0 && <= ${source.length}`, sourceStart);
|
||||
}
|
||||
|
||||
if (sourceEnd === undefined) {
|
||||
|
@ -237,12 +237,6 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) {
|
|||
if (targetStart >= target.length || sourceStart >= sourceEnd)
|
||||
return 0;
|
||||
|
||||
if (sourceStart > source.length) {
|
||||
throw new ERR_OUT_OF_RANGE('sourceStart',
|
||||
`<= ${source.length}`,
|
||||
sourceStart);
|
||||
}
|
||||
|
||||
return _copyActual(source, target, targetStart, sourceStart, sourceEnd);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue