summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChander Sudanthi <chander.sudanthi@arm.com>2012-11-02 11:32:00 -0500
committerChander Sudanthi <chander.sudanthi@arm.com>2012-11-02 11:32:00 -0500
commit322daba74c122c4ba8c89b73ca8107be02990e5c (patch)
tree7417babdcab959f83315caa1feefeedbd9a48d44 /src
parent55787cc0d0ecdbd060f7ee1caaaab90d2482eb67 (diff)
downloadgem5-322daba74c122c4ba8c89b73ca8107be02990e5c.tar.xz
base: Fix a few incorrectly handled print format cases
This patch ensures cases like %0.6u, %06f, and %.6u are processed correctly. The case like %06f is ambiguous and was made to match printf. Also, this patch removes the goto statement in cprintf.cc in favor of a function call.
Diffstat (limited to 'src')
-rw-r--r--src/base/cprintf.cc29
-rw-r--r--src/base/cprintf.hh1
2 files changed, 23 insertions, 7 deletions
diff --git a/src/base/cprintf.cc b/src/base/cprintf.cc
index 4f825c097..2dd2ab486 100644
--- a/src/base/cprintf.cc
+++ b/src/base/cprintf.cc
@@ -69,9 +69,10 @@ Print::process()
while (*ptr) {
switch (*ptr) {
case '%':
- if (ptr[1] != '%')
- goto processing;
-
+ if (ptr[1] != '%') {
+ process_flag();
+ return;
+ }
stream.put('%');
ptr += 2;
break;
@@ -93,10 +94,11 @@ Print::process()
break;
}
}
+}
- return;
-
- processing:
+void
+Print::process_flag()
+{
bool done = false;
bool end_number = false;
bool have_precision = false;
@@ -248,7 +250,20 @@ Print::process()
end_number = false;
number = 0;
}
- }
+
+ if (done) {
+ if ((fmt.format == Format::integer) && have_precision) {
+ // specified a . but not a float, set width
+ fmt.width = fmt.precision;
+ // precision requries digits for width, must fill with 0
+ fmt.fill_zero = true;
+ } else if ((fmt.format == Format::floating) && !have_precision &&
+ fmt.fill_zero) {
+ // ambiguous case, matching printf
+ fmt.precision = fmt.width;
+ }
+ }
+ } // end while
++ptr;
}
diff --git a/src/base/cprintf.hh b/src/base/cprintf.hh
index 6124d8c73..e702fa3a6 100644
--- a/src/base/cprintf.hh
+++ b/src/base/cprintf.hh
@@ -59,6 +59,7 @@ struct Print
Format fmt;
void process();
+ void process_flag();
public:
Print(std::ostream &stream, const std::string &format);