A simple tic-tac-toe program in Visual Studio 2019 causes Windows Defender to report threat

Viewed 305

Create a new C++ console application using Microsoft Visual Studio 2019. Add a file, name it tictactoe.c. Paste the code given below -

#include <stdio.h>

int main(void)
{
    int player = 0;
    int winner = 0;

    char board[3][3] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'} };

    //The main game loop. The game continues for up to 9 turns.
    for (unsigned i = 0; i < 9 && winner == 0; ++i) {
        //Display the board
        printf("\n");
        printf(" %c | %c | %c \n", board[0][0], board[0][1], board[0][2]);
        printf("-----+-----+-----\n");
        printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
        printf("-----+-----+-----\n");
        printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);

        player = i % 2 + 1;
    }

    return 0;
}

Build it, and then run it. For some reason, Windows defender thinks it has detected a threat!!! Windows defender complaining about threat.

2 Answers

Your code looks like normal. I think problem with Windows Defender because of false positive detection. I check it out on my MSVC2019 - same result on second run (first run works). Let's ask this question on Microsoft Support Forums?

It appears to be a false positive from Windows defender. Similar problem has occurred with other compilers like MinGW. Refer to Code::Blocks MinGW Windows Defender Trojan:Win32/Fuery.C!cl for one such instance.

The way to circumvent this is to mark your binary as an exception in Windows 'Allowed threats' window in 'Virus & threat protection' page of Windows Control Panel. Refer to the screen grabs below (assuming Windows 10).

Virus & Threat Protection screen

Allowed Threats

Win32/Fuery.C!cl Trojan Warning

Related