From c78415729edb31d87133637113e976962bed584b Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Wed, 25 Aug 2010 18:30:51 -0400 Subject: [PATCH] fix lexNumCmp with magic end of marker --- db/update.cpp | 8 +++++--- dbtests/basictests.cpp | 9 ++++++++- util/goodies.h | 8 +++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/db/update.cpp b/db/update.cpp index 4caf93d0351..7891b329048 100644 --- a/db/update.cpp +++ b/db/update.cpp @@ -517,10 +517,12 @@ namespace mongo { DEBUGUPDATE( "\t\t createNewFromMods root: " << root ); BSONObjIteratorSorted es( obj ); BSONElement e = es.next(); - + ModStateHolder::iterator m = _mods.lower_bound( root ); - ModStateHolder::iterator mend = _mods.lower_bound( root + (char)254 ); - + StringBuilder buf(root.size() + 2 ); + buf << root << (char)255; + ModStateHolder::iterator mend = _mods.lower_bound( buf.str() ); + set onedownseen; while ( e.type() && m != mend ){ diff --git a/dbtests/basictests.cpp b/dbtests/basictests.cpp index 27f7cdc90e2..ecba7650be7 100644 --- a/dbtests/basictests.cpp +++ b/dbtests/basictests.cpp @@ -319,6 +319,9 @@ namespace BasicTests { class LexNumCmp { public: void run() { + + ASSERT( ! isNumber( (char)255 ) ); + ASSERT_EQUALS( 0, lexNumCmp( "a", "a" ) ); ASSERT_EQUALS( -1, lexNumCmp( "a", "aa" ) ); ASSERT_EQUALS( 1, lexNumCmp( "aa", "a" ) ); @@ -346,7 +349,7 @@ namespace BasicTests { ASSERT_EQUALS( -1, lexNumCmp( "f12f", "f12g" ) ); ASSERT_EQUALS( 1, lexNumCmp( "f12g", "f12f" ) ); ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aab" ) ); - ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aa1" ) ); + ASSERT_EQUALS( -1, lexNumCmp( "aa{", "aa1" ) ); ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a11" ) ); ASSERT_EQUALS( 1, lexNumCmp( "a1{a", "a1{" ) ); ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a1{a" ) ); @@ -355,6 +358,10 @@ namespace BasicTests { ASSERT_EQUALS( -1 , lexNumCmp( "a.0" , "a.1" ) ); ASSERT_EQUALS( -1 , lexNumCmp( "a.0.b" , "a.1" ) ); + + ASSERT_EQUALS( -1 , lexNumCmp( "b." , "b.|" ) ); + ASSERT_EQUALS( -1 , lexNumCmp( "b.0e" , (string("b.") + (char)255).c_str() ) ); + ASSERT_EQUALS( -1 , lexNumCmp( "b." , "b.0e" ) ); } }; diff --git a/util/goodies.h b/util/goodies.h index 70a154a7e25..8bd4d231a5e 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -652,15 +652,17 @@ namespace mongo { // for convenience, '{' is greater than anything and stops number parsing inline int lexNumCmp( const char *s1, const char *s2 ) { + //cout << "START : " << s1 << "\t" << s2 << endl; while( *s1 && *s2 ) { - bool p1 = ( *s1 == '{' ); - bool p2 = ( *s2 == '{' ); + bool p1 = ( *s1 == (char)255 ); + bool p2 = ( *s2 == (char)255 ); + //cout << "\t\t " << p1 << "\t" << p2 << endl; if ( p1 && !p2 ) return 1; if ( p2 && !p1 ) return -1; - + bool n1 = isNumber( *s1 ); bool n2 = isNumber( *s2 );