base: Ensure %p format arguments are printed as pointers.
authorGabe Black <gabeblack@google.com>
Fri, 4 Oct 2019 06:42:35 +0000 (23:42 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 8 Oct 2019 17:45:53 +0000 (17:45 +0000)
If the %p format is used, char * arguments should be printed as the
hex value of their pointer, not as strings. Unfortunately blindly
passing them to an ostream using << will not do that. This change adds
some casting in that case to ensure that they're treated as numbers and
not as strings.

Change-Id: If02bae6d5e468b352266702fcba62b6beddffcbd
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21459
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/cprintf_formats.hh

index f55fb955e6d0c704f9b4c9f0d2a650002ca2b25c..cca41e98ed85589178781b399537c9805af05794 100644 (file)
@@ -312,6 +312,12 @@ format_integer(std::ostream &out, unsigned char data, Format &fmt)
 inline void
 format_integer(std::ostream &out, signed char data, Format &fmt)
 { _format_integer(out, (int)data, fmt); }
+inline void
+format_integer(std::ostream &out, const unsigned char *data, Format &fmt)
+{ _format_integer(out, (uintptr_t)data, fmt); }
+inline void
+format_integer(std::ostream &out, const signed char *data, Format &fmt)
+{ _format_integer(out, (uintptr_t)data, fmt); }
 
 //
 // floating point formats