Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/12571

Change subject: base: Save and restore the width setting of streams used with cprintf.
......................................................................

base: Save and restore the width setting of streams used with cprintf.

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
---
M src/base/cprintf.cc
M src/base/cprintf.hh
2 files changed, 4 insertions(+), 0 deletions(-)



diff --git a/src/base/cprintf.cc b/src/base/cprintf.cc
index caf1bb8..b764f60 100644
--- a/src/base/cprintf.cc
+++ b/src/base/cprintf.cc
@@ -47,6 +47,7 @@
     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 @@
     saved_flags = stream.flags();
     saved_fill = stream.fill();
     saved_precision = stream.precision();
+    saved_width = stream.width();
 }

 Print::~Print()
@@ -310,6 +312,7 @@
     stream.flags(saved_flags);
     stream.fill(saved_fill);
     stream.precision(saved_precision);
+    stream.width(saved_width);
 }

 } // namespace cp
diff --git a/src/base/cprintf.hh b/src/base/cprintf.hh
index 14b663c..9141769 100644
--- a/src/base/cprintf.hh
+++ b/src/base/cprintf.hh
@@ -54,6 +54,7 @@
     std::ios::fmtflags saved_flags;
     char saved_fill;
     int saved_precision;
+    int saved_width;

     Format fmt;
     void process();

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12571
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ibedb26f7f538cd3be4fe0462d2ee4e5efd62bc59
Gerrit-Change-Number: 12571
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to