Home > Enterprise >  How can I fix c6385?
How can I fix c6385?

Time:12-02

    // 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;

Hi, i am getting the following error on "deck.Cards[i] = temp[i];": C6385 Reading invalid data from 'deck.cards': the readable size is '(unsigned int)*64 4 bytes', but '128 bytes' may be used.

What am I doing wrong, and how can I fix this? The problem came up when I added the if statement seen at the top. Is there a chance that this could simply be a false warning? I am using visual studios

CodePudding user response:

dealerCards.Cards[dealerCards.currentElements] will not be assigned for dealerCards.Cards[0]; there will be a hole.

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

This assumes that a valid index is in 0 .. (currentElements-1).

The error however is on the deck, but is probably of very similar code elsewhere.

As C level code is very basic (arrays) and error prone, better switch to higher types like vector.

  • Related