mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 10:03:44 +02:00
Fix string corruption, bug780.
This commit is contained in:
+15
-9
@@ -566,7 +566,8 @@ string V3PreProcImp::defineSubst(V3DefineRef* refp) {
|
||||
bool quote = false;
|
||||
bool haveDefault = false;
|
||||
// Note there's a leading ( and trailing ), so parens==1 is the base parsing level
|
||||
const char* cp=refp->params().c_str();
|
||||
string params = refp->params(); // Must keep in scope
|
||||
const char* cp=params.c_str();
|
||||
if (*cp == '(') cp++;
|
||||
for (; *cp; cp++) {
|
||||
//UINFO(4," Parse Paren="<<paren<<" Arg="<<numArgs<<" token='"<<token<<"' Parse="<<cp<<endl);
|
||||
@@ -1367,9 +1368,11 @@ int V3PreProcImp::getFinalToken(string& buf) {
|
||||
}
|
||||
int tok = m_finToken;
|
||||
buf = m_finBuf;
|
||||
if (0 && debug()>=5) fprintf (stderr,"%d: FIN: %-10s: %s\n",
|
||||
m_lexp->m_tokFilelinep->lineno(),
|
||||
tokenName(tok), V3PreLex::cleanDbgStrg(buf).c_str());
|
||||
if (0 && debug()>=5) {
|
||||
string bufcln = V3PreLex::cleanDbgStrg(buf);
|
||||
fprintf (stderr,"%d: FIN: %-10s: %s\n",
|
||||
m_lexp->m_tokFilelinep->lineno(), tokenName(tok), bufcln.c_str());
|
||||
}
|
||||
// Track `line
|
||||
const char* bufp = buf.c_str();
|
||||
while (*bufp == '\n') bufp++;
|
||||
@@ -1400,7 +1403,7 @@ int V3PreProcImp::getFinalToken(string& buf) {
|
||||
}
|
||||
}
|
||||
// Track newlines in prep for next token
|
||||
for (const char* cp = buf.c_str(); *cp; cp++) {
|
||||
for (string::iterator cp=buf.begin(); cp!=buf.end(); ++cp) {
|
||||
if (*cp == '\n') {
|
||||
m_finAtBol = true;
|
||||
m_finFilelinep->linenoIncInPlace(); // Increment in place to avoid new/delete calls. It's private data.
|
||||
@@ -1422,8 +1425,9 @@ string V3PreProcImp::getline() {
|
||||
string buf;
|
||||
int tok = getFinalToken(buf/*ref*/);
|
||||
if (debug()>=5) {
|
||||
string bufcln = V3PreLex::cleanDbgStrg(buf);
|
||||
fprintf (stderr,"%d: GETFETC: %-10s: %s\n",
|
||||
m_lexp->m_tokFilelinep->lineno(), tokenName(tok), V3PreLex::cleanDbgStrg(buf).c_str());
|
||||
m_lexp->m_tokFilelinep->lineno(), tokenName(tok), bufcln.c_str());
|
||||
}
|
||||
if (tok==VP_EOF) {
|
||||
// Add a final newline, if the user forgot the final \n.
|
||||
@@ -1444,8 +1448,10 @@ string V3PreProcImp::getline() {
|
||||
int len = rtnp-m_lineChars.c_str()+1;
|
||||
string theLine(m_lineChars, 0, len);
|
||||
m_lineChars = m_lineChars.erase(0,len); // Remove returned characters
|
||||
if (debug()>=4) fprintf (stderr,"%d: GETLINE: %s\n",
|
||||
m_lexp->m_tokFilelinep->lineno(),
|
||||
V3PreLex::cleanDbgStrg(theLine).c_str());
|
||||
if (debug()>=4) {
|
||||
string lncln = V3PreLex::cleanDbgStrg(theLine);
|
||||
fprintf (stderr,"%d: GETLINE: %s\n",
|
||||
m_lexp->m_tokFilelinep->lineno(), lncln.c_str());
|
||||
}
|
||||
return theLine;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user