• 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: Strange "exit due to Signal 11"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange "exit due to Signal 11"


  • Subject: Re: Strange "exit due to Signal 11"
  • From: Charilaos Skiadas <email@hidden>
  • Date: Sat, 6 Aug 2005 09:05:08 -0500

On Aug 6, 2005, at 8:49 AM, Michael Ströck wrote:

Hi,

I'm iterating over the lines I get from a CSV-file which has 5 columns.

This works fine:

This should not work quite fine, in fact I'm surprised it doesn't crash. Let's go through it:
for(i=0;i<[myLines count];i++) {
    NSArray * tmpArray = [[NSArray alloc] init];

You're creating a new array, which you are responsible for
tmpArray = [[myLines objectAtIndex:i] componentsSeparatedByString:@";"];

You are now redirecting the pointer to point to the autoreleased object that this method returns, hence in the process leaking the newly constructed array in the previous line.
NSLog([tmpArray objectAtIndex:0]);

Here you are assuming that tmpArray is not null, and I guess you are being lucky
[tmpArray release];

Here you release the already autoreleased array, so if it gets dealloced before the autorelease pool is flushed, you have a good chance of crashing.
}

So instead, it should probably be something like:

NSArray * tmpArray = nil;
for(i=0;i<[myLines count];i++) {
tmpArray = [[myLines objectAtIndex:i] componentsSeparatedByString:@";"];
if (tmpArray != nil) {
NSLog([tmpArray objectAtIndex:0]);
}
tmpArray = nil;
}
Anyway, moving on...
But the following dislpays the values and then (!?) exits with "signal 11 (SIGSEGV)" :

for(i=0;i<[myLines count];i++) {
NSArray * tmpArray = [[NSArray alloc] init];
tmpArray = [[myLines objectAtIndex:i] componentsSeparatedByString:@";"];


    NSLog([tmpArray objectAtIndex:1]);


Are you making sure that tmpArray has more than one element? In fact, are you making sure it has any elements at all? If not, then you are trying to read beyond the bounds.
    [tmpArray release];
}


The only difference is that I want to display the objectAtIndex:1 instead of atIndex:0 .
Why could that happen?



Thanks for any hints, Michael

Haris


_______________________________________________ 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
  • Follow-Ups:
    • Re: Strange "exit due to Signal 11"
      • From: Michael Ströck <email@hidden>
References: 
 >Strange "exit due to Signal 11" (From: Michael Ströck <email@hidden>)

  • Prev by Date: Re: Need help with a nasty memory management problem
  • Next by Date: Name of data model file
  • Previous by thread: Strange "exit due to Signal 11"
  • Next by thread: Re: Strange "exit due to Signal 11"
  • Index(es):
    • Date
    • Thread