When printing a Dec numeric value use the string size and the minimum size.
The vpiDecStrVal case for the get_numeric() function needs to use the
existing string width as the minimum result size. -1 can be represented as
a signed value with a width of 1. This gives a display width of -1 which
is too small for the -1 string value. This was creating valgrind issues.
In general the string value should be the minimum so this is a safe change.
(cherry picked from commit 5a9e4aaec7)
This commit is contained in:
parent
b7b2d710b1
commit
e47f18f79f
|
|
@ -443,7 +443,9 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
|
|||
strcpy(cpb+pad, cp);
|
||||
|
||||
/* If a width was not given, use the default, unless we have a
|
||||
* leading zero (width of zero). */
|
||||
* leading zero (width of zero). Because the width of a real in
|
||||
* Icarus is 1 the string length will set the width of a real
|
||||
* displayed using %d. */
|
||||
if (width == -1) {
|
||||
width = (ld_zero == 1) ? 0 : vpi_get_dec_size(info->items[*idx]);
|
||||
}
|
||||
|
|
@ -855,7 +857,7 @@ static unsigned int get_format(char **rtn, char *fmt,
|
|||
static unsigned int get_numeric(char **rtn, struct strobe_cb_info *info,
|
||||
vpiHandle item)
|
||||
{
|
||||
int size;
|
||||
int size, min;
|
||||
s_vpi_value val;
|
||||
|
||||
val.format = info->default_format;
|
||||
|
|
@ -864,6 +866,11 @@ static unsigned int get_numeric(char **rtn, struct strobe_cb_info *info,
|
|||
switch(info->default_format){
|
||||
case vpiDecStrVal:
|
||||
size = vpi_get_dec_size(item);
|
||||
/* -1 can be represented as a one bit signed value. This returns
|
||||
* a size of 1 which is too small for the -1 string value so make
|
||||
* the string width the minimum display width. */
|
||||
min = strlen(val.value.str);
|
||||
if (size < min) size = min;
|
||||
*rtn = malloc((size+1)*sizeof(char));
|
||||
sprintf(*rtn, "%*s", size, val.value.str);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue