warning about missing format string annotations

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: warning about missing format string annotations
Date: 2022-09-16 01:54:38
Message-ID: 20220916015438.6z62qowmuqnrpzmj@awork3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

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

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2022-09-16 07:53:56 pgsql: Don't allow creation of database with ICU locale with unsupporte
Previous Message Tom Lane 2022-09-15 21:18:03 pgsql: Detect format-string mistakes in the libpq_pipeline test module.

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro Horiguchi 2022-09-16 01:55:53 Re: Improve description of XLOG_RUNNING_XACTS
Previous Message Kyotaro Horiguchi 2022-09-16 01:45:54 Re: Assertion failure in WaitForWALToBecomeAvailable state machine