0

As you will see I am not good in c programming, still learning but my WindowsDefender is yelling at me for compiling this code with MinGW from Codeblocks IDE.

#include <stdio.h>
#include <string.h>

int main(void){

char *strings[] = {"test", "test"};
char *newStr;
int i;
for(i=0;i<2;i++){
   strcat(newStr, strings[i]);
   printf("%s\n", newStr);
}

return 0;
}

This is the Warning from Windows Defender

Can you help me with that I don't know what this is about. This can't be a normal issue mh?

  • very crazy is the fact that it has become two view directly after posting this, someone watching? – mortytheshorty Jun 04 '20 at 22:41
  • Change `char *newStr` to `char newStr[10];`. – isrnick Jun 04 '20 at 23:03
  • 1
    `char newStr[10];` is still UB. Need: `char newStr[10] = { 0 };` to force a starting EOS in the string so the _first_ `strcat` works correctly. Alternate: above the `for` do: `newstr[0] = 0;` – Craig Estey Jun 04 '20 at 23:21
  • 1
    Whenever a question is posted, anybody watching a particular tag (e.g. the `c` tag) will see their browser tab change. Or, on the page, it will show an alert phrase. So, this is quite common. – Craig Estey Jun 04 '20 at 23:24
  • Sorry but what is EOS? Funny fact, I was installing HxD Editor and after execution an error showed up Exception EOSError in module HxD.exe.... A call to an OS function failed. Does it have to do with the problem above? – mortytheshorty Jun 10 '20 at 21:24

1 Answers1

2

I have been having this for several days recently when I compile simple programs in C in Microsoft Visual Studio 2019 Community edition. For example this one.

#include <stdio.h>

int main() {

    int a = 10;
    for (int i = 0; i < 5; i++) {
        a--;
        printf("i = %d\n", i);
        if (a == 8) break;
    }
}

The problem isn't with your program (or mine) but Windows Defender has become overly paranoid and is erroneously identifying normal compiled code. I get the same Trojan warning as you. The danger is if we turn off Defender for crying wolf that a real virus could slip onto an unguarded Pc. I'm tempted to switch to a different a/v like AVG or switch into hyper-V and compile programs on Ubuntu with GCC or clang.

David Bolton
  • 168
  • 3
  • 12