From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 121026 invoked by alias); 25 Feb 2015 23:36:31 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 121008 invoked by uid 89); 25 Feb 2015 23:36:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,MIME_BASE64_BLANKS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: ausc60pc101.us.dell.com Received: from ausc60pc101.us.dell.com (HELO ausc60pc101.us.dell.com) (143.166.85.206) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Wed, 25 Feb 2015 23:36:29 +0000 X-LoopCount0: from 10.175.216.250 From: To: CC: Subject: Re: format string is not a string literal Date: Thu, 26 Feb 2015 00:12:00 -0000 Message-ID: <23CC7871-C616-436C-920C-4A635DC87189@dell.com> References: <0AB56024-875B-4724-8ED2-A9DDB237CBFF@dell.com> In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-ID: <3C18D7DCFEE5D740AAA4CCDAB3F76144@dell.com> Content-Transfer-Encoding: base64 MIME-Version: 1.0 X-IsSubscribed: yes X-SW-Source: 2015-02/txt/msg00055.txt.bz2 DQo+IE9uIEZlYiAyNSwgMjAxNSwgYXQgNjoyMSBQTSwgSmFjayBIb3dhcnRo IDxob3dhcnRoLm1haWxpbmcubGlzdHNAZ21haWwuY29tPiB3cm90ZToNCj4g DQo+IFBhdWwsDQo+ICAgIFRoZSBjbGFuZyBkZXZlbG9wZXJzIGRpc2FncmVl Li4uDQo+IA0KPiBodHRwOi8vbGx2bS5vcmcvYnVncy9zaG93X2J1Zy5jZ2k/ aWQ9MjI3MDEjYzMNCj4gDQo+ICAgICAgICBKYWNrDQo+IA0KPiB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xlIGJlY2F1c2UgeW91IGNhbuKAmXQg a25vdyB0aGUgYXJndW1lbnQgbGlzdDsgb25seSBpbiBwcmludGYgZG8geW91 IHNlZSB0aGUgYXJndW1lbnRzIHNvIHlvdSBjYW4gbWF0Y2ggdGhlIHR5cGVz LiAgU28gdGhlIGJ1ZyBpcyB0aGF0IGZvcm1hdCBjaGVja2luZyBhbmQgY29t cGxhaW5pbmcgZm9yIG5vbi1saXRlcmFsIGZvcm1hdHMgc2hvdWxkIG5vdCBi ZSBlbmFibGVkIGF0IGFsbCBmb3IgdnByaW50Zi4gIFRoYXQgbWF5IGJlIGEg aGVhZGVyIGlzc3VlIHJhdGhlciB0aGFuIGEgY29tcGlsZXIgaXNzdWUsIGJ1 dCBlaXRoZXIgd2F5LCBpdOKAmXMgbm90IHRoZSByaWdodCB0aGluZyB0byBk by4NCg0KCXBhdWwNCg== >From gdb-return-44134-listarch-gdb=sources.redhat.com@sourceware.org Thu Feb 26 00:06:02 2015 Return-Path: Delivered-To: listarch-gdb@sources.redhat.com Received: (qmail 26607 invoked by alias); 26 Feb 2015 00:06:01 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Delivered-To: mailing list gdb@sourceware.org Received: (qmail 26587 invoked by uid 89); 26 Feb 2015 00:06:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_FROM_URIBL_PCCC,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ig0-f178.google.com Received: from mail-ig0-f178.google.com (HELO mail-ig0-f178.google.com) (209.85.213.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 26 Feb 2015 00:05:59 +0000 Received: by mail-ig0-f178.google.com with SMTP id hl2so10466253igb.5 for ; Wed, 25 Feb 2015 16:05:58 -0800 (PST) X-Received: by 10.107.40.2 with SMTP id o2mr8391463ioo.68.1424909157998; Wed, 25 Feb 2015 16:05:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.161.131 with HTTP; Wed, 25 Feb 2015 16:05:27 -0800 (PST) In-Reply-To: <23CC7871-C616-436C-920C-4A635DC87189@dell.com> References: <0AB56024-875B-4724-8ED2-A9DDB237CBFF@dell.com> <23CC7871-C616-436C-920C-4A635DC87189@dell.com> From: Simon Marchi Date: Thu, 26 Feb 2015 00:41:00 -0000 Message-ID: Subject: Re: format string is not a string literal To: Paul_Koning@dell.com Cc: howarth.mailing.lists@gmail.com, gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-02/txt/msg00056.txt.bz2 Content-length: 1931 > I didn=E2=80=99t say it=E2=80=99s a bug, Andrew did. But I agree with hi= m. > > My comment (=E2=80=9Cthe code is legit=E2=80=9D) simply meant that GDB us= es variable formats for obvious valid reasons (so the format can vary, bein= g user-supplied). Given that it=E2=80=99s intentional, the warning is not = wanted. > > But that point is really applicable to printf, not vprintf. Andrew=E2=80= =99s point is that checking formats for vprintf is not possible because you= can=E2=80=99t know the argument list; only in printf do you see the argume= nts so you can match the types. So the bug is that format checking and com= plaining for non-literal formats should not be enabled at all for vprintf. = That may be a header issue rather than a compiler issue, but either way, i= t=E2=80=99s not the right thing to do. > > paul I think the warning is relevant. If you instruct the compiler that inferior_debug takes a format string and format arguments (using a format attribute, as mentioned by Richard in the bug report), then it can check if the callers are doing something wrong. In the case of inferior_debug, the attribute should be __attribute__((format (printf, 2, 3))) By adding the attribute, you get nice warnings of this kind: test.c: In function =E2=80=98main=E2=80=99: test.c:17:2: warning: too many arguments for format [-Wformat-extra-args] inferior_debug (1, "pouet %d", 2, "hello"); If the function is vprintf-style, it's similar but the last argument should be 0. It will push the argument check a level higher, where eventually they are explicitely defined printf-style. The doc is somewhere here [2] in the middle. The warning also has some value because it will tell you if the string originally comes from a non-literal, which should be avoided [1]. [1] http://en.wikipedia.org/wiki/Uncontrolled_format_string [2] https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html Simon