Re: LLVM / clang

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: "P(dot) Caillaud" <peufeu(at)peufeu(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: LLVM / clang
Date: 2010-06-11 04:24:56
Message-ID: 28843.1276230296@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Takahiro Itagaki 2010-06-11 05:42:41 Re: LLVM / clang
Previous Message Fujii Masao 2010-06-11 04:18:54 Re: warning message in standby