[libcxx] r228952 - Fixed a problem that UBSAN found, where we were calling memcmp(null, p, 0) - which is undefined behavior

Marshall Clow mclow.lists at gmail.com
Thu Feb 12 11:58:06 PST 2015


Author: marshall
Date: Thu Feb 12 13:58:06 2015
New Revision: 228952

URL: http://llvm.org/viewvc/llvm-project?rev=228952&view=rev
Log:
Fixed a problem that UBSAN found, where we were calling memcmp(null, p, 0) - which is undefined behavior

Modified:
    libcxx/trunk/include/experimental/string_view

Modified: libcxx/trunk/include/experimental/string_view
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/string_view?rev=228952&r1=228951&r2=228952&view=diff
==============================================================================
--- libcxx/trunk/include/experimental/string_view (original)
+++ libcxx/trunk/include/experimental/string_view Thu Feb 12 13:58:06 2015
@@ -375,7 +375,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS
         _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
         {
             size_type __rlen = _VSTD::min( size(), __sv.size());
-            int __retval = _Traits::compare(data(), __sv.data(), __rlen);
+            int __retval = __rlen == 0 ? 0 : _Traits::compare(data(), __sv.data(), __rlen);
             if ( __retval == 0 ) // first __rlen chars matched
                 __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
             return __retval;





More information about the cfe-commits mailing list