See following code: ``` #include <stdio.h> void f(const char s[5], size_t len) { char b[5]; snprintf(b, len, "%s", s); } int main() { f("Hello World", 4); return 0; } ``` On compiling it with -O2/3 f() gets inlinned and snprintf format checks apply to it even though parameters to snprintf are parameters within f().
The warning is intended (and designed to trigger across inlined function calls). The call to snprintf() truncates the string which may be unintended. To avoid the warning either use the return value of the snprintf function to take some action (i.e., handle the truncation) or use the len argument to specify the precision of the %s directive like so: snprintf (b, sizeof b, "%.*s", (int)len, s);