summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTad Marshall <tad@10gen.com>2012-10-04 07:58:16 -0400
committerEric Milkie <milkie@10gen.com>2012-11-06 15:41:16 -0500
commit9cf0f3c344a4e155e839d2ac04ccec211e70a2eb (patch)
treea98762ab5e032fac8e04f40213b06201bdbc5e40
parent5493d59afcc142ec870bac56e9ad654872fdce5d (diff)
downloadmongo-9cf0f3c344a4e155e839d2ac04ccec211e70a2eb.tar.gz
SERVER-7253 use macro for snprintf on Windows instead of function pointer
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.
-rw-r--r--src/mongo/bson/util/builder.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h
index b8027e561a2..9b512dba8b3 100644
--- a/src/mongo/bson/util/builder.h
+++ b/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