0

関数 realocVet が 2 回目に実行された後、エラー メッセージ「malloc: *** オブジェクト 0x7f8bfac039b0 のエラー: 再割り当てされたポインターが割り当てられませんでした」が表示されるようです。

void realocVet (float *precoList, char *nomeList, short int *quantidadeList)
{
    static short int p=2,n=100,q=2;
    p=4*p;
    n=4*n;
    q=4*q;
    precoList =realloc(precoList,p * sizeof(float));
    nomeList =realloc(nomeList,n * sizeof(char));
    quantidadeList =realloc(quantidadeList,q * sizeof(short int ));
}

void insertData (float *precoList, char *nomeList, short int *quantidadeList, struct newCard myCard)
{
    static short int slotsAvailable = 2, aux=2,currentCard=0,nnchar=0;
    short int nchar;
    precoList[currentCard] = myCard.preco;
    quantidadeList[currentCard] = myCard.quantidade;
    for (nchar=0;nchar<50;nchar++)
    {
        nomeList[nnchar] = myCard.nome[nchar];
        nnchar++;
    }
    currentCard++;
    slotsAvailable--;

    if (slotsAvailable==0)
    {
        realocVet(precoList, nomeList, quantidadeList);
        slotsAvailable = aux;
        aux = 2*aux;
    }
}
4

1 に答える 1