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


C geek Telegram | DID YOU KNOW?

Date: |

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

Mr. Durov launched Telegram in late 2013 with his brother, Nikolai, just months before he was pushed out of VK, the Russian social-media platform he founded. Mr. Durov pitched his new app—funded with the proceeds from the VK sale—less as a business than as a way for people to send messages while avoiding government surveillance and censorship.

C geek from ar


Telegram C++ geek
FROM USA