Get rid of reading invalid data warning

Taylor 21 Reputation points
2021-03-03T20:28:24.62+00:00

I have this warning about reading invalid data, but the loop ensures that the range is valid. How can I suppress this warning? I know I can suppress all warnings of a certain ID but I just want to get rid of this one if that's possible in case this problem actually shows up later.![73829-screenshot-80.png][1] [1]: /api/attachments/73829-screenshot-80.png?platform=QnA

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,706 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
997 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dylan Zhu-MSFT 6,416 Reputation points
    2021-03-04T03:24:13.837+00:00

    Hi Taylor,

    You can add this code before this warning:

    #pragma warning(suppress: 6385)  
    if (players[playerNum].seed == 0){  
    ....  
     }  
    

    Best Regards, Dylan

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our * *documentation* to enable e-mail notifications if you want to receive the related email notification for this thread.**


1 additional answer

Sort by: Most helpful
  1. Viorel 116.8K Reputation points
    2021-03-03T20:44:22.37+00:00

    Probably we and the compiler cannot be sure that playerNum does not exceed the bounds of players.

    Maybe try another condition:

    . . .
    while( iQ.fail || iQ.answer < 1 || iQ.answer > players.size() )
    . . .
    

    (Assuming that players is a vector).


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.