mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
towards SERVER-1300 allow zeros in utf8 strings
This commit is contained in:
parent
5ac8be7e3a
commit
4d72b66db3
@ -205,7 +205,9 @@ namespace mongo {
|
||||
}
|
||||
|
||||
/** Size (length) of a string element.
|
||||
You must assure of type String first. */
|
||||
You must assure of type String first.
|
||||
@return string size including terminating null
|
||||
*/
|
||||
int valuestrsize() const {
|
||||
return *reinterpret_cast< const int* >( value() );
|
||||
}
|
||||
|
19
db/key.cpp
19
db/key.cpp
@ -18,6 +18,7 @@
|
||||
|
||||
#include "pch.h"
|
||||
#include "key.h"
|
||||
#include "../util/unittest.h"
|
||||
|
||||
namespace mongo {
|
||||
|
||||
@ -274,12 +275,12 @@ namespace mongo {
|
||||
}
|
||||
case cstring:
|
||||
{
|
||||
unsigned sz = *l;
|
||||
l++; r++; // skip the size byte
|
||||
// todo: see https://jira.mongodb.org/browse/SERVER-1300
|
||||
int res = strcmp((const char *) l, (const char *) r);
|
||||
// use memcmp as we (will) allow zeros in UTF8 strings
|
||||
int res = memcmp(l, r, sz);
|
||||
if( res )
|
||||
return res;
|
||||
unsigned sz = l[-1];
|
||||
l += sz; r += sz;
|
||||
break;
|
||||
}
|
||||
@ -433,4 +434,16 @@ namespace mongo {
|
||||
return p - _keyData;
|
||||
}
|
||||
|
||||
struct CmpUnitTest : public UnitTest {
|
||||
void run() {
|
||||
char a[2];
|
||||
char b[2];
|
||||
a[0] = -3;
|
||||
a[1] = 0;
|
||||
b[0] = 3;
|
||||
b[1] = 0;
|
||||
assert( strcmp(a,b)>0 && memcmp(a,b,2)>0 );
|
||||
}
|
||||
} cunittest;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user