10

My C++ Setup INFO : OS - Windows 10, IDE - VS Code, compiler - MinGw

ISSUE : I recently found sanitizers for C++ to catch some runtime errors like out of bound array access with -fsanitize=address and -fsanitize=undefined in my VS Code environment.

This is a simple program for out of bound array access : enter image description here

in VS Code terminal being used is CMD when i tried to compile the program with this line g++ -fsanitize=address check.cpp -o main.exe enter image description here

On hitting enter I got this error ( cannot find -lasan ) : enter image description here

here is the c++ code ->

// Program to demonstrate 
// accessing array out of bounds
#include <iostream>
using namespace std ;
int main()
{
    int arr[] = {1,2,3,4,5};
    cout<<arr[0]<<endl;
      
    // arr[10] is out of bound
    cout<<arr[10]<<endl;
    return 0;
}

Cause(s)/Solution(s) for this issue

  1. How to fix cannot find -lasan ?

  2. Does MinGW not support these sanitizers, if so, shall I use cygwin ?

  3. Can I install clang on windows machine (if possible) to use this whole bunch of sanitizers ?

  4. What are the other options to use besides using Visual Studio instead of VS Code ??

  5. Any other suggestions

NOTE : kindly suggest me suitable tags for this post (if I have used a wrong one or missed a crucial one)

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.