Skip to content

Commit

Permalink
Fixed #49 - major bug in basic_utf8_string::compare
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Riedle committed Sep 10, 2020
1 parent a4c5421 commit 68eaf24
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tinyutf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -2142,9 +2142,10 @@ namespace tiny_utf8
*/
inline int compare( const basic_utf8_string& str ) const noexcept {
size_type my_size = size(), str_size = str.size();
if( my_size != str_size )
return my_size < str_size ? -1 : 1;
return std::memcmp( data() , str.data() , my_size );
int result = std::memcmp( data() , str.data() , my_size < str_size ? my_size : str_size );
if( !result && my_size != str_size )
result = my_size < str_size ? -1 : 1;
return result;
}
/**
* Compare this string with the supplied one.
Expand All @@ -2158,9 +2159,10 @@ namespace tiny_utf8
*/
inline int compare( const std::string& str ) const noexcept {
size_type my_size = size(), str_size = str.size();
if( my_size != str_size )
return my_size < str_size ? -1 : 1;
return std::memcmp( data() , str.data() , my_size );
int result = std::memcmp( data() , str.data() , my_size < str_size ? my_size : str_size );
if( !result && my_size != str_size )
result = my_size < str_size ? -1 : 1;
return result;
}
/**
* Compares this string with the supplied one.
Expand Down

0 comments on commit 68eaf24

Please sign in to comment.