{"id":371160,"date":"2024-05-21T04:41:46","date_gmt":"2024-05-21T04:41:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=371160"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T04:41:46","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=371160","title":{"rendered":"<span>\u0412\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 C \u0438 C++: \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c Sanitizers \u0438 Valgrind<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Memory_safety\">memory-unsafe<\/a> (\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e) \u044f\u0437\u044b\u043a\u0430\u0445 \u2014 <a href=\"https:\/\/github.com\/google\/sanitizers\">Sanitizers<\/a> \u0438 <a href=\"https:\/\/www.valgrind.org\/\">Valgrind<\/a>. \u042d\u0442\u0438 \u0434\u0432\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0445\u043e\u0442\u044c Sanitizers (\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430\u043c\u0438 Google) \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043f\u0435\u0440\u0435\u0434 Valgrind, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u0438\u043b\u044c\u043d\u044b\u0435 \u0438 \u0441\u043b\u0430\u0431\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0435\u043a\u0442 Sanitizers \u0438\u043c\u0435\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 Java, Python \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0438\u043c \u044f\u0437\u044b\u043a\u043e\u0432 \u0441 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043f\u0430\u043c\u044f\u0442\u0438, \u044f\u0437\u044b\u043a\u0430\u043c \u0441 \u043f\u0440\u044f\u043c\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043f\u0430\u043c\u044f\u0442\u0438, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a <a href=\"https:\/\/developers.redhat.com\/topics\/c\">C \u0438 C++<\/a>, \u043d\u0443\u0436\u043d\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u0435\u0439. \u0412 memory-unsafe \u044f\u0437\u044b\u043a\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u043e\u043d\u0435\u0446 \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043b\u0438 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0430. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043c\u043e\u0433\u0443\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044f\u0441\u044c \u043a\u0440\u0430\u0448\u0435\u043c \u043b\u0438\u0448\u044c \u0432 \u0440\u0435\u0434\u043a\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445. \u0412\u044b\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0430\u043c\u043e\u043c\u0443 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>\u041d\u0430\u0447\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e Valgrind \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0441\u0438\u043b\u044c\u043d\u0435\u0435, \u0447\u0435\u043c Sanitizers. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434 Valgrind, \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0442 20 \u0434\u043e 50 \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u043c \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0441 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u044b\u043c\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438. \u0417\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 Sanitizers \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 2-4 \u0440\u0430\u0437\u0430 \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439. \u0412\u043c\u0435\u0441\u0442\u043e Valgrind \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Sanitizers \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h3>\u041a\u0440\u0430\u0442\u043a\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043a Sanitizers<\/h3>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043f\u043e\u0434\u044b\u0442\u043e\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c, \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c \u0441 Sanitizers:<\/p>\n<ul>\n<li>\n<p>\u041e\u043f\u0446\u0438\u0438 Clang\/GCC: <\/p>\n<\/li>\n<\/ul>\n<pre><code>-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment<\/code><\/pre>\n<ul>\n<li>\n<p>\u0414\u043b\u044f LLDB\/GDB \u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0441\u0442\u0435\u043a-\u0442\u0440\u0435\u0439\u0441\u043e\u0432 \u0438, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0443\u0442\u0435\u0447\u0435\u043a:<\/p>\n<\/li>\n<\/ul>\n<pre><code>$ export ASAN_OPTIONS=abort_on_error=1:fast_unwind_on_malloc=0:detect_leaks=0 UBSAN_OPTIONS=print_stacktrace=1<\/code><\/pre>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u0443\u0442\u0435\u0447\u043a\u0430\u0445 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/GLib\"><u>glib2<\/u><\/a>:<\/p>\n<\/li>\n<\/ul>\n<pre><code>$ export G_SLICE=always-malloc G_DEBUG=gc-friendly<\/code><\/pre>\n<ul>\n<li>\n<p>\u041e\u043f\u0446\u0438\u044f Clang \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0430 \u0447\u0442\u0435\u043d\u0438\u044f \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438: <code>-fsanitize=memory<\/code>. \u042d\u0442\u0443 \u043e\u043f\u0446\u0438\u044e \u043d\u0435\u043b\u044c\u0437\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 <code>-fsanitize=address<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 rpmbuild .spec \u0444\u0430\u0439\u043b\u0430\u0445 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c: <code>-Wp,-U_FORTIFY_SOURCE<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 Sanitizers\u00a0<\/h3>\n<p>Valgrind \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435, \u0430 \u043d\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u044b\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430. Sanitizers \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441 \u043c\u0435\u043d\u044c\u0448\u0438\u043c\u0438 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c\u0438.<\/p>\n<p>\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 1 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizerComparisonOfMemoryTools\">\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435<\/a>, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043e\u0431\u043e\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u00a0<\/p>\n<\/td>\n<td>\n<p align=\"left\">Sanitizers<\/p>\n<\/td>\n<td>\n<p align=\"left\">Valgrind<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>: \u043e\u0431\u0449\u0435\u0435 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/td>\n<td>\n<p align=\"left\">2 \u2013 4 \u0440\u0430\u0437\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">20 \u2013 50 \u0440\u0430\u0437<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>: <a href=\"https:\/\/godbolt.org\/z\/vedx5q\">\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">1 (= \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u0432\u0440\u0435\u043c\u044f)<\/p>\n<\/td>\n<td>\n<p align=\"left\">3.45 \u0440\u0430\u0437\u0430 (+23\u0441 = 12 \u0440\u0430\u0437)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>: <a href=\"https:\/\/godbolt.org\/z\/zjTG8q\">\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u044f \u0441 malloc<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">17 \u0440\u0430\u0437<\/p>\n<\/td>\n<td>\n<p align=\"left\">101 \u0440\u0430\u0437 (+23\u0441 = 256 \u0440\u0430\u0437)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>: <a href=\"https:\/\/godbolt.org\/z\/Y5EPc3\">\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u044f \u0441 AVX2<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.05 (= \u043d\u0430 5% \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435)<\/p>\n<\/td>\n<td>\n<p align=\"left\">53 \u0440\u0430\u0437\u0430 (+23\u0441 = 60 \u0440\u0430\u0437)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/ThreadSanitizer.html\">TSAN<\/a>: <a href=\"https:\/\/godbolt.org\/z\/6zMWEe\">\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u044f \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0433\u043e\u043d\u043a\u0438<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">9 \u0440\u0430\u0437<\/p>\n<\/td>\n<td>\n<p align=\"left\">340 \u0440\u0430\u0437 (+31\u0441 = 404 \u0440\u0430\u0437\u0430)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0412\u044b\u0445\u043e\u0434 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (<a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#outofboundsstack\">\u0441\u0442\u0435\u043a\u043e\u0432\u044b\u0445<\/a>, <a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#outofboundsglobal\">\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043f\u0443\u0441\u0442\u0438\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">Memcheck<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#uninit\">\u041d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/MemorySanitizer.html\">MSAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">Memcheck<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#stackafterreturn\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0435\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043f\u0443\u0441\u0442\u0438\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">\u041c\u0435\u043c\u0447\u0435\u043a<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#undefined\">\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/UndefinedBehaviorSanitizer.html\">UBSAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043f\u0443\u0441\u0442\u0438\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">\u041c\u0435\u043c\u0447\u0435\u043a<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#leak\">\u0423\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/LeakSanitizer.html\">LSAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">Memcheck<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#datarace\">\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/ThreadSanitizer.html\">TSAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/hg-manual.html\">Helgrind<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#recompilation\">\u041f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412 \u043c\u043e\u0438\u0445 \u0442\u0435\u0441\u0442\u0430\u0445 Valgrind \u0442\u0440\u0430\u0442\u0438\u0442 23 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u042d\u0442\u0443 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u044c, \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \/usr\/lib\/debug. \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e! \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u0430\u044f \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u043f\u0430\u0441\u0442\u044c \u0438 \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f (\u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430):<\/p>\n<pre><code>$ sudo mv \/usr\/lib\/debug \/usr\/lib\/debug-x; sleep 1h; sudo mv \/usr\/lib\/debug-x \/usr\/lib\/debug<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442\u044b \u043d\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u0438 \u0441\u0443\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0430\u043d\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code>$ clang++ -g -O3 -march=native -ffast-math ... clang-11.0.0-2.fc33.x86_64 valgrind-3.16.1-5.fc33.x86_64<\/code><\/pre>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 <code>-fsanitize=address<\/code>, <code>-fsanitize=undefined<\/code> \u0438\u043b\u0438 &#8212;<code>fsanitize=thread<\/code> \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b \u0432 <a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#tldr\">\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043a Sanitizers<\/a>.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 Clang. GCC \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 Sanitizers, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 <code>-fsanitize=memory<\/code> (\u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0438\u043c \u044d\u0442\u043e \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#uninit\">MSAN: \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/a>).<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 debuginfo<\/h3>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0444\u0430\u0439\u043b\u044b <code>*-debuginfo.rpm<\/code> \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>dnf debuginfo-install packagename<\/code>. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 <a href=\"https:\/\/developers.redhat.com\/products\/rhel\/overview\">Red Hat Enterprise Linux<\/a> (RHEL) \u0432\u043c\u0435\u0441\u0442\u043e <code>dnf<\/code> \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>yum<\/code>. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 <code>gdb<\/code>, \u043e\u043d\u0430 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 \u0432\u0430\u043c, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e RPM:<\/p>\n<pre><code class=\"cpp\">$ cat >vector.cpp &lt;&lt;'EOF' \/\/ \u0417\u0434\u0435\u0441\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0435\u0442\u0435, \/\/ \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441 std::vector \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c. #include &lt;vector> int main() {   std::vector&lt;int> v; } EOF $ clang++ -o vector vector.cpp -Wall -g $ gdb .\/vector Reading symbols from .\/vector... (gdb) start ... Missing separate debuginfos, use: dnf debuginfo-install glibc-2.32-2.fc33.x86_64 ... Missing separate debuginfos, use: dnf debuginfo-install libgcc-10.2.1-9.fc33.x86_64 libstdc++-10.2.1-9.fc33.x86_64 (gdb) quit $ sudo dnf debuginfo-install glibc-2.32-2.fc33.x86_64 ... $ sudo dnf debuginfo-install libgcc-10.2.1-9.fc33.x86_64 libstdc++-10.2.1-9.fc33.x86_64 ...<\/code><\/pre>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438: \u041f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0431\u0443\u0444\u0435\u0440\u0430. \u0425\u043e\u0442\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0439, \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043a\u0443\u0434\u0430 \u0431\u043e\u043b\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u044b \u0438 \u0438\u0445 \u0442\u0440\u0443\u0434\u043d\u043e \u043d\u0430\u0439\u0442\u0438. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">Valgrind Memcheck<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a. \u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 Valgrind Memcheck \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">$ cat >overrun.c &lt;&lt;'EOF' #include &lt;stdlib.h> int main() {   char *p = malloc(16);   p[24] = 1; \/\/ \u0432\u044b\u0445\u043e\u0434 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0431\u0443\u0444\u0435\u0440\u0430, \u0432 p \u0432\u0441\u0435\u0433\u043e 16 \u0431\u0430\u0439\u0442   free(p); \/\/ free(): \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c   return 0; } EOF $ clang -o overrun overrun.c -Wall -g $ valgrind .\/overrun ... ==60988== Invalid write of size 1 ==60988==    at 0x401154: main (overrun.c:4) ==60988==  Address 0x4a52058 is 8 bytes after a block of size 16 alloc'd ==60988==    at 0x4839809: malloc (vg_replace_malloc.c:307) ==60988==    by 0x401147: main (overrun.c:3)<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/godbolt.org\/z\/1Wa6n4\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 Valgrind, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0431\u044b\u0442\u044c. \u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0434\u0430\u0435\u0442 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0447\u0438\u0441\u0442\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>free(): invalid pointer<\/code> \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u0437 <a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_C_Library\">glibc<\/a> (<a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_C_Library\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 GNU C<\/a>), \u0430 \u043d\u0435 \u0438\u0437 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Sanitizers \u0438\u043b\u0438 Valgrind:<\/p>\n<pre><code class=\"cpp\">$ cat >overrun.c &lt;&lt;'EOF' #include &lt;stdlib.h> int main() {   char *p = malloc(16);   char *p2 = malloc(16);   p[24] = 1; \/\/ \u0432\u044b\u0445\u043e\u0434 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0431\u0443\u0444\u0435\u0440\u0430, \u0432 p \u0432\u0441\u0435\u0433\u043e 16 \u0431\u0430\u0439\u0442   free(p2); \/\/ free(): \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c   free(p);   return 0; } EOF $ clang -o overrun overrun.c -Wall -g $ .\/overrun free(): invalid pointer Aborted<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/godbolt.org\/z\/rvEjaK\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<p>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 Sanitizers, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e Valgrind \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">AddressSanitizer<\/a>. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 Valgrind \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u0442\u043e AddressSanitizer \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">$ clang -o overrun overrun.c -Wall -g -fsanitize=address $ .\/overrun ================================================================= ==61268==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000028 at pc 0x0000004011b8 bp 0x7fff37c8aa70 sp 0x7fff37c8aa68 WRITE of size 1 at 0x602000000028 thread T0     #0 0x4011b7 in main overrun.c:4     #1 0x7f4c94a2d1e1 in __libc_start_main ..\/csu\/libc-start.c:314     #2 0x4010ad in _start (overrun+0x4010ad)   0x602000000028 is located 8 bytes to the right of 16-byte region [0x602000000010,0x602000000020) allocated by thread T0 here:     #0 0x7f4c94c7b3cf in __interceptor_malloc (\/lib64\/libasan.so.6+0xab3cf)     #1 0x401177 in main overrun.c:3     #2 0x7f4c94a2d1e1 in __libc_start_main ..\/csu\/libc-start.c:314   SUMMARY: AddressSanitizer: heap-buffer-overflow overrun.c:4 in main ...<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/godbolt.org\/z\/3ns4WM\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<h3><\/h3>\n<h3>ASAN: \u0412\u044b\u0445\u043e\u0434 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0435\u043a\u0430<\/h3>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Valgrind \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043e\u043d \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043f\u0430\u043c\u044f\u0442\u0438. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u043d\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 (\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445) \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (\u0441\u043c. <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizerExampleStackOutOfBounds\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e AddressSanitizer Stack Out of Bounds<\/a>).<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Valgrind \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043e\u043d \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u043e\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 <a href=\"https:\/\/en.wikipedia.org\/wiki\/C_dynamic_memory_allocation#Overview_of_functions\">malloc<\/a>. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u0441\u0442\u0435\u043a\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0442\u044a\u0435\u043c\u043b\u0435\u043c\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0443\u0436\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a malloc, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Valgrind \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0441\u0442\u0435\u043a\u043e\u0432\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c. Sanitizers, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0435\u0449\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a \u043a\u0430\u043a\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u0441\u0442\u0435\u043a\u0435 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0438 \u043a\u0430\u043a\u043e\u0432\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0432 \u0441\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">$ cat >stack.c &lt;&lt;'EOF' int main(int argc, char **argv) {   int a[100];   return a[argc + 100]; } EOF $ clang -o stack stack.c -Wall -g -fsanitize=address $ .\/stack ==88682==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff54f500f4 at pc 0x0000004f4c51 bp 0x7fff54f4ff30 sp 0x7fff54f4ff28 READ of size 4 at 0x7fff54f500f4 thread T0     #0 0x4f4c50 in main \/tmp\/stack.c:3:10     #1 0x7f9983c7e1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #2 0x41c41d in _start (\/tmp\/stack+0x41c41d)   Address 0x7fff54f500f4 is located in stack of thread T0 at offset 436 in frame     #0 0x4f4a9f in main \/tmp\/stack.c:1     This frame has 1 object(s):     [32, 432) 'a' (line 2) &lt;== Memory access at offset 436 overflows this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork       (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-buffer-overflow \/tmp\/stack.c:3:10 in main ... $ clang -o stack stack.c -Wall -g $ valgrind .\/stack ... (nothing found by Valgrind)<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/godbolt.org\/z\/451nrc\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<h3>ASAN: \u0412\u044b\u0445\u043e\u0434 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/h3>\n<p>\u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0441\u0442\u0435\u043a\u0435, Valgrind \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0432\u044b\u0445\u043e\u0434 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 (\u0441\u043c. <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizerExampleGlobalOutOfBounds\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e AddressSanitizer Global Out of Bounds<\/a>).<\/p>\n<p>\u042f \u0443\u0436\u0435 <a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#outofboundsstack\">\u043e\u043f\u0438\u0441\u0430\u043b \u0432\u044b\u0448\u0435<\/a>, \u043f\u043e\u0447\u0435\u043c\u0443 Valgrind \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u0412\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b AddressSanitizer \u0438 Valgrind:<\/p>\n<pre><code class=\"cpp\">$ cat >global.c &lt;&lt;'EOF' int a[100]; int main(int argc, char **argv) {   return a[argc + 100]; } EOF $ clang -o global global.c -Wall -g -fsanitize=address $ .\/global ================================================================= ==88735==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000000dcee74 at pc 0x0000004f4b04 bp 0x7ffd5292b580 sp 0x7ffd5292b578 READ of size 4 at 0x000000dcee74 thread T0     #0 0x4f4b03 in main \/tmp\/global.c:3:10     #1 0x7fd416cda1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #2 0x41c41d in _start (\/tmp\/global+0x41c41d)   0x000000dcee74 is located 4 bytes to the right of global variable 'a' defined in 'global.c:1:5' (0xdcece0) of size 400 SUMMARY: AddressSanitizer: global-buffer-overflow \/tmp\/global.c:3:10 in main ... $ clang -o global global.c -Wall -g $ valgrind .\/global ... (nothing found by Valgrind)<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/godbolt.org\/z\/Ycx1qP\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<h3>MSAN: \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/h3>\n<p>AddressSanitizer \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d <a href=\"https:\/\/clang.llvm.org\/docs\/MemorySanitizer.html\">MemorySanitizer<\/a>. \u041e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 (\u0441\u043c. <a href=\"https:\/\/clang.llvm.org\/docs\/MemorySanitizer.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e MemorySanitizer<\/a>). \u041f\u043e\u0447\u0435\u043c\u0443 AddressSanitizer \u043d\u0435 \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 MemorySanitizer, \u043c\u043d\u0435 \u043d\u0435\u044f\u0441\u043d\u043e (\u0438 <a href=\"https:\/\/stackoverflow.com\/a\/38523606\/2995591\">\u043d\u0435 \u043c\u043d\u0435 \u043e\u0434\u043d\u043e\u043c\u0443<\/a>).<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 MemorySanitizer \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c:<\/p>\n<pre><code class=\"cpp\">$ cat >uninit.c &lt;&lt;'EOF' int main(int argc, char **argv) {   int a[2];   if (a[argc != 1])     return 1;   else     return 0; } EOF $ clang -o uninit uninit.c -Wall -g -fsanitize=address -fsanitize=memory clang-11: error: invalid argument '-fsanitize=address' not allowed with '-fsanitize=memory' $ clang -o uninit uninit.c -Wall -g -fsanitize=memory $ .\/uninit ==63929==WARNING: MemorySanitizer: use-of-uninitialized-value     #0 0x4985a9 in main \/tmp\/uninit.c:3:7     #1 0x7f93e232c1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #2 0x41c39d in _start (\/tmp\/uninit+0x41c39d) SUMMARY: MemorySanitizer: use-of-uninitialized-value \/tmp\/uninit.c:3:7 in main<\/code><\/pre>\n<p>\u041e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u043e\u0449\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Valgrind, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0447\u0442\u0435\u043d\u0438\u0438 \u0438\u0437 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">$ clang -o uninit uninit.c -Wall -g $ valgrind .\/uninit ... ==87991== Conditional jump or move depends on uninitialised value(s) ==87991==    at 0x401136: main (uninit.c:3) ...<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/godbolt.org\/z\/hW5xoa\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<h3>ASAN: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0435\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430<\/h3>\n<p>AddressSanitizer \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <code>ASAN_OPTIONS=detect_stack_use_after_return=1<\/code> \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u0441\u043c. <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizerUseAfterReturn\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e AddressSanitizer Use After Return<\/a>). \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a \u0441\u0430\u043c\u0430 \u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Valgrind, \u043d\u043e \u043e\u0431\u043d\u0430\u0436\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441 AddressSanitizer:<\/p>\n<pre><code class=\"cpp\">$ cat >uar.cpp &lt;&lt;'EOF' int *f() {   int i = 42;   int *p = &amp;i;   return p; } int g(int *p) {   return *p; } int main() {   return g(f()); } EOF $ clang++ -o uar uar.cpp -Wall -g -fsanitize=address $ .\/uar (nothing found by default) $ ASAN_OPTIONS=detect_stack_use_after_return=1 .\/uar ================================================================= ==164341==ERROR: AddressSanitizer: stack-use-after-return on address 0x7fb71a561020 at pc 0x0000004f78e1 bp 0x7ffc299184c0 sp 0x7ffc299184b8 READ of size 4 at 0x7fb71a561020 thread T0     #0 0x4f78e0 in g(int*) \/home\/lace\/src\/uar.cpp:7:10     #1 0x4f790b in main \/home\/lace\/src\/uar.cpp:10:10     #2 0x7fb71dbde1e1 in __libc_start_main (\/lib64\/libc.so.6+0x281e1)     #3 0x41c41d in _start (\/home\/lace\/src\/uar+0x41c41d)   Address 0x7fb71a561020 is located in stack of thread T0 at offset 32 in frame     #0 0x4f771f in f() \/home\/lace\/src\/uar.cpp:1     This frame has 1 object(s):     [32, 36) 'i' (line 2) &lt;== Memory access at offset 32 is inside this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork       (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-use-after-return \/home\/lace\/src\/uar.cpp:7:10 in g(int*) ... $ clang++ -o uar uar.cpp -Wall -g $ valgrind .\/uar ... (nothing found by Valgrind)<\/code><\/pre>\n<h3>UBSAN: \u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>UndefinedBehaviorSanitizer \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043a\u043e\u0434 \u043e\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u044f\u0437\u044b\u043a\u0430 (\u0441\u043c. <a href=\"https:\/\/clang.llvm.org\/docs\/UndefinedBehaviorSanitizer.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e UndefinedBehaviorSanitizer<\/a>). \u0418\u0437 \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u043d\u0435 \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043d\u043e \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u043c\u0435\u0441\u0442\u043e \u0432 \u043a\u043e\u0434\u0435. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a\u0438\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. UndefinedBehaviorSanitizer \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0438 \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u043e \u0442\u0430\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445.<\/p>\n<p>UndefinedBehaviorSanitizer \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c Sanitizer\u2019\u043e\u043c, AddressSanitizer:<\/p>\n<pre><code class=\"cpp\">$ cat >undefined.cpp &lt;&lt;'EOF' int main(int argc, char **argv) {   return 0x7fffffff + argc; } EOF $ clang++ -o undefined undefined.cpp -Wall -g -fsanitize=undefined $ export UBSAN_OPTIONS=print_stacktrace=1 $ .\/undefined undefined.cpp:2:21: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'     #0 0x429269 in main \/tmp\/undefined.cpp:2:21     #1 0x7f1212a3e1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #2 0x40345d in _start (\/tmp\/undefined+0x40345d)   SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior undefined.cpp:2:21 in $ valgrind .\/undefined ... (nothing found by Valgrind)<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/godbolt.org\/z\/aMP4sj\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<p>\u041b\u0438\u0447\u043d\u043e \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0436\u0435 \u0442\u0430\u043a\u043e\u043c \u043f\u0440\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043d\u0430\u0447\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0430\u0439\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0442\u0440\u0443\u0434\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e <code>-fno-sanitize-recover=all<\/code>. \u042f \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 UndefinedBehaviorSanitizer, \u0432\u043a\u043b\u044e\u0447\u0438\u0432 \u0432 \u043d\u0435\u0433\u043e: <code>-fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow<\/code>.<\/p>\n<h3>LSAN: \u0423\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438<\/h3>\n<p>LeakSanitizer \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u0431\u044b\u043b\u0430 \u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0430 \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (\u0441\u043c. <a href=\"https:\/\/clang.llvm.org\/docs\/LeakSanitizer.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e LeakSanitizer<\/a>). \u0422\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <a href=\"https:\/\/stackoverflow.com\/q\/654754\/2995591\">\u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439<\/a>. \u041d\u043e \u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u043b\u043e\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445, \u043d\u0435\u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">$ cat >leak.cpp &lt;&lt;'EOF' #include &lt;stdlib.h> int main() {   void *p = malloc(10);   return p == nullptr; } EOF $ clang++ -o leak leak.cpp -Wall -g -fsanitize=address $ .\/leak ================================================================= ==188539==ERROR: LeakSanitizer: detected memory leaks   Direct leak of 10 byte(s) in 1 object(s) allocated from:     #0 0x4bfcdf in malloc (\/tmp\/leak+0x4bfcdf)     #1 0x4f7728 in main \/tmp\/leak.cpp:3:13     #2 0x7fd5a7a781e1 in __libc_start_main (\/lib64\/libc.so.6+0x281e1)   SUMMARY: AddressSanitizer: 10 byte(s) leaked in 1 allocation(s). $ clang++ -o leak leak.cpp -Wall -g $ valgrind --leak-check=full .\/leak ... ==188524== 10 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==188524==    at 0x4839809: malloc (vg_replace_malloc.c:307) ==188524==    by 0x401148: main (leak.cpp:3) ...<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/godbolt.org\/z\/chaf5j\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<h3>LSAN: \u0423\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a (glib2)<\/h3>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0438\u043c\u0435\u044e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u044b \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 LeakSanitizer \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u2014 <a href=\"https:\/\/en.wikipedia.org\/wiki\/GLib\">glib2<\/a> (\u043d\u0435 <a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_C_Library\">glibc<\/a>). \u0414\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u043f\u0446\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0412\u043e\u0442 \u0442\u0430\u043a \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b LeakSanitizer \u0438 Valgrind:<\/p>\n<pre><code class=\"cpp\">$ cat >gc.c &lt;&lt;'EOF' #include &lt;glib.h> int main(void) {     GHashTable *ht = g_hash_table_new(g_str_hash, g_str_equal);     g_hash_table_insert(ht, \"foo\", \"bar\"); \/\/    g_hash_table_destroy(ht); \/\/ \u0443\u0442\u0435\u0447\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 glib2     g_malloc(100); \/\/ \u043f\u0440\u044f\u043c\u0430\u044f \u0443\u0442\u0435\u0447\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438     return 0; } EOF $ clang -o gc gc.c -Wall -g $(pkg-config --cflags --libs glib-2.0) -fsanitize=address $ .\/gc ================================================================= ==233215==ERROR: LeakSanitizer: detected memory leaks   Direct leak of 100 byte(s) in 1 object(s) allocated from:     #0 0x4bfd2f in malloc (\/tmp\/gc+0x4bfd2f)     #1 0x7f1fcf12b908 in g_malloc (\/lib64\/libglib-2.0.so.0+0x5b908)     #2 0x7f1fced961e1 in __libc_start_main (\/lib64\/libc.so.6+0x281e1)   SUMMARY: AddressSanitizer: 100 byte(s) leaked in 1 allocation(s). $ clang -o gc gc.c -Wall -g $(pkg-config --cflags --libs glib-2.0) $ valgrind --leak-check=full .\/gc ... ==233250== 100 bytes in 1 blocks are definitely lost in loss record 8 of 11 ==233250==    at 0x4839809: malloc (vg_replace_malloc.c:307) ==233250==    by 0x48DF908: g_malloc (in \/usr\/lib64\/libglib-2.0.so.0.6600.3) ==233250==    by 0x4011C5: main (gc.c:6) ==233250== ==233250== 256 (96 direct, 160 indirect) bytes in 1 blocks are definitely lost in loss record 9 of 11 ==233250==    at 0x4839809: malloc (vg_replace_malloc.c:307) ==233250==    by 0x48DF908: g_malloc (in \/usr\/lib64\/libglib-2.0.so.0.6600.3) ==233250==    by 0x48F71C1: g_slice_alloc (in \/usr\/lib64\/libglib-2.0.so.0.6600.3) ==233250==    by 0x48C5A51: g_hash_table_new_full (in \/usr\/lib64\/libglib-2.0.so.0.6600.3) ==233250==    by 0x401197: main (gc.c:3) ...<\/code><\/pre>\n<p>LeakSanitizer \u043e\u0431 \u0443\u0442\u0435\u0447\u043a\u0435 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Valgrind \u043e \u043d\u0435\u0439 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e glib2 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u0442 Valgrind \u0438 \u0432 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 Valgrind \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u0430\u043c\u044f\u0442\u0438 (<a href=\"https:\/\/developer.gnome.org\/glib\/stable\/glib-Memory-Slices.html\">g_slice<\/a>). \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c glib2 \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u043e\u0439 \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0434\u0430\u0436\u0435 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c LeakSanitizer:<\/p>\n<pre><code class=\"cpp\">$ clang -o gc gc.c -Wall -g $(pkg-config --cflags --libs glib-2.0) -fsanitize=address # otherwise the backtraces would have only 2 entries: $ export ASAN_OPTIONS=fast_unwind_on_malloc=0 # Show all glib2 memory leaks: $ export G_SLICE=always-malloc G_DEBUG=gc-friendly $ .\/gc ================================================================= ==233921==ERROR: LeakSanitizer: detected memory leaks   Direct leak of 100 byte(s) in 1 object(s) allocated from:     #0 0x4bfd2f in malloc (\/tmp\/gc+0x4bfd2f)     #1 0x7f2a7c302908 in g_malloc ..\/glib\/gmem.c:106:13     #2 0x4f4b35 in main \/tmp\/gc.c:6:5     #3 0x7f2a7bf6d1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #4 0x41c46d in _start (\/tmp\/gc+0x41c46d)   Direct leak of 96 byte(s) in 1 object(s) allocated from:     #0 0x4bfd2f in malloc (\/tmp\/gc+0x4bfd2f)     #1 0x7f2a7c302908 in g_malloc ..\/glib\/gmem.c:106:13     #2 0x7f2a7c31a1c1 in g_slice_alloc ..\/glib\/gslice.c:1069:11     #3 0x7f2a7c2e8a51 in g_hash_table_new_full ..\/glib\/ghash.c:1072:16     #4 0x4f4b07 in main \/tmp\/gc.c:3:22     #5 0x7f2a7bf6d1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #6 0x41c46d in _start (\/tmp\/gc+0x41c46d)   Indirect leak of 32 byte(s) in 1 object(s) allocated from:     #0 0x4bfd2f in malloc (\/tmp\/gc+0x4bfd2f)     #1 0x7f2a7c302908 in g_malloc ..\/glib\/gmem.c:106:13     #2 0x7f2a7c317ce1  ..\/glib\/gstrfuncs.c:392:17     #3 0x7f2a7c317ce1 in g_memdup ..\/glib\/gstrfuncs.c:385:1     #4 0x7f2a7c2e8b65 in g_hash_table_ensure_keyval_fits ..\/glib\/ghash.c:974:36     #5 0x7f2a7c2e8b65 in g_hash_table_insert_node ..\/glib\/ghash.c:1327:3     #6 0x7f2a7c2e930f in g_hash_table_insert_internal ..\/glib\/ghash.c:1601:10     #7 0x7f2a7c2e930f in g_hash_table_insert ..\/glib\/ghash.c:1630:10     #8 0x4f4b28 in main \/tmp\/gc.c:4:5     #9 0x7f2a7bf6d1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #10 0x41c46d in _start (\/tmp\/gc+0x41c46d)   Indirect leak of 32 byte(s) in 1 object(s) allocated from:     #0 0x4bfed7 in calloc (\/tmp\/gc+0x4bfed7)     #1 0x7f2a7c302e20 in g_malloc0 ..\/glib\/gmem.c:136:13     #2 0x7f2a7c2e50ef in g_hash_table_setup_storage ..\/glib\/ghash.c:592:24     #3 0x7f2a7c2e8a90 in g_hash_table_new_full ..\/glib\/ghash.c:1084:3     #4 0x4f4b07 in main \/tmp\/gc.c:3:22     #5 0x7f2a7bf6d1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #6 0x41c46d in _start (\/tmp\/gc+0x41c46d)   Indirect leak of 32 byte(s) in 1 object(s) allocated from:     #0 0x4c0098 in realloc (\/tmp\/gc+0x4c0098)     #1 0x7f2a7c302f5f in g_realloc ..\/glib\/gmem.c:171:16     #2 0x7f2a7c2e50da in g_hash_table_realloc_key_or_value_array ..\/glib\/ghash.c:380:10     #3 0x7f2a7c2e50da in g_hash_table_setup_storage ..\/glib\/ghash.c:590:24     #4 0x7f2a7c2e8a90 in g_hash_table_new_full ..\/glib\/ghash.c:1084:3     #5 0x4f4b07 in main \/tmp\/gc.c:3:22     #6 0x7f2a7bf6d1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #7 0x41c46d in _start (\/tmp\/gc+0x41c46d)   SUMMARY: AddressSanitizer: 292 byte(s) leaked in 5 allocation(s).<\/code><\/pre>\n<h3>TSAN: \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438<\/h3>\n<p>ThreadSanitizer \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0433\u043e\u043d\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0431\u0435\u0437 \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0433\u043e\u043d\u043a\u0438 (\u0441\u043c. <a href=\"https:\/\/clang.llvm.org\/docs\/ThreadSanitizer.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e ThreadSanitizer<\/a>). \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">$ cat >tiny.cpp &lt;&lt;'EOF' #include &lt;thread>   static volatile bool flip1{false}; static volatile bool flip2{false};   int main() {   std::thread t([&amp;]() {     while (!flip1);     flip2 = true;   });   flip1 = true;   while (!flip2);   t.join(); } EOF $ clang++ -o tiny tiny.cpp -Wall -g -pthread -fsanitize=thread $ .\/tiny ================== WARNING: ThreadSanitizer: data race (pid=4057433)   Write of size 1 at 0x000000fb4b09 by thread T1:     #0 main::$_0::operator()() const \/tmp\/tiny.cpp:9:11 (tiny+0x4cfc98)     #1 void std::__invoke_impl&lt;void, main::$_0>(std::__invoke_other, main::$_0&amp;&amp;) \/usr\/lib\/gcc\/x86_64-redhat-linux\/10\/..\/..\/..\/..\/include\/c++\/10\/bits\/invoke.h:60:14 (tiny+0x4cfc30)     #2 std::__invoke_result&lt;main::$_0>::type std::__invoke&lt;main::$_0>(main::$_0&amp;&amp;) \/usr\/lib\/gcc\/x86_64-redhat-linux\/10\/..\/..\/..\/..\/include\/c++\/10\/bits\/invoke.h:95:14 (tiny+0x4cfb40)     #3 void std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::_M_invoke&lt;0ul>(std::_Index_tuple&lt;0ul>) \/usr\/lib\/gcc\/x86_64-redhat-linux\/10\/..\/..\/..\/..\/include\/c++\/10\/thread:264:13 (tiny+0x4cfae8)     #4 std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::operator()() \/usr\/lib\/gcc\/x86_64-redhat-linux\/10\/..\/..\/..\/..\/include\/c++\/10\/thread:271:11 (tiny+0x4cfa88)     #5 std::thread::_State_impl&lt;std::thread::_Invoker&lt;std::tuple&lt;main::$_0> > >::_M_run() \/usr\/lib\/gcc\/x86_64-redhat-linux\/10\/..\/..\/..\/..\/include\/c++\/10\/thread:215:13 (tiny+0x4cf97f)     #6 execute_native_thread_routine ..\/..\/..\/..\/..\/libstdc++-v3\/src\/c++11\/thread.cc:80:18 (libstdc++.so.6+0xd65f3)     Previous read of size 1 at 0x000000fb4b09 by main thread:     #0 main \/tmp\/tiny.cpp:12:11 (tiny+0x4cf51f)     Location is global 'flip2' of size 1 at 0x000000fb4b09 (tiny+0x000000fb4b09)     Thread T1 (tid=4057435, running) created by main thread at:     #0 pthread_create &lt;null> (tiny+0x488b7d)     #1 &lt;null> \/usr\/src\/debug\/gcc-10.2.1-9.fc33.x86_64\/obj-x86_64-redhat-linux\/x86_64-redhat-linux\/libstdc++-v3\/include\/x86_64-redhat-linux\/bits\/gthr-default.h:663:35 (libstdc++.so.6+0xd6898)     #2 std::thread::_M_start_thread(std::unique_ptr&lt;std::thread::_State, std::default_delete&lt;std::thread::_State> >, void (*)()) ..\/..\/..\/..\/..\/libstdc++-v3\/src\/c++11\/thread.cc:135:37 (libstdc++.so.6+0xd6898)     #3 main \/tmp\/tiny.cpp:7:15 (tiny+0x4cf4f4)   SUMMARY: ThreadSanitizer: data race \/tmp\/tiny.cpp:9:11 in main::$_0::operator()() const ================== ThreadSanitizer: reported 1 warnings $ clang++ -o tiny tiny.cpp -Wall -g -pthread $ valgrind --tool=helgrind .\/tiny ... ==4057510== ---------------------------------------------------------------- ==4057510== ==4057510== Possible data race during write of size 1 at 0x40406D by thread #1 ==4057510== Locks held: none ==4057510==    at 0x4011DC: main (tiny.cpp:11) ==4057510== ==4057510== This conflicts with a previous read of size 1 by thread #2 ==4057510== Locks held: none ==4057510==    at 0x4015F8: main::$_0::operator()() const (tiny.cpp:8) ==4057510==    by 0x4015DC: void std::__invoke_impl&lt;void, main::$_0>(std::__invoke_other, main::$_0&amp;&amp;) (invoke.h:60) ==4057510==    by 0x40156C: std::__invoke_result&lt;main::$_0>::type std::__invoke&lt;main::$_0>(main::$_0&amp;&amp;) (invoke.h:95) ==4057510==    by 0x401544: void std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::_M_invoke&lt;0ul>(std::_Index_tuple&lt;0ul>) (thread:264) ==4057510==    by 0x401514: std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::operator()() (thread:271) ==4057510==    by 0x40148D: std::thread::_State_impl&lt;std::thread::_Invoker&lt;std::tuple&lt;main::$_0> > >::_M_run() (thread:215) ==4057510==    by 0x49575F3: execute_native_thread_routine (thread.cc:80) ==4057510==    by 0x4840737: mythread_wrapper (hg_intercepts.c:387) ==4057510==  Address 0x40406d is 0 bytes inside data symbol \"_ZL5flip1\" ==4057510== ==4057510== ---------------------------------------------------------------- ==4057510== ==4057510== Possible data race during read of size 1 at 0x40406D by thread #2 ==4057510== Locks held: none ==4057510==    at 0x4015F8: main::$_0::operator()() const (tiny.cpp:8) ==4057510==    by 0x4015DC: void std::__invoke_impl&lt;void, main::$_0>(std::__invoke_other, main::$_0&amp;&amp;) (invoke.h:60) ==4057510==    by 0x40156C: std::__invoke_result&lt;main::$_0>::type std::__invoke&lt;main::$_0>(main::$_0&amp;&amp;) (invoke.h:95) ==4057510==    by 0x401544: void std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::_M_invoke&lt;0ul>(std::_Index_tuple&lt;0ul>) (thread:264) ==4057510==    by 0x401514: std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::operator()() (thread:271) ==4057510==    by 0x40148D: std::thread::_State_impl&lt;std::thread::_Invoker&lt;std::tuple&lt;main::$_0> > >::_M_run() (thread:215) ==4057510==    by 0x49575F3: execute_native_thread_routine (thread.cc:80) ==4057510==    by 0x4840737: mythread_wrapper (hg_intercepts.c:387) ==4057510==    by 0x4BD33F8: start_thread (pthread_create.c:463) ==4057510==    by 0x4CED902: clone (clone.S:95) ==4057510== ==4057510== This conflicts with a previous write of size 1 by thread #1 ==4057510== Locks held: none ==4057510==    at 0x4011DC: main (tiny.cpp:11) ==4057510==  Address 0x40406d is 0 bytes inside data symbol \"_ZL5flip1\" ==4057510== ==4057510== ---------------------------------------------------------------- ==4057510== ==4057510== Possible data race during write of size 1 at 0x40406E by thread #2 ==4057510== Locks held: none ==4057510==    at 0x401613: main::$_0::operator()() const (tiny.cpp:9) ==4057510==    by 0x4015DC: void std::__invoke_impl&lt;void, main::$_0>(std::__invoke_other, main::$_0&amp;&amp;) (invoke.h:60) ==4057510==    by 0x40156C: std::__invoke_result&lt;main::$_0>::type std::__invoke&lt;main::$_0>(main::$_0&amp;&amp;) (invoke.h:95) ==4057510==    by 0x401544: void std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::_M_invoke&lt;0ul>(std::_Index_tuple&lt;0ul>) (thread:264) ==4057510==    by 0x401514: std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::operator()() (thread:271) ==4057510==    by 0x40148D: std::thread::_State_impl&lt;std::thread::_Invoker&lt;std::tuple&lt;main::$_0> > >::_M_run() (thread:215) ==4057510==    by 0x49575F3: execute_native_thread_routine (thread.cc:80) ==4057510==    by 0x4840737: mythread_wrapper (hg_intercepts.c:387) ==4057510==    by 0x4BD33F8: start_thread (pthread_create.c:463) ==4057510==    by 0x4CED902: clone (clone.S:95) ==4057510== ==4057510== This conflicts with a previous read of size 1 by thread #1 ==4057510== Locks held: none ==4057510==    at 0x4011E4: main (tiny.cpp:12) ==4057510==  Address 0x40406e is 0 bytes inside data symbol \"_ZL5flip2\" ==4057510== ==4057510== ---------------------------------------------------------------- ==4057510== ==4057510== Possible data race during read of size 1 at 0x40406E by thread #1 ==4057510== Locks held: none ==4057510==    at 0x4011E4: main (tiny.cpp:12) ==4057510== ==4057510== This conflicts with a previous write of size 1 by thread #2 ==4057510== Locks held: none ==4057510==    at 0x401613: main::$_0::operator()() const (tiny.cpp:9) ==4057510==    by 0x4015DC: void std::__invoke_impl&lt;void, main::$_0>(std::__invoke_other, main::$_0&amp;&amp;) (invoke.h:60) ==4057510==    by 0x40156C: std::__invoke_result&lt;main::$_0>::type std::__invoke&lt;main::$_0>(main::$_0&amp;&amp;) (invoke.h:95) ==4057510==    by 0x401544: void std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::_M_invoke&lt;0ul>(std::_Index_tuple&lt;0ul>) (thread:264) ==4057510==    by 0x401514: std::thread::_Invoker&lt;std::tuple&lt;main::$_0> >::operator()() (thread:271) ==4057510==    by 0x40148D: std::thread::_State_impl&lt;std::thread::_Invoker&lt;std::tuple&lt;main::$_0> > >::_M_run() (thread:215) ==4057510==    by 0x49575F3: execute_native_thread_routine (thread.cc:80) ==4057510==    by 0x4840737: mythread_wrapper (hg_intercepts.c:387) ==4057510==  Address 0x40406e is 0 bytes inside data symbol \"_ZL5flip2\" ...<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/godbolt.org\/z\/xKjK5P\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer<\/p>\n<h3>\u041f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/h3>\n<p>AddressSanitizer \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a <a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_C_Library\">glibc<\/a>. \u042d\u0442\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c. \u0427\u0442\u043e\u0431\u044b AddressSanitizer \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>-fsanitize=address<\/code>. \u0414\u043b\u044f Valgrind \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <code>libuser.c<\/code> \u0432\u0441\u0435-\u0440\u0430\u0432\u043d\u043e \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f AddressSanitizer \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a\u0443 glibc, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0441 AddressSanitizer:<\/p>\n<pre><code class=\"cpp\">$ cat >library.c &lt;&lt;'EOF' #include &lt;string.h> void library(char *s) {   strcpy(s,\"string\"); } EOF $ cat >libuser.c &lt;&lt;'EOF' #include &lt;stdlib.h> void library(char *s); int main(void) {   char *s = malloc(1);   library(s);   free(s); } EOF $ clang -o library.so library.c -Wall -g -shared -fPIC $ clang -o libuser libuser.c -Wall -g .\/library.so -fsanitize=address $ .\/libuser ================================================================= ==128657==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000011 at pc 0x000000484a6d bp 0x7fff13a4ace0 sp 0x7fff13a4a490 WRITE of size 7 at 0x602000000011 thread T0     #0 0x484a6c in __interceptor_strcpy.part.0 (\/tmp\/libuser+0x484a6c)     #1 0x7fae9f53512b in library \/tmp\/library.c:3:3     #2 0x4f4abe in main \/tmp\/libuser.c:5:3     #3 0x7fae9f1be1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #4 0x41c42d in _start (\/tmp\/libuser+0x41c42d)   0x602000000011 is located 0 bytes to the right of 1-byte region [0x602000000010,0x602000000011) allocated by thread T0 here:     #0 0x4bfcef in malloc (\/tmp\/libuser+0x4bfcef)     #1 0x4f4ab1 in main \/tmp\/libuser.c:4:13     #2 0x7fae9f1be1e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16   SUMMARY: AddressSanitizer: heap-buffer-overflow (\/tmp\/libuser+0x484a6c) in __interceptor_strcpy.part.0 ...<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 AddressSanitizer \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0435\u0441\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AddressSanitizer:<\/p>\n<pre><code class=\"cpp\">$ cat >library.c &lt;&lt;'EOF' void library(char *s) {   const char *cs = \"string\";   while (*cs)     *s++ = *cs++;   *s = 0; } EOF $ cat >libuser.c &lt;&lt;'EOF' #include &lt;stdlib.h> void library(char *s); int main(void) {   char *s = malloc(1);   library(s);   free(s); } EOF $ clang -o library.so library.c -Wall -g -shared -fPIC $ clang -o libuser libuser.c -Wall -g .\/library.so -fsanitize=address $ .\/libuser (nothing found by AddressSanitizer)<\/code><\/pre>\n<p>Valgrind \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0443 \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">$ clang -o library.so library.c -Wall -g -shared -fPIC; clang -o libuser libuser.c -Wall -g .\/library.so; valgrind .\/libuser ... ==128708== Invalid write of size 1 ==128708==    at 0x4849146: library (library.c:4) ==128708==    by 0x40116E: main (libuser.c:5) ==128708==  Address 0x4a57041 is 0 bytes after a block of size 1 alloc'd ==128708==    at 0x4839809: malloc (vg_replace_malloc.c:307) ==128708==    by 0x401161: main (libuser.c:4) ...<\/code><\/pre>\n<p>AddressSanitizer \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0443, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AddressSanitizer:<\/p>\n<pre><code class=\"cpp\">$ clang -o library.so library.c -Wall -g -shared -fPIC -fsanitize=address $ clang -o libuser libuser.c -Wall -g .\/library.so -fsanitize=address $ .\/libuser ================================================================= ==128719==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000011 at pc 0x7f7e4e68b269 bp 0x7ffc40c0dc30 sp 0x7ffc40c0dc28 WRITE of size 1 at 0x602000000011 thread T0     #0 0x7f7e4e68b268 in library \/tmp\/library.c:4:10     #1 0x4f4abe in main \/tmp\/libuser.c:5:3     #2 0x7f7e4e3141e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16     #3 0x41c42d in _start (\/tmp\/libuser+0x41c42d)   0x602000000011 is located 0 bytes to the right of 1-byte region [0x602000000010,0x602000000011) allocated by thread T0 here:     #0 0x4bfcef in malloc (\/tmp\/libuser+0x4bfcef)     #1 0x4f4ab1 in main \/tmp\/libuser.c:4:13     #2 0x7f7e4e3141e1 in __libc_start_main \/usr\/src\/debug\/glibc-2.32-20-g5c36293f06\/csu\/..\/csu\/libc-start.c:314:16   SUMMARY: AddressSanitizer: heap-buffer-overflow \/tmp\/library.c:4:10 in library ...<\/code><\/pre>\n<h3>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 Sanitizers \u0441 _FORTIFY_SOURCE<\/h3>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>rpmbuild<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u043f\u0446\u0438\u044e <code>-Wp,-D_FORTIFY_SOURCE=2<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u0438. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043e\u043d\u0430 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 AddressSanitizer. \u042d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 <a href=\"https:\/\/github.com\/google\/sanitizers\/issues\/247\">\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c<\/a>. \u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0441 \u043f\u043e\u043c\u043e\u0448\u044c\u044e Sanitizers, \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u0435 <code>_FORTIFY_SOURCE<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>-Wp,-U_FORTIFY_SOURCE<\/code> (\u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 <code>-D_FORTIFY_SOURCE=0<\/code>):<\/p>\n<pre><code class=\"cpp\">$ cat >strcpyfrom.spec &lt;&lt;'EOF' Summary: strcpyfrom Name: strcpyfrom Version: 1 Release: 1 License: GPLv3+ %description %build cat >strcpyfrom.c &lt;&lt;'EOH' #include &lt;stdlib.h> #include &lt;string.h> int main(void) {   char *s = malloc(1);   char d[0x1000];   strcpy(d, s);   return 0; } EOH gcc -o strcpyfrom strcpyfrom.c $RPM_OPT_FLAGS -fsanitize=address echo no error caught: .\/strcpyfrom gcc -o strcpyfrom strcpyfrom.c $RPM_OPT_FLAGS -fsanitize=address -Wp,-U_FORTIFY_SOURCE echo error caught: .\/strcpyfrom EOF $ rpmbuild -bb strcpyfrom.spec  Executing(%build): \/bin\/sh -e \/var\/tmp\/rpm-tmp.KTLr7c + umask 022 + cd src\/rpm\/BUILD + cat + gcc -o strcpyfrom strcpyfrom.c -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=\/usr\/lib\/rpm\/redhat\/redhat-hardened-cc1 -fstack-protector-strong -specs=\/usr\/lib\/rpm\/redhat\/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fsanitize=address + echo no error caught: no error caught: + .\/strcpyfrom + gcc -o strcpyfrom strcpyfrom.c -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=\/usr\/lib\/rpm\/redhat\/redhat-hardened-cc1 -fstack-protector-strong -specs=\/usr\/lib\/rpm\/redhat\/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fsanitize=address -Wp,-U_FORTIFY_SOURCE annobin: strcpyfrom.c: Warning: -D_FORTIFY_SOURCE defined as 0 + echo error caught: error caught: + .\/strcpyfrom ================================================================= ==412157==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000011 at pc 0x7fe75d8b2075 bp 0x7ffccf5dd1e0 sp 0x7ffccf5dc990 READ of size 2 at 0x602000000011 thread T0     #0 0x7fe75d8b2074  (\/lib64\/libasan.so.6+0x52074)     #1 0x4011be in main strcpyfrom.c:6     #2 0x7fe75d6bd1e1 in __libc_start_main ..\/csu\/libc-start.c:314     #3 0x40127d in _start (strcpyfrom+0x40127d)   0x602000000011 is located 0 bytes to the right of 1-byte region [0x602000000010,0x602000000011) allocated by thread T0 here:     #0 0x7fe75d90b3cf in __interceptor_malloc (\/lib64\/libasan.so.6+0xab3cf)     #1 0x4011b2 in main strcpyfrom.c:4     #2 0x40200f  (strcpyfrom+0x40200f)   SUMMARY: AddressSanitizer: heap-buffer-overflow (\/lib64\/libasan.so.6+0x52074)  ... error: Bad exit status from \/var\/tmp\/rpm-tmp.KTLr7c (%build)   RPM build errors:     Bad exit status from \/var\/tmp\/rpm-tmp.KTLr7c (%build)<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u043a Valgrind, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 AddressSanitizer \u2014 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u043a\u0438 \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 <code>-fsanitize=address<\/code> (\u0442\u043e \u0435\u0441\u0442\u044c, \u043a\u043e \u0432\u0441\u0435\u043c <code>CFLAGS<\/code>, <code>CXXFLAGS<\/code> \u0438 <code>LDFLAGS<\/code>). \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0442\u043e \u0432\u0435\u0440\u043d\u0438\u0442\u0435\u0441\u044c \u043a \u0440\u0430\u0437\u0434\u0435\u043b\u0443 &#171;<a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#tldr\">\u041a\u0440\u0430\u0442\u043a\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043a Sanitizers<\/a>&#187; \u0437\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u043c\u0438 \u043f\u043e \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u043d\u043a\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435.<\/p>\n<hr\/>\n<p>\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0432\u0441\u0435\u0445 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a \u00ab\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0421\u0438 \u0438 Python\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432 20:00. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0445\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 C \u0438 Python, \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u044d\u0442\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430. \u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/otus.pw\/SLgG\/\">\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u0443\u0440\u0441\u0430 \u00ab\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0421\u00bb.<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/801123\/\"> https:\/\/habr.com\/ru\/articles\/801123\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Memory_safety\">memory-unsafe<\/a> (\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e) \u044f\u0437\u044b\u043a\u0430\u0445 \u2014 <a href=\"https:\/\/github.com\/google\/sanitizers\">Sanitizers<\/a> \u0438 <a href=\"https:\/\/www.valgrind.org\/\">Valgrind<\/a>. \u042d\u0442\u0438 \u0434\u0432\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0445\u043e\u0442\u044c Sanitizers (\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430\u043c\u0438 Google) \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043f\u0435\u0440\u0435\u0434 Valgrind, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u0438\u043b\u044c\u043d\u044b\u0435 \u0438 \u0441\u043b\u0430\u0431\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0435\u043a\u0442 Sanitizers \u0438\u043c\u0435\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 Java, Python \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0438\u043c \u044f\u0437\u044b\u043a\u043e\u0432 \u0441 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043f\u0430\u043c\u044f\u0442\u0438, \u044f\u0437\u044b\u043a\u0430\u043c \u0441 \u043f\u0440\u044f\u043c\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043f\u0430\u043c\u044f\u0442\u0438, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a <a href=\"https:\/\/developers.redhat.com\/topics\/c\">C \u0438 C++<\/a>, \u043d\u0443\u0436\u043d\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u0435\u0439. \u0412 memory-unsafe \u044f\u0437\u044b\u043a\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u043e\u043d\u0435\u0446 \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043b\u0438 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0430. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043c\u043e\u0433\u0443\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044f\u0441\u044c \u043a\u0440\u0430\u0448\u0435\u043c \u043b\u0438\u0448\u044c \u0432 \u0440\u0435\u0434\u043a\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445. \u0412\u044b\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0430\u043c\u043e\u043c\u0443 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>\u041d\u0430\u0447\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e Valgrind \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0441\u0438\u043b\u044c\u043d\u0435\u0435, \u0447\u0435\u043c Sanitizers. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434 Valgrind, \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0442 20 \u0434\u043e 50 \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u043c \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0441 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u044b\u043c\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438. \u0417\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 Sanitizers \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 2-4 \u0440\u0430\u0437\u0430 \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439. \u0412\u043c\u0435\u0441\u0442\u043e Valgrind \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Sanitizers \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h3>\u041a\u0440\u0430\u0442\u043a\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043a Sanitizers<\/h3>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043f\u043e\u0434\u044b\u0442\u043e\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c, \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c \u0441 Sanitizers:<\/p>\n<ul>\n<li>\n<p>\u041e\u043f\u0446\u0438\u0438 Clang\/GCC: <\/p>\n<\/li>\n<\/ul>\n<pre><code>-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment<\/code><\/pre>\n<ul>\n<li>\n<p>\u0414\u043b\u044f LLDB\/GDB \u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0441\u0442\u0435\u043a-\u0442\u0440\u0435\u0439\u0441\u043e\u0432 \u0438, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0443\u0442\u0435\u0447\u0435\u043a:<\/p>\n<\/li>\n<\/ul>\n<pre><code>$ export ASAN_OPTIONS=abort_on_error=1:fast_unwind_on_malloc=0:detect_leaks=0 UBSAN_OPTIONS=print_stacktrace=1<\/code><\/pre>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u0443\u0442\u0435\u0447\u043a\u0430\u0445 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/GLib\"><u>glib2<\/u><\/a>:<\/p>\n<\/li>\n<\/ul>\n<pre><code>$ export G_SLICE=always-malloc G_DEBUG=gc-friendly<\/code><\/pre>\n<ul>\n<li>\n<p>\u041e\u043f\u0446\u0438\u044f Clang \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0430 \u0447\u0442\u0435\u043d\u0438\u044f \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438: <code>-fsanitize=memory<\/code>. \u042d\u0442\u0443 \u043e\u043f\u0446\u0438\u044e \u043d\u0435\u043b\u044c\u0437\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 <code>-fsanitize=address<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 rpmbuild .spec \u0444\u0430\u0439\u043b\u0430\u0445 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c: <code>-Wp,-U_FORTIFY_SOURCE<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 Sanitizers\u00a0<\/h3>\n<p>Valgrind \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435, \u0430 \u043d\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u044b\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430. Sanitizers \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441 \u043c\u0435\u043d\u044c\u0448\u0438\u043c\u0438 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c\u0438.<\/p>\n<p>\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 1 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizerComparisonOfMemoryTools\">\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435<\/a>, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043e\u0431\u043e\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u00a0<\/p>\n<\/td>\n<td>\n<p align=\"left\">Sanitizers<\/p>\n<\/td>\n<td>\n<p align=\"left\">Valgrind<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>: \u043e\u0431\u0449\u0435\u0435 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/td>\n<td>\n<p align=\"left\">2 \u2013 4 \u0440\u0430\u0437\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">20 \u2013 50 \u0440\u0430\u0437<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>: <a href=\"https:\/\/godbolt.org\/z\/vedx5q\">\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">1 (= \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u0432\u0440\u0435\u043c\u044f)<\/p>\n<\/td>\n<td>\n<p align=\"left\">3.45 \u0440\u0430\u0437\u0430 (+23\u0441 = 12 \u0440\u0430\u0437)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>: <a href=\"https:\/\/godbolt.org\/z\/zjTG8q\">\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u044f \u0441 malloc<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">17 \u0440\u0430\u0437<\/p>\n<\/td>\n<td>\n<p align=\"left\">101 \u0440\u0430\u0437 (+23\u0441 = 256 \u0440\u0430\u0437)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>: <a href=\"https:\/\/godbolt.org\/z\/Y5EPc3\">\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u044f \u0441 AVX2<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.05 (= \u043d\u0430 5% \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435)<\/p>\n<\/td>\n<td>\n<p align=\"left\">53 \u0440\u0430\u0437\u0430 (+23\u0441 = 60 \u0440\u0430\u0437)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/clang.llvm.org\/docs\/ThreadSanitizer.html\">TSAN<\/a>: <a href=\"https:\/\/godbolt.org\/z\/6zMWEe\">\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u044f \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0433\u043e\u043d\u043a\u0438<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">9 \u0440\u0430\u0437<\/p>\n<\/td>\n<td>\n<p align=\"left\">340 \u0440\u0430\u0437 (+31\u0441 = 404 \u0440\u0430\u0437\u0430)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0412\u044b\u0445\u043e\u0434 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (<a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#outofboundsstack\">\u0441\u0442\u0435\u043a\u043e\u0432\u044b\u0445<\/a>, <a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#outofboundsglobal\">\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043f\u0443\u0441\u0442\u0438\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">Memcheck<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#uninit\">\u041d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/MemorySanitizer.html\">MSAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">Memcheck<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#stackafterreturn\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0435\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">ASAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043f\u0443\u0441\u0442\u0438\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">\u041c\u0435\u043c\u0447\u0435\u043a<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#undefined\">\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/UndefinedBehaviorSanitizer.html\">UBSAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043f\u0443\u0441\u0442\u0438\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">\u041c\u0435\u043c\u0447\u0435\u043a<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#leak\">\u0423\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/LeakSanitizer.html\">LSAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">Memcheck<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#datarace\">\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/clang.llvm.org\/docs\/ThreadSanitizer.html\">TSAN<\/a>)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0439\u043c\u0430\u043b (<a href=\"https:\/\/www.valgrind.org\/docs\/manual\/hg-manual.html\">Helgrind<\/a>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#recompilation\">\u041f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412 \u043c\u043e\u0438\u0445 \u0442\u0435\u0441\u0442\u0430\u0445 Valgrind \u0442\u0440\u0430\u0442\u0438\u0442 23 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u042d\u0442\u0443 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u044c, \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \/usr\/lib\/debug. \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e! \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u0430\u044f \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u043f\u0430\u0441\u0442\u044c \u0438 \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f (\u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430):<\/p>\n<pre><code>$ sudo mv \/usr\/lib\/debug \/usr\/lib\/debug-x; sleep 1h; sudo mv \/usr\/lib\/debug-x \/usr\/lib\/debug<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442\u044b \u043d\u0430 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u0438 \u0441\u0443\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0430\u043d\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code>$ clang++ -g -O3 -march=native -ffast-math ... clang-11.0.0-2.fc33.x86_64 valgrind-3.16.1-5.fc33.x86_64<\/code><\/pre>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 <code>-fsanitize=address<\/code>, <code>-fsanitize=undefined<\/code> \u0438\u043b\u0438 &#8212;<code>fsanitize=thread<\/code> \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b \u0432 <a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#tldr\">\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043a Sanitizers<\/a>.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 Clang. GCC \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 Sanitizers, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 <code>-fsanitize=memory<\/code> (\u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0438\u043c \u044d\u0442\u043e \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <a href=\"https:\/\/developers.redhat.com\/blog\/2021\/05\/05\/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#uninit\">MSAN: \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/a>).<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 debuginfo<\/h3>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0444\u0430\u0439\u043b\u044b <code>*-debuginfo.rpm<\/code> \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>dnf debuginfo-install packagename<\/code>. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 <a href=\"https:\/\/developers.redhat.com\/products\/rhel\/overview\">Red Hat Enterprise Linux<\/a> (RHEL) \u0432\u043c\u0435\u0441\u0442\u043e <code>dnf<\/code> \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>yum<\/code>. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 <code>gdb<\/code>, \u043e\u043d\u0430 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 \u0432\u0430\u043c, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e RPM:<\/p>\n<pre><code class=\"cpp\">$ cat >vector.cpp &lt;&lt;'EOF' \/\/ \u0417\u0434\u0435\u0441\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0435\u0442\u0435, \/\/ \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441 std::vector \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c. #include &lt;vector> int main() {   std::vector&lt;int> v; } EOF $ clang++ -o vector vector.cpp -Wall -g $ gdb .\/vector Reading symbols from .\/vector... (gdb) start ... Missing separate debuginfos, use: dnf debuginfo-install glibc-2.32-2.fc33.x86_64 ... Missing separate debuginfos, use: dnf debuginfo-install libgcc-10.2.1-9.fc33.x86_64 libstdc++-10.2.1-9.fc33.x86_64 (gdb) quit $ sudo dnf debuginfo-install glibc-2.32-2.fc33.x86_64 ... $ sudo dnf debuginfo-install libgcc-10.2.1-9.fc33.x86_64 libstdc++-10.2.1-9.fc33.x86_64 ...<\/code><\/pre>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438: \u041f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0431\u0443\u0444\u0435\u0440\u0430. \u0425\u043e\u0442\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0439, \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043a\u0443\u0434\u0430 \u0431\u043e\u043b\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u044b \u0438 \u0438\u0445 \u0442\u0440\u0443\u0434\u043d\u043e \u043d\u0430\u0439\u0442\u0438. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <a href=\"https:\/\/www.valgrind.org\/docs\/manual\/mc-manual.html\">Valgrind Memcheck<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a. \u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 Valgrind Memcheck \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">$ cat >overrun.c &lt;&lt;'EOF' #include &lt;stdlib.h> int main() {   char *p = malloc(16);   p[24] = 1; \/\/ \u0432\u044b\u0445\u043e\u0434 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0431\u0443\u0444\u0435\u0440\u0430, \u0432 p \u0432\u0441\u0435\u0433\u043e 16 \u0431\u0430\u0439\u0442   free(p); \/\/ free(): \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c   return 0; } EOF $ clang -o overrun overrun.c -Wall -g $ valgrind .\/overrun ... ==60988== Invalid write of size 1 ==60988==    at 0x401154: main (overrun.c:4) ==60988==  Address 0x4a52058 is 8 bytes after a block of size 16 alloc'd ==60988==    at 0x4839809: malloc (vg_replace_malloc.c:307) ==60988==    by 0x401147: main (overrun.c:3)<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/godbolt.org\/z\/1Wa6n4\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 Valgrind, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0431\u044b\u0442\u044c. \u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0434\u0430\u0435\u0442 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0447\u0438\u0441\u0442\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>free(): invalid pointer<\/code> \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u0437 <a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_C_Library\">glibc<\/a> (<a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_C_Library\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 GNU C<\/a>), \u0430 \u043d\u0435 \u0438\u0437 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Sanitizers \u0438\u043b\u0438 Valgrind:<\/p>\n<pre><code class=\"cpp\">$ cat >overrun.c &lt;&lt;'EOF' #include &lt;stdlib.h> int main() {   char *p = malloc(16);   char *p2 = malloc(16);   p[24] = 1; \/\/ \u0432\u044b\u0445\u043e\u0434 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0431\u0443\u0444\u0435\u0440\u0430, \u0432 p \u0432\u0441\u0435\u0433\u043e 16 \u0431\u0430\u0439\u0442   free(p2); \/\/ free(): \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c   free(p);   return 0; } EOF $ clang -o overrun overrun.c -Wall -g $ .\/overrun free(): invalid pointer Aborted<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/godbolt.org\/z\/rvEjaK\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<p>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 Sanitizers, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e Valgrind \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">AddressSanitizer<\/a>. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 Valgrind \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u0442\u043e AddressSanitizer \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">$ clang -o overrun overrun.c -Wall -g -fsanitize=address $ .\/overrun ================================================================= ==61268==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000028 at pc 0x0000004011b8 bp 0x7fff37c8aa70 sp 0x7fff37c8aa68 WRITE of size 1 at 0x602000000028 thread T0     #0 0x4011b7 in main overrun.c:4     #1 0x7f4c94a2d1e1 in __libc_start_main ..\/csu\/libc-start.c:314     #2 0x4010ad in _start (overrun+0x4010ad)   0x602000000028 is located 8 bytes to the right of 16-byte region [0x602000000010,0x602000000020) allocated by thread T0 here:     #0 0x7f4c94c7b3cf in __interceptor_malloc (\/lib64\/libasan.so.6+0xab3cf)     #1 0x401177 in main overrun.c:3     #2 0x7f4c94a2d1e1 in __libc_start_main ..\/csu\/libc-start.c:314   SUMMARY: AddressSanitizer: heap-buffer-overflow overrun.c:4 in main ...<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/godbolt.org\/z\/3ns4WM\">\u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434<\/a> \u0432 Compiler Explorer.<\/p>\n<h3><\/h3>\n<h3>ASAN: \u0412\u044b\u0445\u043e\u0434 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0435\u043a\u0430<\/h3>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Valgrind \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043e\u043d \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043f\u0430\u043c\u044f\u0442\u0438. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u043d\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 (\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445) \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (\u0441\u043c. <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizerExampleStackOutOfBounds\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e AddressSanitizer Stack Out of Bounds<\/a>).<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Valgrind \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043e\u043d \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u043e\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 <a href=\"https:\/\/en.wikipedia.org\/wiki\/C_dynamic_memory_allocation#Overview_of_functions\">malloc<\/a>. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u0441\u0442\u0435\u043a\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0442\u044a\u0435\u043c\u043b\u0435\u043c\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0443\u0436\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a malloc, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Valgrind \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0441\u0442\u0435\u043a\u043e\u0432\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c. Sanitizers, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0435\u0449\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a \u043a\u0430\u043a\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u0441\u0442\u0435\u043a\u0435 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0438 \u043a\u0430\u043a\u043e\u0432\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0432 \u0441\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">$ cat >stack.c &lt;&lt;'EOF' int main(int argc, char **argv) {   int a[100];   return a[argc + 100]; } EOF $ clang<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-371160","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=371160"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371160\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}