User Profile

Collapse

Profile Sidebar

Collapse
Bold Gambit
Bold Gambit
Last Activity: Jul 16 '10, 10:54 PM
Joined: Jul 16 '10
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Bold Gambit
    replied to Repeated realloc causes crash in glibc
    in C
    Mistake in cut-and-paste, but not in original code: Move a->nelem++ down after a->y[a->nelem] = y;
    Sorry about that....
    See more | Go to post

    Leave a comment:


  • Bold Gambit
    started a topic Repeated realloc causes crash in glibc
    in C

    Repeated realloc causes crash in glibc

    Here is the code snippet, realloc succeeds once but fails the next time. I use gcc 4.1.2, glibc 2.5.

    Code:
    typedef struct array
    {
      double *x, *y;
      size_t nelem, size;
    } array_t;
    
    #define INIT_A_SIZE 1
    int init_a(array_t *a)
    {
      if (a) {
        a->x = (double *)malloc(INIT_A_SIZE*sizeof(double));
        a->y = (double *)malloc(INIT_A_SIZE*sizeof(double));
        if (!a->x
    ...
    See more | Go to post
    Last edited by Banfa; Jul 16 '10, 11:16 PM. Reason: Added [code] ... [/code] tags corrected code
No activity results to display
Show More
Working...