Telegram Group & Telegram Channel
🔥 Ловим баги в C++ на лету с помощью AddressSanitizer (ASan)

Если valgrind — это медленный, но подробный детектив, то ASan — это охрана, которая ловит баги прямо во время исполнения. Быстро, точно, удобно.


💡 Что такое ASan?
Это часть компилятора (clang или gcc), которая вставляет дополнительные проверки в бинарник. Работает во время запуска, ловит:

- выход за границы массива,
- use-after-free,
- double free,
- утечки памяти (с флагом LeakSanitizer).


👨‍💻 Пример:


// asan_example.cpp
#include <iostream>

int main() {
int* arr = new int[5];
arr[10] = 42; // выход за границу
delete[] arr;
return 0;
}


⚙️ Компиляция с ASan:


g++ -fsanitize=address -g asan_example.cpp -o app


🚀 Запуск:


./app


📄 Результат:


==12345==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000050
READ of size 4 at 0x602000000050 thread T0
#0 0x... in main asan_example.cpp:6



📌 Плюсы ASan:
- Мгновенная обратная связь;
- Прост в использовании;
- Отлично работает с CI (GitHub Actions, GitLab CI и т.д.);
- Поддерживает LeakSanitizer (-fsanitize=leak).

📉 Минусы:
- Увеличивает размер бинарника;
- Иногда мешает оптимизациям;
- Не ловит всё (например, утечки в сторонних lib без debug info).


🔧 Совет:
Запускай тесты с -fsanitize=address в debug-сборках. Это бесплатно и спасает от кучи головной боли в будущем.


🧵 Используешь ли ты ASan в своих проектах? Или только valgrind? Пиши в комментах👇

➡️ @cpp_geek



tg-me.com/cpp_geek/299
Create:
Last Update:

🔥 Ловим баги в C++ на лету с помощью AddressSanitizer (ASan)

Если valgrind — это медленный, но подробный детектив, то ASan — это охрана, которая ловит баги прямо во время исполнения. Быстро, точно, удобно.


💡 Что такое ASan?
Это часть компилятора (clang или gcc), которая вставляет дополнительные проверки в бинарник. Работает во время запуска, ловит:

- выход за границы массива,
- use-after-free,
- double free,
- утечки памяти (с флагом LeakSanitizer).


👨‍💻 Пример:


// asan_example.cpp
#include <iostream>

int main() {
int* arr = new int[5];
arr[10] = 42; // выход за границу
delete[] arr;
return 0;
}


⚙️ Компиляция с ASan:


g++ -fsanitize=address -g asan_example.cpp -o app


🚀 Запуск:


./app


📄 Результат:


==12345==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000050
READ of size 4 at 0x602000000050 thread T0
#0 0x... in main asan_example.cpp:6



📌 Плюсы ASan:
- Мгновенная обратная связь;
- Прост в использовании;
- Отлично работает с CI (GitHub Actions, GitLab CI и т.д.);
- Поддерживает LeakSanitizer (-fsanitize=leak).

📉 Минусы:
- Увеличивает размер бинарника;
- Иногда мешает оптимизациям;
- Не ловит всё (например, утечки в сторонних lib без debug info).


🔧 Совет:
Запускай тесты с -fsanitize=address в debug-сборках. Это бесплатно и спасает от кучи головной боли в будущем.


🧵 Используешь ли ты ASan в своих проектах? Или только valgrind? Пиши в комментах👇

➡️ @cpp_geek

BY C++ geek


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/cpp_geek/299

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

The messaging service and social-media platform owes creditors roughly $700 million by the end of April, according to people briefed on the company’s plans and loan documents viewed by The Wall Street Journal. At the same time, Telegram Group Inc. must cover rising equipment and bandwidth expenses because of its rapid growth, despite going years without attempting to generate revenue.

What Is Bitcoin?

Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.

telegram from sg


Telegram C++ geek
FROM USA