diff --git a/Changes b/Changes index ed2c6e4f2..e58c002b6 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/include/verilated.cpp b/include/verilated.cpp index 612e76a78..9bb99166c 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -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(charval); - ++len; - } + if (charval) result += static_cast(charval); } - return std::string{destout, len}; + return result; } std::string VL_CVT_PACK_STR_ND(const VlQueue& q) VL_PURE { diff --git a/include/verilatedos.h b/include/verilatedos.h index 93c907269..6cb83732f 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -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