Re: LLVM / clang - Mailing list pgsql-hackers

From Tom Lane
Subject Re: LLVM / clang
Date
Msg-id 28843.1276230296@sss.pgh.pa.us
Whole thread Raw
In response to Re: LLVM / clang  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> [ assorted LLVM warnings ]

> dt_common.c:818:75: warning: more data arguments than '%' conversions
> [-Wformat-extra-args]
>                                 sprintf(str + strlen(str), (min != 0) ?
> "%+03d:%02d" : "%+03d", hour, min);
> ~~~~~~~        ^

> [and a few more like that]

> These are instances where a format string is an expression that results
> in a variable number of format arguments.  Not sure if that is actually
> legal in C.

I believe it's legal, but I'd be in favor of making a project policy
against it, simply because you aren't going to get any static checking
from gcc about whether the arguments match the format string.  There
isn't any good excuse not to code the above like
if (min != 0)    sprintf(str + strlen(str), "%+03d:%02d", hour, min);else    sprintf(str + strlen(str), "%+03d",
hour);

which would produce warnings if you managed to mess up the format match.

> print.c:778:22: warning: field width should have type 'int', but
> argument has type 'unsigned int' [-Wformat]
>                                 fprintf(fout, "%-*s%s\n", (width_total -
> width) / 2, "",

> Not sure about that.

That one, on the other hand, is pretty silly ...
        regards, tom lane


pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: warning message in standby
Next
From: Takahiro Itagaki
Date:
Subject: Re: LLVM / clang