{"id":348565,"date":"2023-06-09T09:03:04","date_gmt":"2023-06-09T09:03:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=348565"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=348565","title":{"rendered":"<span>60 \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u0434\u043b\u044f \u0421++ \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430, \u0447\u0430\u0441\u0442\u044c 3 (\u0441\u043e\u0432\u0435\u0442 11 \u2014 15)<\/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-1\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/457\/ad5\/eb8\/457ad5eb8f8e1ce3827982d55080a3d8.png\" alt=\"1053_60_cpp_antipatterns_ru\/image2.png\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u0430\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0432\u0440\u0435\u0434\u043d\u044b\u0445 \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u0434\u043b\u044f C++ \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0430\u0441\u044c \u0432 \u0446\u0435\u043b\u0443\u044e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u0443\u044e \u043a\u043d\u0438\u0433\u0443. \u0412\u0441\u0435\u0433\u043e \u0438\u0445 60, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0435\u043c\u0443 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c. \u0412\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u0432 \u0448\u0443\u0442\u043a\u0443, \u0438 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e. \u041a\u0430\u043a \u0431\u044b \u0433\u043b\u0443\u043f\u043e \u043d\u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0441\u044f \u0432\u0440\u0435\u0434\u043d\u044b\u0439 \u0441\u043e\u0432\u0435\u0442, \u043e\u043d \u043d\u0435 \u0432\u044b\u0434\u0443\u043c\u0430\u043d, \u0430 \u043f\u043e\u0434\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u0438\u0440\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. <\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u042f \u0431\u0443\u0434\u0443 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e 5 \u0448\u0442\u0443\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0442\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u0441, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0438\u043d\u0438-\u043a\u043d\u0438\u0433\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043e\u0442\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0432\u0438\u0434\u0435\u043e \u0438 \u0442. \u0434. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u0442\u0435\u0440\u043f\u0438\u0442\u0441\u044f, \u0437\u0434\u0435\u0441\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0435\u0451 \u043f\u043e\u043b\u043d\u043e\u043c\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443: &quot;<a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/1053\/\">60 \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u0434\u043b\u044f \u0421++ \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430<\/a>&quot;. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0436\u0435\u043b\u0430\u044e \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h2 id=\"vrednyy-sovet-n11-vo-vsyom-vinovat-kompilyator\">\u0412\u0440\u0435\u0434\u043d\u044b\u0439 \u0441\u043e\u0432\u0435\u0442 N11. \u0412\u043e \u0432\u0441\u0451\u043c \u0432\u0438\u043d\u043e\u0432\u0430\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440<\/h2>\n<p>  <\/p>\n<p><strong>\u0415\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u043e, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0433\u043b\u044e\u0447\u0438\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0434\u0430.<\/strong><\/p>\n<p>  <\/p>\n<p>\u041b\u044e\u0431\u043e\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u0432\u0448\u0438\u0439\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u043e\u0432\u0435\u0442 \u0430\u0431\u0441\u0443\u0440\u0434\u0435\u043d. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043d\u0435 \u0442\u0430\u043a \u0440\u0435\u0434\u043a\u0430 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0441\u043f\u0435\u0448\u0438\u0442 \u043e\u0431\u0432\u0438\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430\u0445 \u0442\u043e\u0436\u0435 \u0431\u044b\u0432\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0438 \u0441 \u043d\u0438\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 99 % \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u043a\u0442\u043e-\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e &quot;\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u043b\u044e\u0447\u0438\u0442&quot;, \u043e\u043d \u043d\u0435\u043f\u0440\u0430\u0432 \u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0435\u043d \u0438\u043c\u0435\u043d\u043d\u043e \u0435\u0433\u043e \u043a\u043e\u0434.<\/p>\n<p>  <\/p>\n<p>\u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0438\u043b\u0438 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438 \u044f\u0437\u044b\u043a\u0430 C++, \u0438\u043b\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0430\u0440\u0443 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0435\u0440\u0432\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f<\/strong> \u0431\u0435\u0440\u0451\u0442 \u0441\u0432\u043e\u0451 \u043d\u0430\u0447\u0430\u043b\u043e \u0438\u0437 <a href=\"https:\/\/www.linux.org.ru\/forum\/development\/14422428\">\u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f<\/a>, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0432\u0448\u0435\u0433\u043e \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0435 linux.org.ru.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0436\u0430\u043b\u043e\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u0433\u043b\u044e\u043a \u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0435 GCC 8, \u043d\u043e, \u043a\u0430\u043a \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0432\u0438\u043d\u043e\u0439 \u0432\u0441\u0435\u043c\u0443 \u044f\u0432\u043b\u044f\u043b\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u043a\u043e\u0434, \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0438\u0439 \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435. \u0412 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <em>s<\/em> \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f <em>const char *s<\/em>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0430 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0430\u0432\u0442\u043e\u0440\u0430 \u0442\u0438\u043f <em>char<\/em> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u0437\u043d\u0430\u043a\u043e\u0432\u044b\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u044f \u0441\u0440\u0430\u0437\u0443 \u0432 \u043a\u043e\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0442\u0438\u043f\u0430 <em>const unsigned char *<\/em>.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">int foo(const unsigned char *s) {   int r = 0;   while(*s) {     r += ((r * 20891 + *s *200) | *s ^ 4 | *s ^ 3) ^ (r &gt;&gt; 1);     s++;   }   return r &amp; 0x7fffffff; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e\u0433\u043e \u0418 (&amp;). \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0445\u043e\u0442\u044f \u043f\u043e \u0437\u0430\u0434\u0443\u043c\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u044d\u0442\u043e \u0433\u043b\u044e\u043a \u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0435. \u041d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u043f\u0440\u0430\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0438\u0434\u0438\u0442, \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>r<\/em> \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0443\u043c\u043c\u0430. \u041f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>r<\/em> \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e (\u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430). \u0418\u043d\u0430\u0447\u0435 \u044d\u0442\u043e \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c. \u0418\u0442\u0430\u043a, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>r<\/em> \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0446\u0438\u043a\u043b\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <em>r &amp; 0x7fffffff<\/em> \u0434\u043b\u044f \u0441\u0431\u0440\u043e\u0441\u0430 \u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0431\u0438\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u043d\u0435\u0439, \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>r<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043f\u043e\u0441\u043f\u0435\u0448\u0438\u043b \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440. \u041f\u043e \u043c\u043e\u0442\u0438\u0432\u0430\u043c \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0432 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0435 PVS-Studio \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u043a\u0443 <a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v1026\/\">V1026<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0434\u0435\u0444\u0435\u043a\u0442\u044b \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0445\u044d\u0448, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0435\u0437\u0437\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">int foo(const unsigned char *s) {   unsigned r = 0;   while(*s) {     r += ((r * 20891 + *s *200) | *s ^ 4 | *s ^ 3) ^ (r &gt;&gt; 1);     s++;   }   return (int)(r &amp; 0x7fffffff); }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0412\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f<\/strong> \u0431\u044b\u043b\u0430 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u043c\u043d\u043e\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 &quot;<a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0161\/\">\u0412\u043e \u0432\u0441\u0451\u043c \u0432\u0438\u043d\u043e\u0432\u0430\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440<\/a>&quot;. \u041e\u0434\u043d\u0430\u0436\u0434\u044b \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 PVS-Studio \u0432\u044b\u0434\u0430\u043b \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0430 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">TprintPrefs::TprintPrefs(IffdshowBase *Ideci,                          const TfontSettings *IfontSettings) {   memset(this, 0, sizeof(this)); \/\/ This doesn't seem to                                  \/\/ help after optimization.   dx = dy = 0;   isOSD = false;   xpos = ypos = 0;   align = 0;   linespacing = 0;   sizeDx = 0;   sizeDy = 0;   ... }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u0430\u0432. \u0410 \u0430\u0432\u0442\u043e\u0440 \u043a\u043e\u0434\u0430 \u2013 \u043d\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043d\u0430\u043c: \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u043b\u044e\u0447\u0438\u0442 \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043d\u0435 \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0440\u0443\u0433\u0430\u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043f\u0438\u0448\u0435\u0442 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u043b\u0435\u043d \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u0435\u0447\u0430\u043b\u044c\u043d\u043e, \u043d\u043e, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u0432 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u0432\u043e\u0442\u0435. \u0410 \u0432\u0435\u0434\u044c \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u043e\u0431\u044b\u043a\u043d\u043e\u0432\u0435\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437-\u0437\u0430 \u043d\u0435\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u0440\u0435\u0442\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>memset<\/em>. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em>sizeof<\/em> \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430. \u0412 \u0440\u0435\u0436\u0438\u043c\u0435 \u0431\u0435\u0437 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439, \u0432\u0438\u0434\u0438\u043c\u043e, \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b\u0438 \u043e\u0431\u043d\u0443\u043b\u0435\u043d\u044b \u0438 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>memset<\/em> \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">memset(this, 0, sizeof(*this));<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u0434\u0430\u0436\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043a\u043e\u0434\u0430 \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c. \u041e\u043d \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/named_req\/TriviallyCopyable\">\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u0439<\/a>. \u0412\u0441\u0451 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u043e\u043c\u0430\u0442\u044c\u0441\u044f, \u0441\u0442\u043e\u0438\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441 \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u043f\u043e\u043b\u0435 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435 \u043d\u0430\u0434\u043e \u0442\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c. \u042f \u043f\u0440\u0438\u0432\u0451\u043b \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u044d\u0442\u0438 \u043d\u044e\u0430\u043d\u0441\u044b \u043c\u0435\u0440\u043a\u043d\u0443\u0442 \u043f\u0435\u0440\u0435\u0434 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0438 \u0440\u043e\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u043b\u0435\u0433\u0435\u043d\u0434\u044b \u043e \u0433\u043b\u044e\u0447\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430\u0445 \u0438 \u043e\u0442\u0432\u0430\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441 \u043d\u0438\u043c\u0438 \u0441\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u044b\u0432\u043e\u0434.<\/strong> \u041d\u0435 \u0442\u043e\u0440\u043e\u043f\u0438\u0442\u0435\u0441\u044c \u043e\u0431\u0432\u0438\u043d\u044f\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432 \u043d\u0435\u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u0418 \u0443\u0436\u0435 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043d\u0435 \u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u043c\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435 &quot;\u043e\u0431\u043e\u0439\u0442\u0438 \u0431\u0430\u0433 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430&quot;.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043f\u043e\u043b\u0435\u0437\u043d\u043e:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u0433 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043e\u0431\u0437\u043e\u0440 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430;<\/li>\n<li>\u0412\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043d\u0435 \u0432\u044b\u0434\u0430\u0451\u0442 \u043b\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0430 \u0432\u0430\u0448 \u043a\u043e\u0434 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f, \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043a\u043b\u044e\u0447\u0438, \u043a\u0430\u043a <em>-Wall<\/em>, <em>-pedantic<\/em>;<\/li>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a PVS-Studio;<\/li>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u0434 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c;<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440, \u0442\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0434\u043b\u044f \u043a\u043e\u0434\u0430, \u0438 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d \u043c\u043e\u0433 \u0442\u0430\u043a\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f;<\/li>\n<li>\u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432 \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u043c \u043a\u043e\u0434\u0435 \u0438 \u0437\u0430\u0434\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 <a href=\"https:\/\/stackoverflow.com\/\">Stack Overflow<\/a>.<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"vrednyy-sovet-n12-budte-smelymi-s-argv\">\u0412\u0440\u0435\u0434\u043d\u044b\u0439 \u0441\u043e\u0432\u0435\u0442 N12. \u0411\u0443\u0434\u044c\u0442\u0435 \u0441\u043c\u0435\u043b\u044b\u043c\u0438 \u0441 argv<\/h2>\n<p>  <\/p>\n<p><strong>\u041d\u0435 \u043c\u0435\u0448\u043a\u0430\u0439\u0442\u0435 \u0438 \u043d\u0435 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u0435. \u0421\u0440\u0430\u0437\u0443 \u0431\u0435\u0440\u0438\u0442\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a: char buf[100]; strcpy(buf, argv[1]);. \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043d\u043e\u0438\u043a\u0438, \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u0435\u0431\u0435 \u0438 \u043b\u044e\u0434\u044f\u0445.<\/strong><\/p>\n<p>  <\/p>\n<p>\u0414\u0435\u043b\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0431\u0443\u0444\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0437 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u044f\u0449\u0438\u043a \u041f\u0430\u043d\u0434\u043e\u0440\u044b, \u043f\u043e\u043b\u043d\u044b\u0439 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u2013 \u044d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0442\u0435\u043c\u0430, \u0432\u044b\u0445\u043e\u0434\u044f\u0449\u0430\u044f \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0439, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e:<\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0599\/\">\u0421\u0442\u0440\u0435\u043b\u044f\u0435\u043c \u0432 \u043d\u043e\u0433\u0443, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/a>;<\/li>\n<li><a href=\"https:\/\/cwe.mitre.org\/data\/definitions\/20.html\">CWE-20<\/a>: Improper Input Validation;<\/li>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/terms\/6496\/\">Taint-\u0430\u043d\u0430\u043b\u0438\u0437<\/a> (taint checking);<\/li>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v1010\/\">V1010<\/a>. Unchecked tainted data is used in expression.<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"vrednyy-sovet-n13-undefined-behavior--prosto-strashilka\">\u0412\u0440\u0435\u0434\u043d\u044b\u0439 \u0441\u043e\u0432\u0435\u0442 N13. Undefined behavior \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0440\u0430\u0448\u0438\u043b\u043a\u0430<\/h2>\n<p>  <\/p>\n<p><strong>Undefined behavior \u2013 \u044d\u0442\u043e \u0441\u0442\u0440\u0430\u0448\u0438\u043b\u043a\u0430 \u043d\u0430 \u043d\u043e\u0447\u044c \u0434\u043b\u044f \u0434\u0435\u0442\u0435\u0439. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0435\u0433\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u0432\u044b \u043e\u0436\u0438\u0434\u0430\u043b\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u043e\u043d\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f. \u0418 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u043d\u0435\u0447\u0435\u0433\u043e, \u0442\u043e\u0447\u043a\u0430. Everything is fine.<\/strong><\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1f4\/7a1\/74f\/1f47a174f021a8116c02be565f3e16b9.png\" alt=\"1053_60_cpp_antipatterns_ru\/image9.png\"><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0439\u0442\u0435\u0441\u044c! \ud83d\ude42<\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9D%D0%B5%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D1%91%D0%BD%D0%BD%D0%BE%D0%B5_%D0%BF%D0%BE%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5\">\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/a>.<\/li>\n<li>\u0427\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043d\u0430 C \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c \u043e\u0431 Undefined Behavior. <a href=\"https:\/\/habr.com\/ru\/articles\/341048\/\">\u0427\u0430\u0441\u0442\u044c 1<\/a>, <a href=\"https:\/\/habr.com\/ru\/articles\/341144\/\">\u0447\u0430\u0441\u0442\u044c 2<\/a>, <a href=\"https:\/\/habr.com\/ru\/articles\/341154\/\">\u0447\u0430\u0441\u0442\u044c 3<\/a>.<\/li>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0722\/\">\u0413\u043b\u0443\u0431\u0438\u043d\u0430 \u043a\u0440\u043e\u043b\u0438\u0447\u044c\u0435\u0439 \u043d\u043e\u0440\u044b \u0438\u043b\u0438 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e C++ \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 PVS-Studio<\/a>.<\/li>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0374\/\">Undefined behavior \u0431\u043b\u0438\u0436\u0435, \u0447\u0435\u043c \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435<\/a>.<\/li>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0883\/\">\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043f\u0440\u043e\u043d\u0435\u0441\u0451\u043d\u043d\u043e\u0435 \u0441\u043a\u0432\u043e\u0437\u044c \u0433\u043e\u0434\u0430<\/a>.<\/li>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0306\/\">\u0420\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u043d\u0438\u0435 \u043d\u0443\u043b\u0435\u0432\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e<\/a>.<\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/pvs-studio\/articles\/439502\/\">\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0430\u0432\u0434\u0430 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e<\/a>.<\/li>\n<li><a href=\"https:\/\/raphlinus.github.io\/programming\/rust\/2018\/08\/17\/undefined-behavior.html\">With Undefined Behavior, Anything is Possible<\/a>.<\/li>\n<li><a href=\"https:\/\/softwareengineering.stackexchange.com\/questions\/99692\/philosophy-behind-undefined-behavior\">Philosophy behind Undefined Behavior<\/a>.<\/li>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/0589\/\">\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u043f\u0440\u0438 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u043c \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u2014 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0438\u0434\u0435\u044f<\/a>.<\/li>\n<li><a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0917\/\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0438\u0437-\u0437\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f return<\/a>.<\/li>\n<li>YouTube. <a href=\"https:\/\/youtu.be\/AeEwxtEOgH0\">C++Now 2018: John Regehr &quot;Closing Keynote: Undefined Behavior and Compiler Optimizations&quot;<\/a>.<\/li>\n<li>YouTube. <a href=\"https:\/\/youtu.be\/zfmoxVkeJXI\">Towards optimization-safe systems: analyzing the impact of undefined behavior<\/a>.<\/li>\n<li>\u0410 \u0434\u0430\u043b\u044c\u0448\u0435 \u0432\u0432\u043e\u0434\u0438\u0442\u0435 \u0432 Google &quot;Undefined behavior&quot; \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0439\u0442\u0435 \ud83d\ude42<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"vrednyy-sovet-n14-double--double\">\u0412\u0440\u0435\u0434\u043d\u044b\u0439 \u0441\u043e\u0432\u0435\u0442 N14. double == double<\/h2>\n<p>  <\/p>\n<p><strong>\u0421\u043c\u0435\u043b\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0439\u0442\u0435 \u0447\u0438\u0441\u043b\u0430 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 ==. \u0420\u0430\u0437 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u0437\u043d\u0430\u0447\u0438\u0442 \u0438\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/strong><\/p>\n<p>  <\/p>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c-\u0442\u043e \u043c\u043e\u0436\u043d\u043e\u2026 \u0412\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">double A = 0.5; if (A == 0.5)               \/\/ True   foo();  double B = sin(M_PI \/ 6.0); if (B == 0.5)               \/\/ ????   foo();<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 <em>A == 0.5<\/em> \u0438\u0441\u0442\u0438\u043d\u043d\u043e. \u0412\u0442\u043e\u0440\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 <em>B == 0.5<\/em> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u0438\u0441\u0442\u0438\u043d\u043d\u043e, \u0442\u0430\u043a \u0438 \u043b\u043e\u0436\u043d\u043e. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f <em>B == 0.5<\/em> \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u0432\u0435\u0440\u0441\u0438\u0438 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u044f \u043f\u0438\u0448\u0443 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u043c\u043e\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u043e\u0437\u0434\u0430\u043b \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>B,<\/em> \u0440\u0430\u0432\u043d\u043e\u0435 0.49999999999999994.<\/p>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">double b = sin(M_PI \/ 6.0); if (std::abs(b - 0.5) &lt; DBL_EPSILON)   foo();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c\u044e <em>DBL_EPSILON<\/em> \u0432\u0435\u0440\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>sin<\/em> \u043b\u0435\u0436\u0438\u0442 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [-1, 1]. <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/types\/climits\">C numeric limits interface<\/a>:<\/p>\n<p>  <\/p>\n<blockquote><p>DBL_EPSILON \u2014 difference between 1.0 and the next representable value for <em>double<\/em> respectively.<\/p><\/blockquote>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0435\u0434\u0438\u043d\u0438\u0446, \u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u043a <em>FLT_EPSILON<\/em>, <em>DBL_EPSILON,<\/em> \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u044b. \u0418 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0442\u0438\u043f\u0430 0.00001 \u044d\u0442\u0438 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0435\u043b\u0438\u043a\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c, \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u0443\u044e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441. \u041a\u0430\u043a \u0436\u0435 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 <em>double<\/em>?<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">double a = ...; double b = ...; if (a == b) \/\/ how? { }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u043e\u0433\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435\u0442. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 <em>double<\/em>, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">if (std::abs(a - b) &lt;= DBL_EPSILON * std::max(std::abs(a),                                               std::abs(b))) { }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u0435\u0439 \u0441 \u044d\u0442\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u043e\u0439, \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u0447\u0438\u0441\u0435\u043b \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0437\u043d\u0430\u043a\u043e\u043c. \u0422\u0430\u043a\u0436\u0435 \u0432 \u0440\u044f\u0434\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043d\u0430\u0431\u0435\u0433\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430, \u0438 \u0443 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b <em>DBL_EPSILON<\/em> \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p><strong>\u0410 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0442\u043e\u0447\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439?<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0434\u0430. \u041d\u043e \u044d\u0442\u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0432\u0435\u0441\u044c\u043c\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b. \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c, \u043f\u043e \u0441\u0443\u0442\u0438, \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e \u0442\u043e\u0447\u043d\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">\/\/ -1 - \u043f\u0440\u0438\u0437\u043d\u0430\u043a, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043d\u0435 \u0431\u044b\u043b\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e double val = -1.0; if (Foo1())   val = 123.0; if (val == -1.0) \/\/ OK { }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <em>-1<\/em> \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0440\u0430\u043d\u0435\u0435.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0434\u0440\u043e\u0431\u044c\u044e. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 <a href=\"https:\/\/godbolt.org\/z\/nj9TnWbYT\">\u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442<\/a> &quot;V == 1.0\/3.0&quot;:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">double V = 1.0\/3.0; if (V == 1.0\/3.0) {   std::cout &lt;&lt; &quot;V == 1.0\/3.0&quot; &lt;&lt; std::endl; } else {   std::cout &lt;&lt; &quot;V != 1.0\/3.0&quot; &lt;&lt; std::endl; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u0434\u043e \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0431\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>V<\/em> \u043d\u0430 <em>float<\/em> \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 <a href=\"https:\/\/godbolt.org\/z\/83zfMr5MK\">\u043b\u043e\u0436\u043d\u044b\u043c<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">float V = 1.0\/3.0; if (V == 1.0\/3.0) {   std::cout &lt;&lt; &quot;V == 1.0\/3.0&quot; &lt;&lt; std::endl; } else {   std::cout &lt;&lt; &quot;V != 1.0\/3.0&quot; &lt;&lt; std::endl; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0443\u0436\u0435 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 &quot;V != 1.0\/3.0&quot;. \u041f\u043e\u0447\u0435\u043c\u0443? \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>V<\/em> \u0440\u0430\u0432\u043d\u043e 0.333333, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <em>1.0\/3.0<\/em> \u0440\u0430\u0432\u043d\u043e 0.333333333333333. \u041f\u0435\u0440\u0435\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <em>V<\/em>, \u0438\u043c\u0435\u044e\u0449\u0430\u044f \u0442\u0438\u043f <em>float,<\/em> \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0438\u043f\u0430 <em>double<\/em>. \u041f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">if (0.333333000000000 == 0.333333333333333)<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0438 \u0447\u0438\u0441\u043b\u0430 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0435 \u0440\u0430\u0432\u043d\u044b. \u0412 \u043e\u0431\u0449\u0435\u043c, \u0431\u0443\u0434\u044c\u0442\u0435 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b. <\/p>\n<p>  <\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 PVS-Studio \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <em>==<\/em> \u0438 <em>!=<\/em>, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u043d\u0434\u044b \u0438\u043c\u0435\u044e\u0442 \u0442\u0438\u043f \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0435\u0449\u0451 \u0440\u0430\u0437 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434. \u0421\u043c. \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u043a\u0443 <a href=\"https:\/\/pvs-studio.ru\/ru\/docs\/warnings\/v550\/\">V550 \u2014 Suspicious precise comparison<\/a>.<\/p>\n<p>  <\/p>\n<p><strong>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b:<\/strong><\/p>\n<p>  <\/p>\n<ol>\n<li>Bruce Dawson. <a href=\"https:\/\/randomascii.wordpress.com\/2012\/02\/25\/comparing-floating-point-numbers-2012-edition\/\">Comparing floating point numbers, 2012 Edition<\/a>. <\/li>\n<li>RSDN. <a href=\"http:\/\/rsdn.org\/forum\/cpp\/2640596.1\">\u041f\u0440\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 double (RU).<\/a> <\/li>\n<li>\u0410\u043d\u0434\u0440\u0435\u0439 \u041a\u0430\u0440\u043f\u043e\u0432. <a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/0074\/\">64-\u0431\u0438\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439<\/a>.<\/li>\n<li>Wikipedia. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Floating_point\">Floating point<\/a>.<\/li>\n<li>CodeGuru Forums. <a href=\"https:\/\/forums.codeguru.com\/showthread.php?323835-c-general-how-is-floating-point-representated\">C++ General: How is floating point representated?<\/a><\/li>\n<li>Boost. <a href=\"https:\/\/www.boost.org\/doc\/libs\/1_34_0\/libs\/test\/doc\/components\/test_tools\/floating_point_comparison.html\">Floating-point comparison algorithms<\/a>.<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"vrednyy-sovet-n15-memmove--lishnyaya-funkciya\">\u0412\u0440\u0435\u0434\u043d\u044b\u0439 \u0441\u043e\u0432\u0435\u0442 N15. memmove \u2014 \u043b\u0438\u0448\u043d\u044f\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/h2>\n<p>  <\/p>\n<p><strong>memmove \u2014 \u043b\u0438\u0448\u043d\u044f\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u0412\u0441\u0435\u0433\u0434\u0430 \u0438 \u0432\u0435\u0437\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 memcpy.<\/strong><\/p>\n<p>  <\/p>\n<p>\u0420\u043e\u043b\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430. \u041d\u043e \u0435\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435: \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f, <em><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/byte\/memmove\">memmove<\/a><\/em> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 <em><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/byte\/memcpy\">memcpy<\/a><\/em> \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9da\/7cc\/815\/9da7cc8150c6c310453516d365306d6c.png\" alt=\"1053_60_cpp_antipatterns_ru\/image10.png\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c \u043f\u044f\u0442\u044c \u0431\u0430\u0439\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0442\u0440\u0438 \u0431\u0430\u0439\u0442\u0430, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435. \u0422\u043e\u0433\u0434\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li><strong>memmove<\/strong> \u2013 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e;<\/li>\n<li><strong>memcpy<\/strong> \u2013 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u0431\u0430\u0439\u0442\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0438 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0430 \u0431\u0430\u0439\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435, \u0447\u0442\u043e \u0438 \u0434\u0432\u0430 \u043f\u0435\u0440\u0432\u044b\u0445.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0421\u043c. \u0442\u0430\u043a\u0436\u0435 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u044e \u043d\u0430 Stack Overflow: <a href=\"https:\/\/stackoverflow.com\/questions\/4415910\/memcpy-vs-memmove\/\">memcpy() vs memmove()<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u0442\u0430\u043a \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u0432\u043e\u0434\u043e\u043c \u0448\u0443\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443? \u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0430\u0432\u0442\u043e\u0440\u044b \u043c\u043d\u043e\u0433\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0435\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u0440\u043e \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0441\u043f\u0430\u0441\u0430\u043b\u043e \u0442\u043e, \u0447\u0442\u043e \u0432 \u0441\u0442\u0430\u0440\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 glibc \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>memcpy<\/em> \u0431\u044b\u043b\u0430 \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u043e\u043c <em>memmove<\/em>. \u0417\u0430\u043c\u0435\u0442\u043a\u0430 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443: <a href=\"https:\/\/lwn.net\/Articles\/414467\/\">Glibc change exposing bugs<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0410 \u0432\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u043e <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/memcpy.3.html\">\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f<\/a> \u0432 Linux manual page:<\/p>\n<p>  <\/p>\n<blockquote><p>Failure to observe the requirement that the memory areas do not overlap has been the source of significant bugs. (POSIX and the C standards are explicit that employing memcpy() with overlapping areas produces undefined behavior.) Most notably, in glibc 2.13 a performance optimization of memcpy() on some platforms (including x86-64) included changing the order in which bytes were copied from src to dest.<\/p>\n<p>  This change revealed breakages in a number of applications that performed copying with overlapping areas. Under the previous implementation, the order in which the bytes were copied had fortuitously hidden the bug, which was revealed when the copying order was reversed. In glibc 2.14, a versioned symbol was added so that old binaries (i.e., those linked against glibc versions earlier than 2.14) employed a memcpy() implementation that safely handles the overlapping buffers case (by providing an &quot;older&quot; memcpy() implementation that was aliased to memmove(3)).<\/p><\/blockquote>\n<p>  <\/p>\n<h2 id=\"ob-etoy-mini-knige\">\u041e\u0431 \u044d\u0442\u043e\u0439 \u043c\u0438\u043d\u0438-\u043a\u043d\u0438\u0433\u0435<\/h2>\n<p>  <\/p>\n<p>\u0410\u0432\u0442\u043e\u0440: \u041a\u0430\u0440\u043f\u043e\u0432 \u0410\u043d\u0434\u0440\u0435\u0439 \u041d\u0438\u043a\u043e\u043b\u0430\u0435\u0432\u0438\u0447. E-Mail: karpov [@] viva64.com.<\/p>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 15 \u043b\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043a\u043e\u0434\u0430 \u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f. \u0410\u0432\u0442\u043e\u0440 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u044b\u0445 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C++. \u0421 2011 \u043f\u043e 2021 \u0433\u043e\u0434 \u0443\u0434\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u043b\u0441\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u044b Microsoft MVP \u0432 \u043d\u043e\u043c\u0438\u043d\u0430\u0446\u0438\u0438 Developer Technologies. \u041e\u0434\u0438\u043d \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 PVS-Studio. \u0414\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u044f\u0432\u043b\u044f\u043b\u0441\u044f CTO \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0421++ \u044f\u0434\u0440\u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438, \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u0438 DevRel \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442:<\/p>\n<p>  <\/p>\n<ul>\n<li>RU \u2014 <a href=\"https:\/\/pvs-studio.ru\/ru\/blog\/posts\/cpp\/1053\/\">60 \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u0434\u043b\u044f \u0421++ \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430<\/a><\/li>\n<li>EN \u2014 <a href=\"https:\/\/pvs-studio.com\/en\/blog\/posts\/cpp\/1053\/\">60 terrible tips for a C++ developer<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p><a href=\"https:\/\/pvs-studio.ru\/ru\/subscribe\/\">\u041f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c<\/a> \u043d\u0430 \u0435\u0436\u0435\u043c\u0435\u0441\u044f\u0447\u043d\u0443\u044e \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0430\u0432\u0442\u043e\u0440\u0430 \u0438 \u0435\u0433\u043e \u043a\u043e\u043b\u043b\u0435\u0433.<\/p>\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\/companies\/pvs-studio\/articles\/740838\/\"> https:\/\/habr.com\/ru\/companies\/pvs-studio\/articles\/740838\/<\/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-1\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/457\/ad5\/eb8\/457ad5eb8f8e1ce3827982d55080a3d8.png\" alt=\"1053_60_cpp_antipatterns_ru\/image2.png\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u0430\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0432\u0440\u0435\u0434\u043d\u044b\u0445 \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u0434\u043b\u044f C++ \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0430\u0441\u044c \u0432 \u0446\u0435\u043b\u0443\u044e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u0443\u044e \u043a\u043d\u0438\u0433\u0443. \u0412\u0441\u0435\u0433\u043e \u0438\u0445 60, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0435\u043c\u0443 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c. \u0412\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u0432 \u0448\u0443\u0442\u043a\u0443, \u0438 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e. \u041a\u0430\u043a \u0431\u044b \u0433\u043b\u0443\u043f\u043e \u043d\u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0441\u044f \u0432\u0440\u0435\u0434\u043d\u044b\u0439 \u0441\u043e\u0432\u0435\u0442, \u043e\u043d \u043d\u0435 \u0432\u044b\u0434\u0443\u043c\u0430\u043d, \u0430 \u043f\u043e\u0434\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u0438\u0440\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. <\/p>\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-348565","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348565","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=348565"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348565\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}