Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to _VL_VINT_TO_STRING in ./include/verilated.cpp #931

Closed
veripoolbot opened this issue Jun 12, 2015 · 3 comments
Closed

fix to _VL_VINT_TO_STRING in ./include/verilated.cpp #931

veripoolbot opened this issue Jun 12, 2015 · 3 comments
Labels
area: wrong runtime result Issue involves an incorrect runtine result from Verilated model resolution: fixed Closed; fixed

Comments

@veripoolbot
Copy link
Contributor


Author Name: Fabrizio Ferrandi
Original Redmine Issue: 931 from https://www.veripool.org
Original Date: 2015-06-12


Dears,

there is a subtile bug in function _VL_VINT_TO_STRING that prevents the removal of trailing spaces.
The HEAD code is the following:
@void _VL_VINT_TO_STRING(int obits, char* destoutp, WDataInP sourcep) {
// See also VL_DATA_TO_STRING_NW
int lsb=obits-1;
bool start=true;
char* destp = destoutp;
for (; lsb>=0; lsb--) {
lsb = (lsb / 8) * 8; // Next digit
IData charval = (sourcep[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb)) & 0xff;
if (!start || charval) {
*destp++ = (charval==0)?' ':charval;
start = false; // Drop leading 0s
}
}
destp++ = '\0'; // Terminate
while (isspace(
(destp-1)) && destp>destoutp) *--destp = '\0'; // Drop trailing spaces
}
@
The problem is the following line just before the trailing spaces removal.
@ *destp++ = '\0'; // Terminate
@
The postincrement has to be removed otherwise isspace will not check the possible space but the null character.

Cheers,

Fabrizio

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Fabrizio Ferrandi
Original Date: 2015-06-12T05:29:41Z


Dears,

there is a subtile bug in function _VL_VINT_TO_STRING that prevents the removal of trailing spaces.

The HEAD code is the following:

void _VL_VINT_TO_STRING(int obits, char* destoutp, WDataInP sourcep) {
     // See also VL_DATA_TO_STRING_NW
     int lsb=obits-1;
     bool start=true;
     char* destp = destoutp;
     for (; lsb>=0; lsb--) {
	lsb = (lsb / 8) * 8; // Next digit
	IData charval = (sourcep[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb)) & 0xff;
	if (!start || charval) {
	    *destp++ = (charval==0)?' ':charval;
	    start = false;	// Drop leading 0s
	}
     }
     *destp++ = '\0'; // Terminate
     while (isspace(*(destp-1)) && destp>destoutp) *--destp = '\0';  // Drop trailing spaces
}

The problem is the following line just before the trailing spaces removal.

*destp++ = '\0'; // Terminate

The post-increment has to be removed otherwise isspace will not check the possible space but the null character.

Cheers,

Fabrizio

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2015-06-12T11:28:49Z


Thanks for diagnosing. Fixed in git towards 3.875.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2015-08-13T01:44:27Z


In 3.876.

@veripoolbot veripoolbot added area: wrong runtime result Issue involves an incorrect runtine result from Verilated model resolution: fixed Closed; fixed labels Dec 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: wrong runtime result Issue involves an incorrect runtine result from Verilated model resolution: fixed Closed; fixed
Projects
None yet
Development

No branches or pull requests

1 participant