From c9d2400dd0dac7ca1e27dd57899843c703123e2c Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Thu, 19 Mar 2009 05:27:48 +0200 Subject: [PATCH] fixing: %0b format prints nothing for a 0 input the following example returns ||. This patch fixes it to return |0|. module t(); wire [3:0] b; initial $monitor("|%0b|", b); assign b = 0; endmodule --- vpi/sys_display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 3ff0e2ebc..35a63414c 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -328,7 +328,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus, if (ld_zero == 1) { /* Strip the leading zeros if a width is not given. */ - if (width == -1) while (*cp == '0') cp++; + if (width == -1) while (*cp == '0' && *(cp+1) != '\0') cp++; /* Pad with leading zeros. */ else if (ljust == 0 && (signed)swidth < width) { unsigned pad = (unsigned)width - swidth; @@ -337,7 +337,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus, strcpy(cp+pad, value.value.str); free_flag = 1; /* For a left aligned value also strip the leading zeros. */ - } else if (ljust != 0) while (*cp == '0') cp++; + } else if (ljust != 0) while (*cp == '0' && *(cp+1) != '\0') cp++; } /* If a width was not given, use a width of zero. */