---
tags: debug
---
# Using Address Sanitizer in VS Code for C Language on Mac
## Running normally in VS Code

After installing all the essential components for VS Code to complie C language, we can run the code by pressing "control+option+N", VS Code will automatically generate the words
`cd "/Users/lintingxuan/Desktop/9/" && gcc main.c -o main && "/Users/lintingxuan/Desktop/9/"main`
while `"/Users/lintingxuan/Desktop/9/"` is the directory of this `main.c` file

## Running Address Sanitizer in VS Code
Instead of pressing `"control+option+N"`, we type the words ourselves
```
gcc main.c -o main -fsanitize=address -g && "/Users/lintingxuan/Desktop/9/"main
```

After pressing enter, we can see something like

We can type in whatever we want to use as an input of the program, if there is an error, it will show


We shall edit our code until the image above does not show, then everything is good.
## Reference
1. [address sanitizer](https://www.osc.edu/resources/getting_started/howto/howto_use_address_sanitizer)
2. [solution for mac](https://stackoverflow.com/questions/44501833/makefile-for-linux-and-mac-with-address-sanitizer)
3. [debug](https://www.youtube.com/watch?v=KMC4AKpq_CM)