我该如何修复c6385?

How can I fix c6385?

    // Take last element from deck and add to dealer's hand
    // Update current elements after
    //Ensure the deck still has cards
    if (deck.currentElements == 0) {
        getNewDeck(deck);
        shuffleDeck(deck);
    }
    deck.currentElements -= 1;
    dealerCards.currentElements += 1;
    dealerCards.Cards[dealerCards.currentElements] = deck.Cards[deck.currentElements];

    // Update the deck array by decreasing size 
    // hence used cards are removed
    Card* temp = deck.Cards;
    deck.Cards = new Card[deck.currentElements];
    for (int i = 0; i < deck.currentElements; i++) {

        deck.Cards[i] = temp[i];
    }
    // Delete memory associated with temp
    delete[] temp;

嗨,我在“deck.Cards[i] = temp[i];”上收到以下错误:C6385 从 'deck.cards' 读取无效数据:可读大小为'(unsigned int )*64+4 字节',但可以使用'128 字节'。

我做错了什么,我该如何解决?当我添加在顶部看到的 if 语句时,问题出现了。这有可能只是一个错误的警告吗?我正在使用视觉工作室

dealerCards.Cards[dealerCards.currentElements] 不会分配给 dealerCards.Cards[0];会有一个洞

--deck.currentElements;
dealerCards.Cards[dealerCards.currentElements] = deck.Cards[deck.currentElements];
++dealerCards.currentElements;

这假定有效索引在 0 .. (currentElements-1) 中。

但是错误在 deck,但其他地方的代码可能非常相似。

由于 C 级代码非常基础(数组)且容易出错,最好切换到更高类型,如 vector