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

  • SEARCH
  • Home
  • 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 9213921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:51:39+00:00 2026-06-18T01:51:39+00:00

I am trying to get NSMutableArray from NSData by 16 bytes, but failing to

  • 0

I am trying to get NSMutableArray from NSData by 16 bytes, but failing to do so. Maybe anyone could point me in the right direction.

Example:
input: <c4ebc39d edf81fe6 09e0a41a 34b4d20d c4ebc39d edf81fe6 09e0a41a 34b4d20d>

output: <c4ebc39d edf81fe6 09e0a41a 34b4d20d> <c4ebc39d edf81fe6 09e0a41a 34b4d20d>

I am trying like this:

NSMutableArray *blocks = [[NSMutableArray alloc]init];
for (NSUInteger i = 0; i <= [data length]; i=i+16) {
    unsigned char *byte = NULL;
    [data getBytes:byte range:NSMakeRange(i, 16)];
    NSData *temp = [[NSData alloc] initWithBytes:byte length:sizeof(byte)];
    [blocks addObject:temp];
}

For some reason this throws me exc_bad_access.

  • 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-06-18T01:51:40+00:00Added an answer on June 18, 2026 at 1:51 am
    [data getBytes:byte range:NSMakeRange(i, 16)];
    

    copies the data into the memory pointed to by byte, it does not allocate memory. Copying the data crashes because byte == NULL does not point to valid memory. Replacing

    unsigned char *byte = NULL;
    

    by

    unsigned char byte[16];
    

    should solve the problem. But note that

    NSData *temp = [data subdataWithRange:NSMakeRange(i, 16)];
    

    is even easier and does not require the byte buffer at all.

    Note also that the for loop

    for (NSUInteger i = 0; i <= [data length]; i=i+16)
    

    should be changed to

    for (NSUInteger i = 0; i <= [data length] - 16; i=i+16)
    

    to avoid access to the data object beyond its bounds.

    You loop would then look like this:

    for (NSUInteger i = 0; i <= [data length] - 16; i = i + 16) {
        NSData *temp = [data subdataWithRange:NSMakeRange(i, 16)];
        [blocks addObject:temp];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a string in my call from an array. But have
I'm trying to get data from a database using FMDB but having tried with
I'm trying to return a NSMutableArray from my block in my method, but when
Hi i am trying to get an integer value from a NSMutableArray I called
Using this code I am trying to get the data from Templates.plist file but
I'm currently trying to get hold of my NSMutableArray 's index depending on one
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I am trying to re-load a table every time some data I get from
I am trying to get an array from a plist as suggested on an
I am trying to get the number of frames per second from a gif

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.