Skip to content

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

Closed

Description

@eugenis
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.

Activity

  1. eugenis commented on Feb 1, 2019

    @eugenis
    ContributorAuthor

    assigned to @mclow

  2. mclow commented on Feb 1, 2019

    @mclow
    Contributor

    Sweet! It works! (the integer truncation sanitizer)

  3. mclow commented on Feb 1, 2019

    @mclow
    Contributor

    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));
    ?

  4. eugenis commented on Feb 1, 2019

    @eugenis
    ContributorAuthor

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

  5. mclow commented on Feb 1, 2019

    @mclow
    Contributor

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

  6. mclow commented on Feb 7, 2019

    @mclow
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillalibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions