summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-09-04 18:05:13 -0700
committerGabe Black <gabeblack@google.com>2018-10-03 00:53:29 +0000
commitfd0da6800aae3eaf46bca4fdbfd85a5f9f161326 (patch)
treeb2cf538d3ce346fd334505794d5fddadf6c31e74 /src
parentfc0e22461e51eebcc6919672802fd9f1a3bc860c (diff)
downloadgem5-fd0da6800aae3eaf46bca4fdbfd85a5f9f161326.tar.xz
systemc: Copy the msgType and msg parameters of sc_report.
The original strings pointed to by those parameters may go away before the sc_report has been completely consumed. By copying them, we make sure other consumers downstream can still access them. Change-Id: Iab9a802b7ae3bb5aed3a2716cd92886b8d241dfa Reviewed-on: https://gem5-review.googlesource.com/c/12469 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/systemc/utils/sc_report.cc24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/systemc/utils/sc_report.cc b/src/systemc/utils/sc_report.cc
index 838488021..77da92b57 100644
--- a/src/systemc/utils/sc_report.cc
+++ b/src/systemc/utils/sc_report.cc
@@ -27,6 +27,8 @@
* Authors: Gabe Black
*/
+#include <cstring>
+
#include "base/logging.hh"
#include "systemc/ext/utils/sc_report.hh"
#include "systemc/ext/utils/sc_report_handler.hh"
@@ -34,13 +36,17 @@
namespace sc_core
{
-sc_report::sc_report(sc_severity _severity, const char *_msgType,
- const char *_msg, int _verbosity, const char *_fileName,
+sc_report::sc_report(sc_severity _severity, const char *msg_type,
+ const char *msg, int _verbosity, const char *_fileName,
int _lineNumber, sc_time _time, const char *_processName, int _id) :
- _severity(_severity), _msgType(_msgType), _msg(_msg),
+ _severity(_severity), _msgType(msg_type), _msg(msg),
_verbosity(_verbosity), _fileName(_fileName), _lineNumber(_lineNumber),
_time(_time), _processName(_processName), _id(_id)
{
+ if (_msgType)
+ _msgType = strdup(_msgType);
+ if (_msg)
+ _msg = strdup(_msg);
_what = sc_report_compose_message(*this);
}
@@ -53,8 +59,10 @@ sc_report &
sc_report::operator = (const sc_report &r)
{
_severity = r._severity;
- _msgType = r._msgType;
- _msg = r._msg;
+ free((void *)_msgType);
+ _msgType = r._msgType ? strdup(r._msgType) : nullptr;
+ free((void *)_msg);
+ _msg = r._msg ? strdup(r._msg) : nullptr;
_verbosity = r._verbosity;
_fileName = r._fileName;
_lineNumber = r._lineNumber;
@@ -64,7 +72,11 @@ sc_report::operator = (const sc_report &r)
return *this;
}
-sc_report::~sc_report() throw() {}
+sc_report::~sc_report() throw()
+{
+ free((void *)_msgType);
+ free((void *)_msg);
+}
const char *
sc_report::what() const throw()