|
From: Fabrizio F. <fab...@po...> - 2015-06-07 14:03:32
|
Dears,
Playing with strings and $fopen I discovered a possible bug of format_vpiStringVal in vpi_signal.cc.
This function seems to convert all 0s in spaces. This creates problems when a signal is used as first parameter of $fopen and when the signal size is greater than the filename to be open. I've changed the code leaving the space conversion for middle zeros but I've removed the trailing ones.
Here it is the git diff:
diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc
index 552fb49..331b6c1 100644
--- a/vvp/vpi_signal.cc
+++ b/vvp/vpi_signal.cc
@@ -368,6 +368,7 @@ static void format_vpiStringVal(vvp_signal_value*sig, int base, unsigned wid,
don't form an 8 bit group. */
char *rbuf = (char *) need_result_buf(wid/8 + ((wid&7)!=0) + 1, RBUF_VAL);
char *cp = rbuf;
+ char *last_non_null=rbuf;
char tmp = 0;
for (long idx = base+(signed)wid-1; idx >= base; idx -= 1) {
@@ -385,10 +386,11 @@ static void format_vpiStringVal(vvp_signal_value*sig, int base, unsigned wid,
/* Nulls in the middle get turned into spaces. */
*cp++ = tmp ? tmp : ' ';
+ last_non_null = tmp ? cp : last_non_null;
tmp = 0;
}
}
- *cp++ = 0;
+ *last_non_null = 0;
vp->value.str = rbuf;
}
Cheers,
Fabrizio
|