Ness Posted July 28, 2019 Report Share Posted July 28, 2019 Hi, When I try to trace sc_signal<sc_bigint<W> > when W=1024 the following program doesn't finish. However when I try W=1023 and W=1025 the program works as expected. Could you please help me to debug the case? Thank you in advance, Ness Quote #include "systemc.h" #include <iostream> #include <fstream> int sc_main ( int argc, char **argv ) { sc_signal<sc_bigint<1023> > signal_to_trace; sc_start(1, SC_NS); sc_trace_file *Tf = sc_create_vcd_trace_file("waves"); sc_trace(Tf, signal_to_trace, "signal_to_trace"); sc_start(1, SC_NS); sc_close_vcd_trace_file(Tf); return 0 ; } Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted July 28, 2019 Report Share Posted July 28, 2019 I can't reproduce, works fine for sc_bigint<1024> on my side. What compiler and OS do you use? Quote Link to comment Share on other sites More sharing options...
Ness Posted July 29, 2019 Author Report Share Posted July 29, 2019 I'm running the code in Visual Studio 2015 on a Windows 10 64-bit platform. SystemC compiler is "SystemC 2.3.3 (Includes TLM)" from Accellera website. I can do a workaround in my code if this is a problem in my side. Thanks for the quick response! Ness Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted July 29, 2019 Report Share Posted July 29, 2019 Thanks for reporting this. I've reproduced the issue. On my side (VS 2017) it crashes with heap corruption, instead of hanging. But I think this is the same issue. I will debug on this evening. Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted July 30, 2019 Report Share Posted July 30, 2019 There is a buffer overflow bug in vcd_sc_signed_trace::write, someone forgot to reserve a space for null terminator in null-terminated string. void vcd_sc_signed_trace::write(FILE* f) { static std::vector<char> compdata(1024), rawdata(1024); typedef std::vector<char>::size_type size_t; if ( compdata.size() < static_cast<size_t>(object.length()) ) { size_t sz = ( static_cast<size_t>(object.length()) + 4096 ) & (~static_cast<size_t>(4096-1)); std::vector<char>( sz ).swap( compdata ); // resize without copying values std::vector<char>( sz ).swap( rawdata ); } char *rawdata_ptr = &rawdata[0]; for (int bitindex = object.length() - 1; bitindex >= 0; --bitindex) { *rawdata_ptr++ = "01"[object[bitindex].to_bool()]; } *rawdata_ptr = '\0'; compose_data_line(&rawdata[0], &compdata[0]); std::fputs(&compdata[0], f); old_value = object; } When you have sc_bigint<1024> , 1024 chars in compdata and rawdata are not enough to store 1024 symbols, because 1 symbol is required for null terminator assigned here: *rawdata_ptr = '\0'; It will also fail with sc_bigint<4096> Can you add + 1 to size of buffer everywhere , rebuild SystemC and rerun your test? : void vcd_sc_signed_trace::write(FILE* f) { static std::vector<char> compdata(1024 + 1), rawdata(1024 + 1); typedef std::vector<char>::size_type size_t; if ( compdata.size() < static_cast<size_t>(object.length()) ) { size_t sz = ( static_cast<size_t>(object.length()) + 4096 ) & (~static_cast<size_t>(4096-1)); sz ++; ... Same problem also with sc_biguint<1024>. Thanks for finding this bug! Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted September 4, 2019 Report Share Posted September 4, 2019 Fix pushed to the public SystemC repository, see https://github.com/accellera-official/systemc/commit/3e4fc6e0e669c727fcbd46100ee1d7ba58ec5894. This fix will be part of a future release of the Accellera reference implementation. Thanks again for reporting the issue! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.