You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Libc++ is not Implicit Integer Truncation Sanitizer clean #39912
int main() {
std::stringstream ss;
ss.write("\xd1", 1);
}
with -fsanitize=implicit-signed-integer-truncation gives:
include/c++/v1/sstream:561:28: runtime error: implicit conversion from type 'std::__1::basic_stringbuf<char, std::__1::char_traits, std::__1::allocator >::int_type' (aka 'int') of value 209 (32-bit, signed) to type 'std::__1::basic_streambuf<char, std::__1::char_traits >::char_type' (aka 'char') changed the value to -47 (8-bit, signed)
basic_stringbuf::overflow converts an int, which is the result of char -> unsigned char -> int conversion, directly to (signed) char.
Activity
eugenis commentedon Feb 1, 2019
assigned to @mclow
mclow commentedon Feb 1, 2019
Sweet! It works! (the integer truncation sanitizer)
mclow commentedon Feb 1, 2019
What happens if you change line 561 of sstream to be:
from
return this->sputc(__c);
to
return this->sputc(traits_type::to_char_type(__c));
?
eugenis commentedon Feb 1, 2019
traits_type::to_char_type makes the cast explicit, and fixes the runtime error
mclow commentedon Feb 1, 2019
I fixed some of this in revision 352926. Leaving this bug open while I do more testing
mclow commentedon Feb 7, 2019
I haven't found any other cases. Closing. Please reopen if you find more.