• 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: warning at nslog
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: warning at nslog


  • Subject: Re: warning at nslog
  • From: Fritz Anderson <email@hidden>
  • Date: Sun, 27 Sep 2009 11:33:14 -0500

On 27 Sep 2009, at 11:12 AM, Jos Timanta Tarigan wrote:

i got problem trying to print stuff by using nslog eg. i want to print absolute path by this:

NSString *absolutePath = [path stringByExpandingTildeInPath];

and i print it with this

NSLog(absolutePath);

it gives me warning:

Format not a string literal and no format arguments.

i got this error a lot eg trying to print class name, proccesId, etc.
What is this error and how can i handle this?

When you pass a computed string, instead of a literal format string, as a format argument, you are begging for security exploits and crashes. This is true of NSLog, stringWithFormat:, or printf. The warning you got is pretty explicit about that.


Consider what happens when your program does this:

NSString * urlString = @"file:///MyVolume/Users/me/mission /impossible";
NSLog(urlString);


The format parser sees /, tries to pull the float you promised off the stack, and you crash. The roster of buggy programs is full of things that "can't happen."

Instead write

NSLog(@"%@", urlString);

	— F

--
Fritz Anderson -- Xcode 3 Unleashed: Headed for its third printing -- <http://x3u.manoverboard.org/ >


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >warning at nslog (From: Jos Timanta Tarigan <email@hidden>)

  • Prev by Date: Re: warning at nslog
  • Next by Date: Re: warning at nslog
  • Previous by thread: Re: warning at nslog
  • Next by thread: Re: warning at nslog
  • Index(es):
    • Date
    • Thread