i find printf(char *fmt, ...) function may drop the character '%' in the end of any string.
Such as printf("i can print last %\n") can work as expected , but printf("i can print last %") can't.
The error behavior is reason for c = fmt[++i] & 0xff; if (c == 0) break; .
I think it can be changed as
if (c == 0) {
// when string is '\0' , this loop break at 'for' . So it is security using i - 1 in here.
if (fmt[i - 1] == '%') consputc('%');
break;
}
This is not a bug: % indicates the format for an argument. If you want to print '%', escape the % (i.e., type %%). xv6 printf could give a better error for % followed by a non-format character.
the error function is :
i find
printf(char *fmt, ...)
function may drop the character '%' in the end of any string. Such asprintf("i can print last %\n")
can work as expected , butprintf("i can print last %")
can't. The error behavior is reason forc = fmt[++i] & 0xff; if (c == 0) break;
. I think it can be changed as