From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14367 invoked by alias); 26 Feb 2015 00:41:10 -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 14356 invoked by uid 89); 26 Feb 2015 00:41:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.6 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-ie0-f175.google.com Received: from mail-ie0-f175.google.com (HELO mail-ie0-f175.google.com) (209.85.223.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 26 Feb 2015 00:41:08 +0000 Received: by ierx19 with SMTP id x19so9947322ier.3 for ; Wed, 25 Feb 2015 16:41:06 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.42.229.10 with SMTP id jg10mr6973609icb.62.1424911266115; Wed, 25 Feb 2015 16:41:06 -0800 (PST) Received: by 10.107.136.80 with HTTP; Wed, 25 Feb 2015 16:41:06 -0800 (PST) In-Reply-To: <7A311B56-C424-4C4F-A0E4-B12B65131745@gmail.com> References: <0AB56024-875B-4724-8ED2-A9DDB237CBFF@dell.com> <23CC7871-C616-436C-920C-4A635DC87189@dell.com> <7A311B56-C424-4C4F-A0E4-B12B65131745@gmail.com> Date: Thu, 26 Feb 2015 02:31:00 -0000 Message-ID: Subject: Re: format string is not a string literal From: Jack Howarth To: pinskia@gmail.com Cc: Simon Marchi , "Paul_Koning@dell.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/msg00058.txt.bz2 Andrew, See the additional comments from the llvm.org clang developers at... http://llvm.org/bugs/show_bug.cgi?id=3D22701#c5 Jack On Wed, Feb 25, 2015 at 7:12 PM, wrote: > > > > > On Feb 25, 2015, at 4:05 PM, Simon Marchi wrote: > >>> I didn=E2=80=99t say it=E2=80=99s a bug, Andrew did. But I agree with = him. >>> >>> My comment (=E2=80=9Cthe code is legit=E2=80=9D) simply meant that GDB = uses variable formats for obvious valid reasons (so the format can vary, be= ing user-supplied). Given that it=E2=80=99s intentional, the warning is no= t 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 arg= uments so you can match the types. So the bug is that format checking and = complaining for non-literal formats should not be enabled at all for vprint= f. That may be a header issue rather than a compiler issue, but either way= , it=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. > > Then clang's warning should suggest putting the format attribute on that = function rather than giving out a warning that seems like it is a bogus one. > > Gcc does that iirc why not clang. > > Thanks, > Andrew > > >> >> 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