Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SERVER-7253 use macro for snprintf on Windows instead of function poi…

…nter

Call _snprintf on Windows or snprintf on other platforms directly instead
of through a statically initialized function pointer.  Windows code was
calling sprintf_s, but _snprintf works fine and is already used in other
places in the code.
  • Loading branch information...
commit 9cf0f3c344a4e155e839d2ac04ccec211e70a2eb 1 parent 5493d59
@tadmarshall tadmarshall authored milkie committed
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/mongo/bson/util/builder.h
View
15 src/mongo/bson/util/builder.h
@@ -247,13 +247,10 @@ namespace mongo {
void decouple(); // not allowed. not implemented.
};
- namespace {
#if defined(_WIN32)
- int (*mongo_snprintf)(char *str, size_t size, const char *format, ...) = &sprintf_s;
-#else
- int (*mongo_snprintf)(char *str, size_t size, const char *format, ...) = &snprintf;
+#pragma push_macro("snprintf")
+#define snprintf _snprintf
#endif
- }
/** stringstream deals with locale so this is a lot faster than std::stringstream for UTF8 */
template <typename Allocator>
@@ -301,7 +298,7 @@ namespace mongo {
const int prev = _buf.l;
const int maxSize = 32;
char * start = _buf.grow( maxSize );
- int z = mongo_snprintf( start , maxSize , "%.16g" , x );
+ int z = snprintf( start , maxSize , "%.16g" , x );
verify( z >= 0 );
verify( z < maxSize );
_buf.l = prev + z;
@@ -335,7 +332,7 @@ namespace mongo {
template <typename T>
StringBuilderImpl& SBNUM(T val,int maxSize,const char *macro) {
int prev = _buf.l;
- int z = mongo_snprintf( _buf.grow(maxSize) , maxSize , macro , (val) );
+ int z = snprintf( _buf.grow(maxSize) , maxSize , macro , (val) );
verify( z >= 0 );
verify( z < maxSize );
_buf.l = prev + z;
@@ -346,4 +343,8 @@ namespace mongo {
typedef StringBuilderImpl<TrivialAllocator> StringBuilder;
typedef StringBuilderImpl<StackAllocator> StackStringBuilder;
+#if defined(_WIN32)
+#undef snprintf
+#pragma pop_macro("snprintf")
+#endif
} // namespace mongo
Please sign in to comment.
Something went wrong with that request. Please try again.