From e47f18f79fc90a44f8072ca3ecacd2fbd9bb5885 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 9 Oct 2011 22:12:10 -0700 Subject: [PATCH] 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 5a9e4aaec721ab846457060210d834c8e8e0332b) --- vpi/sys_display.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 1ab395e63..4ade4186a 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -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;