• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Format not a string literal and no format arguments"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Format not a string literal and no format arguments"


  • Subject: Re: "Format not a string literal and no format arguments"
  • From: "Sean McBride" <email@hidden>
  • Date: Mon, 31 Aug 2009 18:23:19 -0400
  • Organization: Rogue Research Inc.

On 8/29/09 4:00 PM, Ken Thomases said:

>GCC knows about the standard formatting functions and applies the
>analysis to them automatically, by default.  However, it also allows
>the application of the __attribute__((format ...)) decoration to user-
>defined functions to have them checked in the same way.  This applies
>to all of the formatting-related warnings.
>
>There's -Wformat and -Wformat-security (among a few others).  The
>former checks the types, the latter also warns about a lone non-
>literal argument. -Wformat-security is ignored if -Wformat is not
>enabled, so -Wno-format disables both.
>
>Both warnings are available in GCC 4.0.1, but not enabled by default.
>They are apparently both enabled by default in GCC 4.2.1.  (Currently,
>-Wformat-security is a subset of -Wformat-nonliteral, which is
>apparently not enabled by default.  It warns when the format string is
>a non-literal even if it's followed by arguments.)

The following common usage now trips this warning:

----
#import <Cocoa/Cocoa.h>

int main (void)
{
	NSString* foo = [NSString stringWithFormat:
		NSLocalizedString(@"%d days ago", @"some comment"),
		350];

	return 0;
}
----

$ gcc-4.2 -Wformat=2 -framework Cocoa test.m
test.m: In function 'main':
test.m:7: warning: format not a string literal, argument types not checked


Other than removing the warning, or hacking the headers in the SDK (to
add compiler decorations), anyone have any suggestions on how to rewrite
this code to work with that warning?

Thanks,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >"Format not a string literal and no format arguments" (From: Jonathan del Strother <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Quincey Morris <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Peter Duniho <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Quincey Morris <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Ken Thomases <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Quincey Morris <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Overriding NSMenu from an NSTextView
  • Next by Date: Re: How to use NSTextView's new -checkTextInRange:types:options:?
  • Previous by thread: Re: "Format not a string literal and no format arguments"
  • Next by thread: Re: "Format not a string literal and no format arguments"
  • Index(es):
    • Date
    • Thread