PB Realloc avec pointeur sur tableau passé en parametre
Bonjour j'ai un pb avec un realloc dans une fonction, le code suivant marche si je met i_nb = 2 mais pas avec i_nb = 3 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <stdio.h>
#include <stdlib.h>
static int i_ajoute(/*@out@*/ unsigned short ** p_tab, /*@out@*/ int * p_size)
{
int i;
int i_nb = 3;
int i_taille;
for (i = 0; i< i_nb; i++)
{
(*p_size)+=1;
i_taille = (*p_size) * sizeof(unsigned short);
//Augmente la taille
*p_tab = realloc((*p_tab),i_taille);
if((*p_tab) == NULL)
{
printf("ERREUR: Allocation memoire\n");
return 0;
}
printf("Apres realloc\n");
*p_tab[(*p_size)-1] = (unsigned short)i;
}
return 1;
}
int main ( int argc, char ** argv)
{
unsigned short * p_tab_elt_suppr = NULL;
int i_size = 0;
i_ajoute(&p_tab_elt_suppr, &i_size);
printf("FIN\n");
return 1;
} |