• Stephan Hartmann's avatar
    GCC: fix comparison of base::StringPiece in char_traits · 95f68caa
    Stephan Hartmann authored
    Comparing base::StringPiece("\x11\x11") with
    base::StringPiece("\x99\x99") wrongly returns that "\x99\x99" is smaller
    than "\x11\x11". The problem here is that characters are interpreted
    signed. In previous example 0x99 is therefore interpreted as -104 which
    of course is smaller than 17 (0x11). Clang is not affected, because it
    uses __builtin_memcmp or __builtin_wmemcmp.
    
    Solution is to use std::char_traits<T>::lt, which is constexpr in C++14
    already and handles signed characters correctly.
    
    Bug: 941696
    Change-Id: I24edfa4f92058faf87bd029b06832ae1e9e3a6d5
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2624670
    Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
    Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#843037}
    95f68caa
char_traits.h 2.7 KB