Closed ujos closed 6 months ago
Right, it's intentionally UB. The check can't be moved up because res
position can be known only after incoming range is consumed because it can be input range whose size can't be efficiently calculated before copy
. It's user's responsibility to verify that input fits into the array.
In the following code the boundary check assert must be moved before the copy. Otherwise in case of buffer overrun the further application behaviour is undefined.