08

Be Careful when Using printf()’s return value

#SecureCoding #C/C++
Functions from the printf() family typically return the number of printed characters. This value can be used to determine how many characters are needed on the output medium for a given input to a format string. Depending on your C library, printf() may use an internal dynamic buffer, and memory allocation can fail. In such cases, the function returns a negative number. Therefore, we recommend to always check the return value for positivity when using it in a computation.
Icon with a waving hand

Get in touch

sigma star gmbh
Eduard-Bodem-Gasse 6, 1st floor
6020 Innsbruck | Austria

sigma star gmbh logo