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:
Diomidis Spinellis 2006-12-03 17:05:04 +00:00
parent 576be2064b
commit 34785a9fc0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=164851

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)