Ich habe aktuell ein merkwürdiges realloc Problem..
Listing:
Code: Alles auswählen
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main (void)
{
int i = 0;
int *array;
array = (int*) malloc(1*sizeof(int));
for (i=1;i<=10000;i++){
  printf("Index %d\n",i);
  array = (int *) realloc(array,sizeof( int ) * i);
  array[i]=i;
}
return EXIT_SUCCESS;
}
837$: realloc
Index 1
Index 2
Index 3
Index 4
Index 5
Index 6
Index 7
*** glibc detected *** realloc: realloc(): invalid next size: 0x0000000000762010 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3467a748f4]
/lib64/libc.so.6(realloc+0x102)[0x3467a753e2]
realloc[0x400576]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x3467a1d994]
realloc[0x400479]
Ich meine, daß ich malloc und realloc korrekt (laut Lehrbuch) implementiert habe... ist die glibc buggy???
Ciao
Bruno


 Die glibc hat zwar sicher Bugs, aber im Normalfall liegt der Fehler eigentlich immer im eigenen Code.
 Die glibc hat zwar sicher Bugs, aber im Normalfall liegt der Fehler eigentlich immer im eigenen Code.