Hi,

On 2022-09-15 21:18:03 +0000, Tom Lane wrote:
> We're so used to having the compiler check this stuff for us that
> a printf-like function without pg_attribute_printf is a land mine.
> I wonder if there is a way to detect such omissions.

gcc has -Wsuggest-attribute=format - but unfortunately its heuristics appear
to be too simplistic to catch many omission. It doesn't catch this one, for
example. But it may still be worth trying out in a few more cases.

           -Wsuggest-attribute=format
           -Wmissing-format-attribute
               Warn about function pointers that might be candidates for 
"format" attributes.  Note these are only possible candidates, not absolute 
ones.
               GCC guesses that function pointers with "format" attributes that 
are used in assignment, initialization, parameter passing or return
               statements should have a corresponding "format" attribute in the 
resulting type.  I.e. the left-hand side of the assignment or
               initialization, the type of the parameter variable, or the 
return type of the containing function respectively should also have a "format"
               attribute to avoid the warning.

               GCC also warns about function definitions that might be 
candidates for "format" attributes.  Again, these are only possible candidates. 
 GCC
               guesses that "format" attributes might be appropriate for any 
function that calls a function like "vprintf" or "vscanf", but this might not
               always be the case, and some functions for which "format" 
attributes are appropriate may not be detected.

Greetings,

Andres Freund


Reply via email to