Skip to content

Commit 6239b16

Browse files
acmorrowerh
authored andcommitted
SERVER-1498: qualify custom strnlen in bsoninlines, move impl
- strnlen was ambiguous in bsoninlines.h without goodies.h header - goodies.h header includes lots of other stuff, so moved custom strnlen to bson/util/misc.h. - update bsoninlines.h to use namespace qualified name
1 parent 2bc9393 commit 6239b16

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

bson/bsoninlines.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <map>
2121
#include "util/atomic_int.h"
22+
#include "util/misc.h"
2223
#include "../util/hex.h"
2324

2425
namespace mongo {
@@ -263,7 +264,7 @@ namespace mongo {
263264
if ( x > 0 && valuestr()[x-1] == 0 )
264265
return;
265266
StringBuilder buf;
266-
buf << "Invalid dbref/code/string/symbol size: " << x << " strnlen:" << strnlen( valuestr() , x );
267+
buf << "Invalid dbref/code/string/symbol size: " << x << " strnlen:" << mongo::strnlen( valuestr() , x );
267268
msgasserted( 10321 , buf.str() );
268269
break;
269270
}
@@ -274,7 +275,7 @@ namespace mongo {
274275
massert( 10323 , "Invalid CodeWScope string size", totalSize >= strSizeWNull + 4 + 4 );
275276
massert( 10324 , "Invalid CodeWScope string size",
276277
strSizeWNull > 0 &&
277-
(strSizeWNull - 1) == strnlen( codeWScopeCode(), strSizeWNull ) );
278+
(strSizeWNull - 1) == mongo::strnlen( codeWScopeCode(), strSizeWNull ) );
278279
massert( 10325 , "Invalid CodeWScope size", totalSize >= strSizeWNull + 4 + 4 + 4 );
279280
int objSize = *( int * )( value() + 4 + 4 + strSizeWNull );
280281
massert( 10326 , "Invalid CodeWScope object size", totalSize == 4 + 4 + strSizeWNull + objSize );
@@ -343,10 +344,10 @@ namespace mongo {
343344
case RegEx:
344345
{
345346
const char *p = value();
346-
size_t len1 = ( maxLen == -1 ) ? strlen( p ) : strnlen( p, remain );
347+
size_t len1 = ( maxLen == -1 ) ? strlen( p ) : mongo::strnlen( p, remain );
347348
//massert( 10318 , "Invalid regex string", len1 != -1 ); // ERH - 4/28/10 - don't think this does anything
348349
p = p + len1 + 1;
349-
size_t len2 = ( maxLen == -1 ) ? strlen( p ) : strnlen( p, remain - len1 - 1 );
350+
size_t len2 = ( maxLen == -1 ) ? strlen( p ) : mongo::strnlen( p, remain - len1 - 1 );
350351
//massert( 10319 , "Invalid regex options string", len2 != -1 ); // ERH - 4/28/10 - don't think this does anything
351352
x = (int) (len1 + 1 + len2 + 1);
352353
}

bson/util/misc.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,13 @@ namespace mongo {
8282
return buf;
8383
}
8484
};
85-
85+
86+
// Like strlen, but only scans up to n bytes.
87+
// Returns -1 if no '0' found.
88+
inline int strnlen( const char *s, int n ) {
89+
for( int i = 0; i < n; ++i )
90+
if ( !s[ i ] )
91+
return i;
92+
return -1;
93+
}
8694
}

util/goodies.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,6 @@ namespace mongo {
358358
return swapEndian(x);
359359
}
360360
#endif
361-
362-
// Like strlen, but only scans up to n bytes.
363-
// Returns -1 if no '0' found.
364-
inline int strnlen( const char *s, int n ) {
365-
for( int i = 0; i < n; ++i )
366-
if ( !s[ i ] )
367-
return i;
368-
return -1;
369-
}
370361

371362
#if !defined(_WIN32)
372363
typedef int HANDLE;

0 commit comments

Comments
 (0)