I think finding a bug where printf("%*.s") was used instead of printf(".*s") was the point at which I realized that some C issues cannot be mitigated with better tooling...

Reply to this note

Please Login to reply.

Discussion

What is your current opinion of C?

Do you like Rust?

Not the compile times!

Yeah, I have noticed. Go is far superior in that regard.

😭😭😭

tinyformat does compile time checks that catch that, for C++ anyway. At least if I'm not misunderstanding the bug.

GCC does compile-time checks too, but they're both valid, and both print a string of the given width, but %*.s is weird and should probably elicit a warning. The man page suggests this will print padding (* specifies the minimum width, . specifies zero precision, so no chars from string are printed) and that the string need not be nul terminated, but it printed something and valgrind complained (string was *not* nul terminated), so I suspect the man page or implementation are wrong.

But it's really a "did you mean %*." warning because I expect no code deliberately does this...

Oh I thought you had a format string where you just wanted a literal. Null termination should still be handled by types (string vs span perhaps) rather than format spec, though i guess that's straying further from C.