From: Alex Rousskov Date: Tue, 27 Oct 2020 16:11:59 +0000 (+0000) Subject: Fix std::ostream precision settings leak in Progress::print() (#739) X-Git-Tag: 4.15-20210522-snapshot~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9fa45f86f6bd84fa59cf119e592abf1f1b668739;p=thirdparty%2Fsquid.git Fix std::ostream precision settings leak in Progress::print() (#739) No functionality changes expected. Broken since inception (commit 8ecbe78d). Detected by Coverity. CID 1468264: API usage errors(STREAM_FORMAT_STATE) --- diff --git a/src/store_rebuild.cc b/src/store_rebuild.cc index eb39f3fc44..71f343386e 100644 --- a/src/store_rebuild.cc +++ b/src/store_rebuild.cc @@ -244,9 +244,10 @@ void Progress::print(std::ostream &os) const { if (goal > 0) { + const auto savedPrecision = os.precision(2); const auto percent = 100.0 * completed / goal; - os << std::setprecision(2) << percent << "% (" << - completed << " out of " << goal << ")"; + os << percent << "% (" << completed << " out of " << goal << ")"; + (void)os.precision(savedPrecision); } else if (!completed && !goal) { os << "nothing to do"; } else {