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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:05:50+00:00 2026-06-15T06:05:50+00:00

I’m trying an example int main(){ int count = 5; char *a = JOSUA;

  • 0

I’m trying an example

int main(){
    int count = 5;
    char *a = "JOSUA";
    char *c = "JANETALAE";
    char *b = NULL;
    char *d = NULL;
    b = (char *)malloc(sizeof(char)*5);
    b = a;
    if(b == NULL){
        printf("\n malloc failed");
    }
    printf("\nChar is:%s\n",b);
    d = (char *)realloc(b,sizeof(char) * 9);
    if(d == NULL){
        printf("\n realloc failed");
    }
    else{
        b = d;
        b = c;                                                                                                                                                                             
    }
    printf("\nChar is:%s\n",b);
    return 0;
}

I’m trying a sample program to allocate and reallocate memory. But i couldn’t reallocate the memory and getting a compilation break as below.

Char is:JOSUA
*** glibc detected *** ./realloc: realloc(): invalid pointer: 0x080485b4 ***
======= Backtrace: ========= /lib/libc.so.6[0x88ffd1] /lib/libc.so.6(realloc+0x2cf)[0x89613f] /lib/libc.so.6(realloc+0x2e7)[0x896157] ./realloc[0x80484aa] /lib/libc.so.6(__libc_start_main+0xe6)[0x836e16] ./realloc[0x8048391]
======= Memory map: ======== 007fc000-0081c000 r-xp 00000000 fd:00 659977     /lib/ld-2.12.90.so 0081c000-0081d000 r--p 0001f000 fd:00 659977     /lib/ld-2.12.90.so 0081d000-0081e000 rw-p 00020000 fd:00 659977     /lib/ld-2.12.90.so 00820000-009ad000 r-xp 00000000 fd:00 660018     /lib/libc-2.12.90.so 009ad000-009af000 r--p 0018c000 fd:00 660018     /lib/libc-2.12.90.so 009af000-009b0000 rw-p 0018e000 fd:00 660018     /lib/libc-2.12.90.so 009b0000-009b3000 rw-p 00000000 00:00 0  00a29000-00a45000 r-xp 00000000 fd:00 660039     /lib/libgcc_s-4.5.1-20100924.so.1 00a45000-00a46000 rw-p 0001b000 fd:00 660039     /lib/libgcc_s-4.5.1-20100924.so.1 00a84000-00a85000 r-xp 00000000 00:00 0          [vdso] 08048000-08049000 r-xp 00000000 fd:02 9440701    /home/user/beata/c_samples/realloc 08049000-0804a000 rw-p 00000000 fd:02 9440701    /home/user/beata/c_samples/realloc 092ac000-092cd000 rw-p 00000000 00:00 0          [heap] b78bc000-b78bd000 rw-p 00000000 00:00 0  b78d3000-b78d5000 rw-p 00000000 00:00 0  bfbd8000-bfbf9000 rw-p 00000000 00:00 0          [stack] Aborted (core dumped)

Could not understand why the compilation break happened.

  • 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-15T06:05:51+00:00Added an answer on June 15, 2026 at 6:05 am

    You are passing an invalid pointer to realloc(), just as the error says.

    It’s from this line:

    b = a;
    

    where you overwrite the return value of malloc() with the address of a string literal. You cannot pass that to realloc().

    Your overall logic in this program is very broken; if malloc() fails, there’s little reason to believe realloc() will succeed (assuming the above line is an editing error and shouldn’t be there).

    Also, this is a run-time error, not a “compilation error” as you say.

    Further, the typical errors apply:

    1. In C, don’t cast the return value of malloc(). This applies just as well to realloc(), too.
    2. Don’t use sizeof (char), it’s just a very cumbersome way to write 1.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string

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.