[SERVER-36576] Coverity analysis defect 104963: Not restoring ostream format Created: 10/Aug/18  Updated: 29/Oct/23  Resolved: 06/Sep/18

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.1.3

Type: Bug Priority: Minor - P4
Reporter: Coverity Collector User Assignee: Mark Benvenuto
Resolution: Fixed Votes: 0
Labels: coverity, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-36475 Reduce use of stringstream in BSONObj... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Platforms 2018-08-27, Platforms 2018-09-10
Participants:

 Description   

Not restoring the stream format state of an ostream

Defect 104963 (STATIC_C)
Checker STREAM_FORMAT_STATE (subcategory none)
File: /src/mongo/bson/bsonelement.cpp
Function mongo::BSONElement::jsonStringStream(mongo::JsonStringFormat, bool, int, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char>> &) const
/src/mongo/bson/bsonelement.cpp, line: 90
"precision" changes the format state of "s" for category precision.

                    s.precision(16);

/src/mongo/bson/bsonelement.cpp, line: 314
Changing format state of stream "s" for category precision without later restoring it.

    }

File: /src/mongo/bson/bsonelement.cpp
Function mongo::BSONElement::jsonStringStream(mongo::JsonStringFormat, bool, int, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char>> &) const
/src/mongo/bson/bsonelement.cpp, line: 209
"hex" changes the format state of "s" for category basefield.

                s << "\", \"$type\" : \"" << hex;

/src/mongo/bson/bsonelement.cpp, line: 211
"fill" changes the format state of "s" for category fill.

                s.fill('0');

/src/mongo/bson/bsonelement.cpp, line: 212
"dec" changes the format state of "s" for category basefield.

                s << type << dec;

/src/mongo/bson/bsonelement.cpp, line: 314
Changing format state of stream "s" for category fill without later restoring it.

    }



 Comments   
Comment by Githook User [ 06/Sep/18 ]

Author:

{'name': 'Mark Benvenuto', 'email': 'mark.benvenuto@mongodb.com', 'username': 'markbenvenuto'}

Message: SERVER-36576 Restore ostream formatters after change
Branch: master
https://github.com/mongodb/mongo/commit/dfca02c17d430b7b983157154055a58939b22372

Generated at Thu Feb 08 04:43:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.