Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libc++ is not Implicit Integer Truncation Sanitizer clean #39912

Closed
eugenis opened this issue Feb 1, 2019 · 6 comments
Closed

Libc++ is not Implicit Integer Truncation Sanitizer clean #39912

eugenis opened this issue Feb 1, 2019 · 6 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@eugenis
Copy link
Contributor

eugenis commented Feb 1, 2019

Bugzilla Link 40566
Resolution FIXED
Resolved on Feb 07, 2019 10:08
Version unspecified
OS Linux
CC @dwblaikie,@LebedevRI,@mclow

Extended Description

#include

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.

@eugenis
Copy link
Contributor Author

eugenis commented Feb 1, 2019

assigned to @mclow

@mclow
Copy link
Contributor

mclow commented Feb 1, 2019

Sweet! It works! (the integer truncation sanitizer)

@mclow
Copy link
Contributor

mclow commented 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
Copy link
Contributor Author

eugenis commented Feb 1, 2019

traits_type::to_char_type makes the cast explicit, and fixes the runtime error

@mclow
Copy link
Contributor

mclow commented Feb 1, 2019

I fixed some of this in revision 352926. Leaving this bug open while I do more testing

@mclow
Copy link
Contributor

mclow commented Feb 7, 2019

I haven't found any other cases. Closing. Please reopen if you find more.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants