Fix long module names crashing string handling (#5546).

This commit is contained in:
Wilson Snyder 2024-10-22 09:25:58 -04:00
parent 2409f32d87
commit 36888fac5d
3 changed files with 7 additions and 13 deletions

View File

@ -85,6 +85,7 @@ Verilator 5.029 devel
* Fix configure inserting absolute paths for Python and Perl (#5504) (#5505). [Nathan Graybeal]
* Fix pattern initialization with typedef key (#5512). [Eugene Feinberg]
* Fix `-j` option without argument in hierarchical Verilation (#5514). [Ryszard Rozak, Antmicro Ltd.]
* Fix long module names crashing string handling (#5546). [Filip Badáň]
Verilator 5.028 2024-08-21

View File

@ -1765,9 +1765,8 @@ IData VL_SYSTEM_IQ(QData lhs) VL_MT_SAFE {
return VL_SYSTEM_IW(VL_WQ_WORDS_E, lhsw);
}
IData VL_SYSTEM_IW(int lhswords, const WDataInP lhsp) VL_MT_SAFE {
char filenamez[VL_VALUE_STRING_MAX_CHARS + 1];
_vl_vint_to_string(lhswords * VL_EDATASIZE, filenamez, lhsp);
return VL_SYSTEM_IN(filenamez);
const std::string lhs = VL_CVT_PACK_STR_NW(lhswords, lhsp);
return VL_SYSTEM_IN(lhs);
}
IData VL_SYSTEM_IN(const std::string& lhs) VL_MT_SAFE {
const int code = std::system(lhs.c_str()); // Yes, std::system() is threadsafe
@ -1917,20 +1916,16 @@ std::string VL_TOUPPER_NN(const std::string& ld) VL_PURE {
std::string VL_CVT_PACK_STR_NW(int lwords, const WDataInP lwp) VL_PURE {
// See also _vl_vint_to_string
char destout[VL_VALUE_STRING_MAX_CHARS + 1];
std::string result;
result.reserve((lwords * VL_EDATASIZE) / 8 + 1);
const int obits = lwords * VL_EDATASIZE;
int lsb = obits - 1;
char* destp = destout;
size_t len = 0;
for (; lsb >= 0; --lsb) {
lsb = (lsb / 8) * 8; // Next digit
const IData charval = VL_BITRSHIFT_W(lwp, lsb) & 0xff;
if (charval) {
*destp++ = static_cast<char>(charval);
++len;
}
if (charval) result += static_cast<char>(charval);
}
return std::string{destout, len};
return result;
}
std::string VL_CVT_PACK_STR_ND(const VlQueue<std::string>& q) VL_PURE {

View File

@ -468,8 +468,6 @@ using ssize_t = uint32_t; ///< signed size_t; returned from read()
#define VL_VALUE_STRING_MAX_WORDS 64 ///< Max size in words of String conversion operation
#endif
#define VL_VALUE_STRING_MAX_CHARS (VL_VALUE_STRING_MAX_WORDS * VL_EDATASIZE / VL_BYTESIZE)
//=========================================================================
// Base macros