Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There may have a bug in printf.c. #121

Closed
jasonzhouy opened this issue Apr 22, 2022 · 1 comment
Closed

There may have a bug in printf.c. #121

jasonzhouy opened this issue Apr 22, 2022 · 1 comment

Comments

@jasonzhouy
Copy link

the error function is :

printf.c -> void printf(char *fmt, ...)

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;
}

@kaashoek
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants