Skip to content

Fix #1615: Encoding exception with VS compiler

Xiang Li requested to merge XiangLi/VVCSoftware_VTM:xlxiangli/fix_1615 into master

This interesting issue looks only with VS compiler. It is related to different implementations of std::copy_n()

For VS, the function is implemented as follows

template<class _SourceTy,
size_t _SourceSize,
class _Diff,
class _DestTy,
size_t _DestSize> inline
_DestTy *copy_n(_SourceTy (&_First)[_SourceSize], _Diff _Count_raw, _DestTy (&_Dest)[_DestSize])
{ // copy [_First, _First + _Count) to [_Dest, ...), array source/dest
const _Algorithm_int_t<_Diff> _Count = _Count_raw;
if (0 < _Count)
{
_STL_VERIFY_ARRAY_SIZE(_First, _Count);
_STL_VERIFY_ARRAY_SIZE(_Dest, _Count);
return (_Copy_n_unchecked3(_First, _Count, _Dest));
}

return (_Dest);
}

The exception was thrown by _STL_VERIFY_ARRAY_SIZE which is as below.

#define _STL_VERIFY_ARRAY_SIZE(_Array, _Desired) \
	_STL_VERIFY((_STD size(_Array) >= static_cast<common_type_t<size_t, \
		decltype(_Desired)>>(_Desired)), "array too small")

Basically, the size of the array is checked by std::size(). Unfortunately, std::size() checks 1-d array size while our intention is to check 2-d array size. As the 1-d array size is smaller than the size of the 2-d array, the exception was thrown. We don't have the issue with gcc as gcc implementation does not verify the array size.

Merge request reports