Correct handling of format strings with escaped % specifications.

Note: It would be nice to be able to implement getformat() using
fmtcheck(3), but fmtcheck does not distinguish between signed and
unsigned types, a facility jot needs to perform range checks on its
output.

Submitted by:   Per Kristian Hove
MFC after:	2 weeks
This commit is contained in:
dds 2006-12-03 17:05:04 +00:00
parent 86ce72fe0a
commit 552b6c0ead

View File

@ -393,8 +393,11 @@ getformat(void)
if (boring) /* no need to bother */
return;
for (p = format; *p; p++) /* look for '%' */
if (*p == '%' && *(p+1) != '%') /* leave %% alone */
break;
if (*p == '%')
if (p[1] == '%')
p++; /* leave %% alone */
else
break;
sz = sizeof(format) - strlen(format) - 1;
if (!*p && !chardata) {
if (snprintf(p, sz, "%%.%df", prec) >= (int)sz)