Skip to content

Commit

Permalink
fix bug 8089
Browse files Browse the repository at this point in the history
  • Loading branch information
clock999 committed Feb 14, 2025
1 parent 5ff116d commit 5499844
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions htmlreport/cppcheck-htmlreport
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def blame_lookup(blame_data, line):
return next((data for start, end, data in blame_data if line >= start and line < end), {})


def tr_str(td_th, line, id, cwe, severity, message, author, author_mail, date, add_author, tr_class=None, htmlfile=None, message_class=None):
def tr_str(td_th, line, id, cwe, severity, message, timestamp, author, author_mail, date, add_author, tr_class=None, htmlfile=None, message_class=None):
ret = ''
if htmlfile:
ret += '<%s><a href="%s#line-%d">%d</a></%s>' % (td_th, htmlfile, line, line, td_th)
Expand All @@ -485,6 +485,9 @@ def tr_str(td_th, line, id, cwe, severity, message, author, author_mail, date, a
message_attribute = ''
ret += '<%s%s>%s</%s>' % (td_th, message_attribute, html_escape(message), td_th)

if timestamp:
ret += '<%s>%s</%s>' % (td_th, timestamp, td_th)

for field in add_author:
if field == 'name':
ret += '<%s>%s</%s>' % (td_th, html_escape(author), td_th)
Expand Down Expand Up @@ -579,6 +582,7 @@ class CppCheckHandler(XmlContentHandler):
}],
'id': attributes['id'],
'severity': attributes['severity'],
'timestamp': attributes['timestamp'],
'msg': attributes['msg']
})

Expand All @@ -592,6 +596,7 @@ class CppCheckHandler(XmlContentHandler):
'line': 0,
'id': attributes['id'],
'severity': attributes['severity'],
'timestamp': attributes['timestamp'],
'msg': attributes['msg'],
'verbose': attributes.get('verbose')
}
Expand Down Expand Up @@ -865,7 +870,7 @@ def main() -> None:
output_file.write('\n <table class=\"summaryTable\">')
output_file.write(
'\n %s' %
tr_str('th', 'Line', 'Id', 'CWE', 'Severity', 'Message', 'Author', 'Author mail', 'Date (DD/MM/YYYY)', add_author=add_author_information))
tr_str('th', 'Line', 'Id', 'CWE', 'Severity', 'Message', 'Timestamp', 'Author', 'Author mail', 'Date (DD/MM/YYYY)', add_author=add_author_information))

for filename, data in sorted(files.items()):
file_error = filename in decode_errors or filename.endswith('*')
Expand Down Expand Up @@ -905,7 +910,7 @@ def main() -> None:

output_file.write(
'\n %s' %
tr_str('td', line, error["id"], cwe_url, error["severity"], error["msg"],
tr_str('td', line, error["id"], cwe_url, error["severity"], error["msg"], error["timestamp"],
git_blame_dict.get('author', 'Unknown'), git_blame_dict.get('author-mail', '---'),
git_blame_dict.get('author-time', '---'),
tr_class=to_css_selector(error["id"]) + ' sev_' + error["severity"] + ' issue',
Expand Down
9 changes: 9 additions & 0 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <unordered_map>
#include <utility>

#include <time.h>

#include "xml.h"

const std::set<std::string> ErrorLogger::mCriticalErrorIds{
Expand Down Expand Up @@ -485,6 +487,13 @@ std::string ErrorMessage::toXML() const
{
tinyxml2::XMLPrinter printer(nullptr, false, 2);
printer.OpenElement("error", false);

time_t t = time(NULL);
char * t_s = ctime(&t);
if(t_s) {
printer.PushAttribute("timestamp", t_s);
}

printer.PushAttribute("id", id.c_str());
if (!guideline.empty())
printer.PushAttribute("guideline", guideline.c_str());
Expand Down

0 comments on commit 5499844

Please sign in to comment.