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 7545933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:04:00+00:00 2026-05-30T09:04:00+00:00

Hi I am using base 64 encoding for my string but I am getting

  • 0

Hi I am using base 64 encoding for my string but I am getting crash sometimes. It is not reproducing frequently. I tried using different ways but not get success.

Here is crash :

malloc: * error for object 0x6880830: incorrect checksum for freed object – object was probably modified after being freed.
*
set a breakpoint in malloc_error_break to debug

And here is code snippet:

-(NSString *)Base64Encode:(NSData *)data{

      if([data length])
  {
  //Point to start of the data and set buffer sizes
int inLength = [data length];
int outLength = ((((inLength * 4)/3)/4)*4) + (((inLength * 4)/3)%4 ? 4 : 0);
const char *inputBuffer = [data bytes];
char *outputBuffer = malloc(outLength);
outputBuffer[outLength] = 0;
//64 digit code
static char Encode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//start the count
int cycle = 0;
int inpos = 0;
int outpos = 0;
char temp;

//Pad the last to bytes, the outbuffer must always be a multiple of 4
outputBuffer[outLength-1] = '=';
outputBuffer[outLength-2] = '=';

/* 
 Text content   M           a           n
 ASCII          77          97          110
 8 Bit pattern  01001101    01100001    01101110

 6 Bit pattern  010011  010110  000101  101110
 Index          19      22      5       46
 Base64-encoded T       W       F       u
 */


while (inpos < inLength){
    switch (cycle) {
        case 0:
            outputBuffer[outpos++] = Encode[(inputBuffer[inpos]&0xFC)>>2];
            cycle = 1;
            break;
        case 1:
            temp = (inputBuffer[inpos++]&0x03)<<4;
            outputBuffer[outpos] = Encode[temp];
            cycle = 2;
            break;
        case 2:
            outputBuffer[outpos++] = Encode[temp|(inputBuffer[inpos]&0xF0)>> 4];
            temp = (inputBuffer[inpos++]&0x0F)<<2;
            outputBuffer[outpos] = Encode[temp];
            cycle = 3;                  
            break;
        case 3:
            outputBuffer[outpos++] = Encode[temp|(inputBuffer[inpos]&0xC0)>>6];
            cycle = 4;
            break;
        case 4:
            outputBuffer[outpos++] = Encode[inputBuffer[inpos++]&0x3f];
            cycle = 0;
            break;                          
        default:
            cycle = 0;
            break;
    }
}
NSString *pictemp = [NSString stringWithUTF8String:outputBuffer];
free(outputBuffer);
return pictemp;

}
else {
    return @"";
}

}
  • 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-30T09:04:01+00:00Added an answer on May 30, 2026 at 9:04 am

    You are writing beyond the end of your output buffer:

    char *outputBuffer = malloc(outLength);
    outputBuffer[outLength] = 0;
    

    If you allocate outLength + 1 bytes you should be fine.

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

Sidebar

Related Questions

In CodeIgniter I'm using a base CRUD My_model , but I have this small
I am not very familiar with the OAuth flow and/or encoding, but I've managed
I am wondering what is the purpose of encoding the String: "login:password" in base
i am using Encoding and decoding : For Encoding: private string EncodeServerName(string ServerName) {
A bit of background first: I am using base code from a remote SVN
I am using form base authentication in my Sharepoint site. On my login page
I have a small code base using Subsonic 2.1 in my project. I would
when accessing foo() of base using derived class's object. #include <iostream> class base {
For my tests I'm using a base class MyTestBase defining a method setup() that
I am using YUI reset/base, after the reset it sets the ul and li

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.