• 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: String causes NSLog to crash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String causes NSLog to crash


  • Subject: Re: String causes NSLog to crash
  • From: Ryan Britton <email@hidden>
  • Date: Fri, 24 Feb 2006 10:46:47 -0800

Because in that url you have a number of printf-style formatters. When you use it as the format string for NSLog, it searches the argument list (which is not provided) for the values, finds garbage memory, and crashes when it tries to interpret it.

On Feb 24, 2006, at 10:34 AM, Sunil Vemuri wrote:

I'm experiencing a peculiar problem with NSString: use of certain strings leads to crashes. The code below illustrates the problem. The program crashes on the NSLog(test) line. I'm not sure why the first NSLog() would would work and the second crashes.


int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* test = @"http://images.google.com/imgres?imgurl=http:// jameselee.myblogsite.com/EXAMPLE%20-%20RSS%20Icon% 25202.gif&imgrefurl=http://jameselee.myblogsite.com/ &h=14&w=36&sz=1&tbnid=lLM7cy- VxzIJ:&tbnh=14&tbnw=36&hl=en&start=28&prev=/images?q=xml+rss% 2Bicon&start=20&svnum=10&hl=en&lr=&client=safari &rls=en-us&sa=N";
NSLog(@" link:%@", test);
NSLog(test);

[pool release];
}


Program output when run in debugger:
Running…
2006-02-24 11:59:55.515 MyApp[15395] link:http://images.google.com/ imgres?imgurl=http://jameselee.myblogsite.com/EXAMPLE%20-%20RSS% 2520Icon%202.gif&imgrefurl=http://jameselee.myblogsite.com/ &h=14&w=36&sz=1&tbnid=lLM7cy- VxzIJ:&tbnh=14&tbnw=36&hl=en&start=28&prev=/images?q=xml+rss% 2Bicon&start=20&svnum=10&hl=en&lr=&client=safari &rls=en-us&sa=N
Catchpoint 10 (throw)Catchpoint 11 (catch)Program received signal: "EXC_BAD_ACCESS".


Stack trace at crash:
#0	0x90003008 in strlen
#1	0x90742e68 in _CFStringAppendFormatAndArgumentsAux
#2	0x90741fa8 in _CFStringCreateWithFormatAndArgumentsAux
#3	0x928f1854 in NSLogv
#4	0x928f17f0 in NSLog
#5	0x0000ece0 in main at main.m:24


Many other strings will not cause a crash. This one (and others url strings from images.google.com) seem to cause the failure. I'm running MacOS X 10.4.4. I tried the sample code above on another machine with the same result. If I append this "faulty" string to another string [str appendString:test], it "messes up" str (i.e., modifies str in unpredictable ways).


I'm curious if anyone has any insight into what may be going wrong here.

Thanks,
--Sunil

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

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >String causes NSLog to crash (From: Sunil Vemuri <email@hidden>)

  • Prev by Date: Re: String causes NSLog to crash
  • Next by Date: Re: String causes NSLog to crash
  • Previous by thread: Re: String causes NSLog to crash
  • Next by thread: Re: String causes NSLog to crash
  • Index(es):
    • Date
    • Thread