[SERVER-7253] Do not use indirect pointer to call 'snprintf' Created: 04/Oct/12  Updated: 11/Jul/16  Resolved: 04/Oct/12

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 2.0.7, 2.2.0
Fix Version/s: 2.2.2, 2.3.0

Type: Bug Priority: Major - P3
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

In src/mongo/bson/util/builder.h in lines 250 to 256, we create a static initializer used to call sprintf_s on Windows or snprintf on other platforms. This makes it possible to crash at startup if another static initializer tries to use this function pointer before this one has run. Since the order in which static initializers run is unspecified by the C++ standard, this should be coded differently.

Since Windows has a '_snprintf' function that does what 'snprintf' does on other platforms, this code can be replaced by a macro.



 Comments   
Comment by auto [ 06/Nov/12 ]

Author:

{u'date': u'2012-10-04T11:58:16Z', u'email': u'tad@10gen.com', u'name': u'Tad Marshall'}

Message: 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.
Branch: v2.2
https://github.com/mongodb/mongo/commit/9cf0f3c344a4e155e839d2ac04ccec211e70a2eb

Comment by Tad Marshall [ 04/Oct/12 ]

Suggest backport to 2.0 and 2.2.

Comment by auto [ 04/Oct/12 ]

Author:

{u'date': u'2012-10-04T04:58:16-07:00', u'email': u'tad@10gen.com', u'name': u'Tad Marshall'}

Message: 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.
Branch: master
https://github.com/mongodb/mongo/commit/eae26e6044aae32b147fcdb511be034dc4163bc8

Generated at Thu Feb 08 03:14:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.