base: Save and restore the width setting of streams used with cprintf.
authorGabe Black <gabeblack@google.com>
Tue, 11 Sep 2018 07:55:28 +0000 (00:55 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 11 Sep 2018 21:39:05 +0000 (21:39 +0000)
The flags, precision, and fill character were all being saved and
restored, but cprintf might also change the width setting of the
stream, and that wasn't being saved or restored and could leak from
the cprintf statement.

This change adds the code to save and restore that value.

Change-Id: Ibedb26f7f538cd3be4fe0462d2ee4e5efd62bc59
Reviewed-on: https://gem5-review.googlesource.com/12571
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

src/base/cprintf.cc
src/base/cprintf.hh

index caf1bb847c51758c0e0fddddab1f733c6c139ca5..b764f60e955b388cd929be0cfba753436f35afd6 100644 (file)
@@ -47,6 +47,7 @@ Print::Print(std::ostream &stream, const std::string &format)
     saved_flags = stream.flags();
     saved_fill = stream.fill();
     saved_precision = stream.precision();
+    saved_width = stream.width();
 }
 
 Print::Print(std::ostream &stream, const char *format)
@@ -55,6 +56,7 @@ Print::Print(std::ostream &stream, const char *format)
     saved_flags = stream.flags();
     saved_fill = stream.fill();
     saved_precision = stream.precision();
+    saved_width = stream.width();
 }
 
 Print::~Print()
@@ -310,6 +312,7 @@ Print::end_args()
     stream.flags(saved_flags);
     stream.fill(saved_fill);
     stream.precision(saved_precision);
+    stream.width(saved_width);
 }
 
 } // namespace cp
index 14b663c9c12634e2a68ac0ebce614e073224b1c8..9141769fb11967c6edaac86226c4fe139b59f61b 100644 (file)
@@ -54,6 +54,7 @@ struct Print
     std::ios::fmtflags saved_flags;
     char saved_fill;
     int saved_precision;
+    int saved_width;
 
     Format fmt;
     void process();