From cb1eb7e29d196cc4febca194b7d295e88c37c093 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 3 Oct 2019 23:42:35 -0700 Subject: [PATCH] base: Ensure %p format arguments are printed as pointers. 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 Maintainer: Andreas Sandberg Tested-by: kokoro --- src/base/cprintf_formats.hh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/base/cprintf_formats.hh b/src/base/cprintf_formats.hh index f55fb955e..cca41e98e 100644 --- a/src/base/cprintf_formats.hh +++ b/src/base/cprintf_formats.hh @@ -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 -- 2.30.2