From: Gabe Black Date: Wed, 5 Sep 2018 01:05:13 +0000 (-0700) Subject: systemc: Copy the msgType and msg parameters of sc_report. X-Git-Tag: v19.0.0.0~1662 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fd0da6800aae3eaf46bca4fdbfd85a5f9f161326;p=gem5.git 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 Maintainer: Gabe Black --- 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 + #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()