Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3484140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:45:17+00:00 2026-05-18T10:45:17+00:00

I’m getting an EXC_BAD_ACCESS error, and It’s because of this part of code. Basically,

  • 0

I’m getting an EXC_BAD_ACCESS error, and It’s because of this part of code. Basically, I take an input and do some work on it. After multiple inputs, it throws the error. Am I doing something wrong with my memory here? I’d post the rest of the code, but it’s rather long — and I think this may be where my problem lies (It’s where Xcode points me, at least).

-(IBAction) findShows: (id) clicked
{  
    char urlChars[1000];
    [self getEventURL: urlChars];
    NSString * theUrl = [[NSString alloc] initWithFormat:@"%s", urlChars];

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:theUrl]];
    int theLength = [data length];
    NSString *content = [NSString stringWithUTF8String:[data bytes]];

    char eventData[[data length]];
    strcpy(eventData, [content UTF8String]);
    [self parseEventData: eventData dataLength: theLength];
    [whatIsShowing setStringValue:@"Showing events by this artist"];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:45:18+00:00Added an answer on May 18, 2026 at 10:45 am

    When a crash occurs, there will be a backtrace.

    Post it.

    Either your program will break in the debugger, and the call stack will be in the debugger UI (or you can type ‘bt

    With that, the cause of the crash is often quite obvious. Without that, we are left to critique the code.

    So, here goes….


    char urlChars[1000];
    [self getEventURL: urlChars];
    

    This is, at best, a security hole and, at worst, the source of your crash. Any time you are going to copy bytes into a buffer, there should be some kind of way to (a) limit the # of bytes copied in (pass the length of the buffer) and (b) the # of bytes copied is returned (0 for failure or no bytes copied).

    Given the above, what happens if there are 1042 bytes copied into urlChars by getEventURL:? boom

    NSString * theUrl = [[NSString alloc] initWithFormat:@"%s", urlChars];
    

    This is making some assumptions about urlChars that will lead to failure. First, it assumes that urlChars is of a proper %s compatible encoding. Secondly, it assumes that urlChars is NULL terminated (and didn’t overflow the buffer).

    Best to use one of the various NSString methods that create strings directly from the buffer of bytes using a particular encoding. More precise and more efficient.

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:theUrl]];
    

    I hope this isn’t on the main thread… ’cause it’ll block if it is and that’ll make your app unresponsive on slow/flaky networks.

    int theLength = [data length];
    NSString *content = [NSString stringWithUTF8String:[data bytes]];
    
    char eventData[[data length]];
    strcpy(eventData, [content UTF8String]);
    

    This is about the least efficient possible way of doing this. There is no need to create an NSString instance just to then turn it into a (char *). Just grab the bytes from the data directly.

    Also — are you sure that the data returned is NULL terminated? If not, that strcpy() is gonna blow right past the end of your eventData buffer, corrupting the stack.

    [self parseEventData: eventData dataLength: theLength];
    [whatIsShowing setStringValue:@"Showing events by this artist"];
    

    What kind of data are you parsing that you really want to parse the raw bytes? In almost all cases, such data should be of some kind of structured type; XML or, even, HTML. If so, there is no need to drop down to parsing the raw bytes. (Not that raw data is unheard of — just odd).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.