@@ -2142,9 +2142,10 @@ namespace tiny_utf8
2142
2142
*/
2143
2143
inline int compare ( const basic_utf8_string& str ) const noexcept {
2144
2144
size_type my_size = size (), str_size = str.size ();
2145
- if ( my_size != str_size )
2146
- return my_size < str_size ? -1 : 1 ;
2147
- return std::memcmp ( data () , str.data () , my_size );
2145
+ int result = std::memcmp ( data () , str.data () , my_size < str_size ? my_size : str_size );
2146
+ if ( !result && my_size != str_size )
2147
+ result = my_size < str_size ? -1 : 1 ;
2148
+ return result;
2148
2149
}
2149
2150
/* *
2150
2151
* Compare this string with the supplied one.
@@ -2158,9 +2159,10 @@ namespace tiny_utf8
2158
2159
*/
2159
2160
inline int compare ( const std::string& str ) const noexcept {
2160
2161
size_type my_size = size (), str_size = str.size ();
2161
- if ( my_size != str_size )
2162
- return my_size < str_size ? -1 : 1 ;
2163
- return std::memcmp ( data () , str.data () , my_size );
2162
+ int result = std::memcmp ( data () , str.data () , my_size < str_size ? my_size : str_size );
2163
+ if ( !result && my_size != str_size )
2164
+ result = my_size < str_size ? -1 : 1 ;
2165
+ return result;
2164
2166
}
2165
2167
/* *
2166
2168
* Compares this string with the supplied one.
0 commit comments