From 54ed0832db2b51a80f63820d10b2395f975d2294 Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 19 Apr 2011 15:31:45 -0700 Subject: [PATCH] Convert a single % at the end of a format string to %%. If there is a single % at the end of a format string then automatically convert this to %% so that we get a single % in the output. --- vpi/sys_display.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 5a5efd19d..00f91ebd3 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2011 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -172,7 +172,7 @@ static char * format_as_string(int ljust, int plus, int ld_zero, int width, size += sprintf(&buf[size], "%d", width); if (prec != -1) size += sprintf(&buf[size], ".%d", prec); - buf[size++] = fmt; + if (fmt) buf[size++] = fmt; /* The same goes here ">"! */ buf[size++] = '>'; buf[size] = '\0'; @@ -277,6 +277,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus, switch (fmt) { case '%': + case '\0': if (ljust != 0 || plus != 0 || ld_zero != 0 || width != -1 || prec != -1) { vpi_printf("WARNING: %s:%d: invalid format %s%s.\n", @@ -845,7 +846,7 @@ static unsigned int get_format(char **rtn, char *fmt, memcpy(*rtn+size-1, result, cnt); free(result); size += cnt; - cp += 1; + if (*cp) cp += 1; } } *(*rtn+size-1) = '\0';