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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:35:58+00:00 2026-05-15T00:35:58+00:00

i got a crazy error within that for-loop matr=realloc(matr, newmax*sizeof(matr*)); for (i=0; i<newmax; i++){

  • 0

i got a crazy error within that for-loop

matr=realloc(matr, newmax*sizeof(matr*));

for (i=0; i<newmax; i++){
    matr[i]=realloc(matr[i], newmax*sizeof(int));
}

matr is a multi-dimension array: int **matr. i need to resize column and row. first line resizes column and the for-loop resizes every row. it worked fine in c. now im working on a library for lua and it crashs here. compilin’ works fine as well. but calling from lua crashs with

lua: malloc.c:3552: mremap_chunk: Assertion `((size + offset) & (mp_.pagesize-1)) == 0' failed.

i have no damn idea since it’s working fine using it in c.

  • 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-15T00:35:58+00:00Added an answer on May 15, 2026 at 12:35 am

    After calling realloc, the contents of the newly allocated portion are indeterminate. This means that then calling realloc on the new rows may fail because it tries to reallocate an invalid pointer.

    You can use realloc on the old rows and malloc on the new rows to fix this. Or you can zero the new part after the first realloc, and then your loop will work as is:

    matr=realloc(matr, newmax*sizeof(matr*));
    for (i=oldmax; i<newmax; i++)
        matr[i] = NULL;
    
    for (i=0; i<newmax; i++){
        matr[i]=realloc(matr[i], newmax*sizeof(int));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a task that makes me a little crazy, there is the section
I've got a table-view with more than a thousand entries! That's just crazy, I
I got this error and makes me crazy. My desired output is shows the
I got this crazy idea that I don't know is possible or not... what
I got this crazy problem I'm trying to deal with. I know that when
I've got this simple problem that is really making me crazy. I've got a
I'm getting crazy with this problem: I have got some Oracle SQL-Reports to redesign
Got this error message while trying to load view: The model item passed into
Got a seg fault from my memcpy that gdb can't give me anything else
got some problems. Built an applet that has to be used step-by-step. After each

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.