summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel@rtems.org>2021-04-10 20:08:20 -0500
committerJoel Sherrill <joel@rtems.org>2021-04-13 13:53:44 -0500
commit177c7520f45ec474387dced653395f37c1430bb1 (patch)
tree381c7b8be6a91a36d4238dfacad3b333fc940e5f
parent4faf9a6ffc0b5c5562c8471a2b58d7609ef7e645 (diff)
downloadrtems-tools-177c7520f45ec474387dced653395f37c1430bb1.tar.bz2
TraceWriterQEMU.cc: Multiple clean ups
Change sprintf() to strncpy() to avoid buffer overwrite CID 1399603, Switch to auto pointer for iterator. Initialize _pad field of entry CID 1399603, fclose file on error patch CID 1399621,
-rw-r--r--tester/covoar/TraceWriterQEMU.cc25
1 files changed, 13 insertions, 12 deletions
diff --git a/tester/covoar/TraceWriterQEMU.cc b/tester/covoar/TraceWriterQEMU.cc
index cd325b6..4bc9667 100644
--- a/tester/covoar/TraceWriterQEMU.cc
+++ b/tester/covoar/TraceWriterQEMU.cc
@@ -34,9 +34,8 @@
* reading the QEMU coverage data files.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
+#include <cstring>
+#include <cstdio>
#include <iostream>
#include <iomanip>
@@ -107,7 +106,7 @@ namespace Trace {
//
// Write the Header to the file
//
- sprintf( header.magic, "%s", QEMU_TRACE_MAGIC );
+ strncpy( header.magic, QEMU_TRACE_MAGIC, sizeof(header.magic) );
header.version = QEMU_TRACE_VERSION;
header.kind = QEMU_TRACE_KIND_RAW; // XXX ??
header.sizeof_target_pc = 32;
@@ -135,14 +134,15 @@ namespace Trace {
//
// Loop through log and write each entry.
//
- struct trace_entry32 entry;
- TraceList::ranges_t::iterator itr;
-
- for (itr = log->Trace.set.begin(); (itr != log->Trace.set.end()); itr++ ){
- entry.pc = itr->lowAddress;
- entry.size = itr-> length;
- entry.op = TRACE_OP_BLOCK;
- switch (itr->exitReason) {
+
+ for (const auto & itr : log->Trace.set) {
+ struct trace_entry32 entry;
+
+ entry._pad[0] = 0;
+ entry.pc = itr.lowAddress;
+ entry.size = itr.length;
+ entry.op = TRACE_OP_BLOCK;
+ switch (itr.exitReason) {
case TraceList::EXIT_REASON_BRANCH_TAKEN:
entry.op |= taken;
break;
@@ -164,6 +164,7 @@ namespace Trace {
status = ::fwrite( &entry, sizeof(entry), 1, traceFile );
if (status != 1) {
+ ::fclose( traceFile );
std::cerr << "Unable to write entry to " << file << std::endl;
return false;
}