[ 
https://issues.apache.org/jira/browse/THRIFT-2026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15931388#comment-15931388
 ] 

ASF GitHub Bot commented on THRIFT-2026:
----------------------------------------

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.

----


> Fix TCompactProtocol 64 bit builds
> ----------------------------------
>
>                 Key: THRIFT-2026
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2026
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library
>    Affects Versions: 0.9
>         Environment: Mac 64, Win 64, Linux 64
>            Reporter: Ben Craig
>            Assignee: Ben Craig
>             Fix For: 0.9.2
>
>         Attachments: compact_int_stuff.patch
>
>
> TCompactProtocol has several places where it truncates a size_t to a 32-bit 
> value.
> TCompactProtocol also does bitwise operations on signed values, which has 
> undefined behavior.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to