GitHub user jbapple-cloudera opened a pull request:

    https://github.com/apache/thrift/pull/1214

    THRIFT-2026: Eliminate some undefined behavior in C/C++

    Clients: glib, C++
    Patch: Jim Apple <jbapple-imp...@apache.org>
    
    These examples of undefined behavior were found using Clang's
    UndefinedBehaviorSanitizer (UBSan). To check them, first set your C and C++
    compiler to a recent Clang:
    
        export CC=clang-3.8
        export CXX=clang++-3.8
    
    Then run configure with the UBSan flags:
    
        ./configure CFLAGS="-fsanitize=undefined \
        -fno-sanitize-recover=undefined -fno-sanitize=vptr" CXXFLAGS=
        "-fsanitize=undefined -fno-sanitize-recover=undefined \
        -fno-sanitize=vptr"
    
    Then set your environment so that the backtrace can be printed:
    
        export UBSAN_OPTIONS=print_stacktrace=1
    
    Finally, make sure that llvm-symbolizer corresponding to the Clang
    version is in your path:
    
        export PATH=.......:${PATH}
    
    Now you can run the build and test to see the undefined behavior.
    
    The three examples fixed in this commit are:
    
    Enumerations exhibit undefined behavior under bitwise operations; see
    libstdc++'s
    <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56158>. Adding an
    "underlying type" to t_field::e_req fixes it, following C++14 The
    behavior in question is in violation of chapter 5 ("Expressions")
    paragraph 4: "If during the evaluation of an expression, the result is
    not mathematically defined or not in the range of representable values
    for its type, the behavior is undefined." as well as 7.2 ("Enumeration
    declarations"), paragraph 8, which is too long to quote here.
    
    Left shift of negative values, used in zigzag encoding, is undefined
    behavior. See 5.8 ("Shift operators"), paragraph 2 for C++ and 6.5.7
    ("Bitwise shift operators"), paragraph 4 for C99 and C11.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jbapple-cloudera/thrift THRIFT-2026

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/1214.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1214
    
----
commit fd007eccfb652578f556b190caff394cc327978a
Author: Jim Apple <jbapple-imp...@apache.org>
Date:   2017-03-18T19:56:50Z

    THRIFT-2026: Eliminate some undefined behavior in C/C++
    Clients: glib, C++
    Patch: Jim Apple <jbapple-imp...@apache.org>
    
    These examples of undefined behavior were found using Clang's
    UndefinedBehaviorSanitizer (UBSan). To check them, first set your C and C++
    compiler to a recent Clang:
    
        export CC=clang-3.8
        export CXX=clang++-3.8
    
    Then run configure with the UBSan flags:
    
        ./configure CFLAGS="-fsanitize=undefined \
        -fno-sanitize-recover=undefined -fno-sanitize=vptr" CXXFLAGS=
        "-fsanitize=undefined -fno-sanitize-recover=undefined \
        -fno-sanitize=vptr"
    
    Then set your environment so that the backtrace can be printed:
    
        export UBSAN_OPTIONS=print_stacktrace=1
    
    Finally, make sure that llvm-symbolizer corresponding to the Clang
    version is in your path:
    
        export PATH=.......:${PATH}
    
    Now you can run the build and test to see the undefined behavior.
    
    The three examples fixed in this commit are:
    
    Enumerations exhibit undefined behavior under bitwise operations; see
    libstdc++'s
    <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56158>. Adding an
    "underlying type" to t_field::e_req fixes it, following C++14 The
    behavior in question is in violation of chapter 5 ("Expressions")
    paragraph 4: "If during the evaluation of an expression, the result is
    not mathematically defined or not in the range of representable values
    for its type, the behavior is undefined." as well as 7.2 ("Enumeration
    declarations"), paragraph 8, which is too long to quote here.
    
    Left shift of negative values, used in zigzag encoding, is undefined
    behavior. See 5.8 ("Shift operators"), paragraph 2 for C++ and 6.5.7
    ("Bitwise shift operators"), paragraph 4 for C99 and C11.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to