• 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
va_list and unanticipated format specifiers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

va_list and unanticipated format specifiers


  • Subject: va_list and unanticipated format specifiers
  • From: "email@hidden" <email@hidden>
  • Date: Thu, 3 Jun 2010 12:47:43 +0100

One of my logging methods uses a variable argument list and is accessed via a macro

#define MLog(level,s,...) [[MLog sharedController] withLevel:level sourceFile:__FILE__ lineNumber:__LINE__ format:(s),## __VA_ARGS__]

The method implementation retrieves the va_list and instantiates an NSString

// read variable argument list
va_list ap;
va_start(ap,format);
NSString *logEntry = [[NSString alloc] initWithFormat:format arguments:ap];
va_end(ap);

The input into this is highly variable.
So a log/error message raised at a higher level may contain additional unanticipated format specifiers such as "%@".
This causes runtime woe as we run off the end of the va_list.

With the va_list we don't know the number of items.
With the format spec we don't know which of the format specifiers are unanticipated.

So is it just a question of sanitising the input format?

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com







_______________________________________________

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

  • Follow-Ups:
    • Re: va_list and unanticipated format specifiers
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: CFAttributedString and NSDATA
  • Next by Date: Re: CFAttributedString and NSDATA
  • Previous by thread: Re: CFAttributedString and NSDATA
  • Next by thread: Re: va_list and unanticipated format specifiers
  • Index(es):
    • Date
    • Thread