Skip to content

Commit d57b2d6

Browse files
committed
Fix off-by-one in format
he original loop stopped at _Last (condition _First != _Last; ++_First), so the upper bound of each lead-byte range from CPINFOEXW::LeadByte was never marked. The Windows lead-byte ranges are inclusive, so the final byte in each pair must be set.
1 parent c370e05 commit d57b2d6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

stl/src/format.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ extern "C" [[nodiscard]] __std_win_error __stdcall __std_get_cvt(
3131
break;
3232
}
3333

34-
for (unsigned char _First = _Info.LeadByte[_Idx], _Last = _Info.LeadByte[_Idx + 1]; _First != _Last; ++_First) {
35-
_Pcvt->_Isleadbyte[_First >> 3] |= 1u << (_First & 0b111u);
34+
const unsigned int _First = _Info.LeadByte[_Idx];
35+
const unsigned int _Last = _Info.LeadByte[_Idx + 1];
36+
37+
if (_Last < _First) {
38+
continue;
39+
}
40+
41+
for (unsigned int _Byte = _First; _Byte <= _Last; ++_Byte) {
42+
_Pcvt->_Isleadbyte[_Byte >> 3] |= 1u << (_Byte & 0b111u);
3643
}
3744
}
3845

0 commit comments

Comments
 (0)