[NSWI004] simple_printf

Vojtech Horky horky at d3s.mff.cuni.cz
Fri Oct 2 14:16:41 CEST 2020


Hello.

Dne 02. 10. 20 v 13:39 Jakub Růžička napsal(a):
> I would like to ask, what should happened if, the simple_printf() 
> arguments are not passed correctly (such as simple_printf(%s) - no 
> string ). Should we write some error message,just return nonzero code or 
> just say, that the behaviour is undefined in such cases?

In C, the options are rather limited: there will always be some data on 
the stack that can be read. From inside printf you really cannot check 
it, there is no reflection or other runtime information available.

Probably the only widely used check is the format attribute [1] that 
works for constant strings only anyway.

[1] 
https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/Common-Function-Attributes.html

Thus: it is undefined and it is the responsibility of the caller to 
prevent this behavior.

Cheers,
- VH


More information about the NSWI004 mailing list