Internal: Remove deprecated/insecure functions. No functional change intended.

This commit is contained in:
Wilson Snyder
2021-03-06 10:34:03 -05:00
parent cf9ac8270b
commit 47dcbd4b8a
17 changed files with 109 additions and 77 deletions
+22 -13
View File
@@ -269,7 +269,7 @@ void VerilatedVcd::printStr(const char* str) {
void VerilatedVcd::printQuad(vluint64_t n) {
char buf[100];
sprintf(buf, "%" VL_PRI64 "u", n);
VL_SNPRINTF(buf, 100, "%" VL_PRI64 "u", n);
printStr(buf);
}
@@ -347,9 +347,16 @@ void VerilatedVcd::printIndent(int level_change) {
void VerilatedVcd::dumpHeader() {
printStr("$version Generated by VerilatedVcd $end\n");
time_t time_str = time(nullptr);
printStr("$date ");
printStr(ctime(&time_str));
{
time_t tick = time(nullptr);
tm ticktm;
VL_LOCALTIME_R(&tick, &ticktm);
constexpr int bufsize = 50;
char buf[bufsize];
strftime(buf, bufsize, "%c", &ticktm);
printStr(buf);
}
printStr(" $end\n");
printStr("$timescale ");
@@ -487,11 +494,12 @@ void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep,
decl += wirep; // usually "wire"
}
char buf[1000];
sprintf(buf, " %2d ", bits);
constexpr size_t bufsize = 1000;
char buf[bufsize];
VL_SNPRINTF(buf, bufsize, " %2d ", bits);
decl += buf;
if (m_evcd) {
sprintf(buf, "<%u", code);
VL_SNPRINTF(buf, bufsize, "<%u", code);
decl += buf;
} else {
// Add string code to decl
@@ -505,7 +513,8 @@ void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep,
// 1 bit values don't have a ' ' separator between value and string code
const bool isBit = bits == 1;
entryp[0] = ' '; // Separator
std::strcpy(entryp + !isBit, buf); // Code (overwrite separator if isBit)
// Use memcpy as we checked size above, and strcpy is flagged unsafe
std::memcpy(entryp + !isBit, buf, strlen(buf)); // Code (overwrite separator if isBit)
entryp[length + !isBit] = '\n'; // Replace '\0' with line termination '\n'
// Set length of suffix (used to increment write pointer)
entryp[VL_TRACE_SUFFIX_ENTRY_SIZE - 1] = !isBit + length + 1;
@@ -513,12 +522,12 @@ void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep,
decl += " ";
decl += basename;
if (array) {
sprintf(buf, "(%d)", arraynum);
VL_SNPRINTF(buf, bufsize, "(%d)", arraynum);
decl += buf;
hiername += buf;
}
if (bussed) {
sprintf(buf, " [%d:%d]", msb, lsb);
VL_SNPRINTF(buf, bufsize, " [%d:%d]", msb, lsb);
decl += buf;
}
decl += " $end\n";
@@ -656,8 +665,8 @@ void VerilatedVcd::emitWData(vluint32_t code, const WData* newvalp, int bits) {
VL_ATTR_ALWINLINE
void VerilatedVcd::emitDouble(vluint32_t code, double newval) {
char* wp = m_writep;
// Buffer can't overflow before sprintf; we sized during declaration
sprintf(wp, "r%.16g", newval);
// Buffer can't overflow before VL_SNPRINTF; we sized during declaration
VL_SNPRINTF(wp, m_wrChunkSize, "r%.16g", newval);
wp += strlen(wp);
finishLine(code, wp);
}
@@ -770,8 +779,8 @@ void VerilatedVcd::fullTriArray(vluint32_t code, const vluint32_t* newvalp,
void VerilatedVcd::fullDouble(vluint32_t code, const double newval) {
// cppcheck-suppress invalidPointerCast
(*(reinterpret_cast<double*>(oldp(code)))) = newval;
// Buffer can't overflow before sprintf; we sized during declaration
sprintf(m_writep, "r%.16g", newval);
// Buffer can't overflow before VL_SNPRINTF; we sized during declaration
VL_SNPRINTF(m_writep, m_wrChunkSize, "r%.16g", newval);
m_writep += strlen(m_writep);
*m_writep++ = ' ';
m_writep = writeCode(m_writep, code);