From 85d510cd48fcf1e44521f8cbe1f1c7821f44be10 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 16 Feb 2010 11:54:39 -0500 Subject: [PATCH] Fix vl_mc_scan_plusarg returning stack based pointer --- include/verilated.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/verilated.cpp b/include/verilated.cpp index cb33f1af2..6ac87df77 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -920,8 +920,12 @@ IData VL_VALUEPLUSARGS_IW(int rbits, const char* prefixp, char fmt, WDataOutP rw const char* vl_mc_scan_plusargs(const char* prefixp) { string match = VerilatedImp::argPlusMatch(prefixp); - if (match == "") return 0; - else return match.c_str()+strlen(prefixp)+1; // +1 to skip the "+" + static VL_THREAD char outstr[VL_VALUE_STRING_MAX_WIDTH]; + if (match == "") return NULL; + strncpy(outstr, match.c_str()+strlen(prefixp)+1, // +1 to skip the "+" + VL_VALUE_STRING_MAX_WIDTH); + outstr[VL_VALUE_STRING_MAX_WIDTH-1] = '\0'; + return outstr; } //===========================================================================