casaroli commented on issue #21467:
URL: https://github.com/apache/nuttx/issues/21467#issuecomment-6649291313
@anchao The cases we listed are not programmer errors. They are all valid C:
the format and the arguments agree, as in your first Rust example.
```c
char buf[301];
sprintf(buf, "%300d", 1); /* the width fits the buffer, and 556
bytes are written */
printf("%a|%s\n", 1.0, "x"); /* %a is in C99 and takes a double; %s
gets a wrong pointer on arm64 */
printf("%Lf|%s\n", 1.5L, "x"); /* %Lf takes a long double, and it is
read as a double */
```
The compiler will not solve these, because there is nothing wrong in the
code. GCC 13.2 with `-Wall -Wextra -Wformat=2 -Wformat-overflow=2` and Clang 22
with `-Wall -Wextra -Wformat=2` compile them with no warning. The bug is in
`printf`, and no developer, experienced or not, can avoid it without knowing
the code of `printf`.
We agree on the rest. A wrong type for a conversion, an unknown conversion
and a truncated format are programmer errors, and the same compilers warn about
them with `-Wall`. We spend no flash on the wrong types, and the other two move
behind an option.
So this is the boundary: if the compiler accepts the call, it is correct
usage and `printf` must handle it. If the compiler warns, it is wrong usage.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]