🔥Ловим баги в 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? Пиши в комментах👇
🔥Ловим баги в 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? Пиши в комментах👇
You can’t. What you can do, though, is use WhatsApp’s and Telegram’s web platforms to transfer stickers. It’s easy, but might take a while.Open WhatsApp in your browser, find a sticker you like in a chat, and right-click on it to save it as an image. The file won’t be a picture, though—it’s a webpage and will have a .webp extension. Don’t be scared, this is the way. Repeat this step to save as many stickers as you want.Then, open Telegram in your browser and go into your Saved messages chat. Just as you’d share a file with a friend, click the Share file button on the bottom left of the chat window (it looks like a dog-eared paper), and select the .webp files you downloaded. Click Open and you’ll see your stickers in your Saved messages chat. This is now your sticker depository. To use them, forward them as you would a message from one chat to the other: by clicking or long-pressing on the sticker, and then choosing Forward.
The global forecast for the Asian markets is murky following recent volatility, with crude oil prices providing support in what has been an otherwise tough month. The European markets were down and the U.S. bourses were mixed and flat and the Asian markets figure to split the difference.The TSE finished modestly lower on Friday following losses from the financial shares and property stocks.For the day, the index sank 15.09 points or 0.49 percent to finish at 3,061.35 after trading between 3,057.84 and 3,089.78. Volume was 1.39 billion shares worth 1.30 billion Singapore dollars. There were 285 decliners and 184 gainers.