{"id":411296,"date":"2024-06-29T21:53:12","date_gmt":"2024-06-29T21:53:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=411296"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=411296","title":{"rendered":"<span>\u041a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a<\/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<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/d62\/10f\/0c1\/d6210f0c1830fb71760de7026aa51b39.png\" alt=\"strlen \u0438 sizeof\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d62\/10f\/0c1\/d6210f0c1830fb71760de7026aa51b39.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0423 \u043d\u0430\u0441, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043a\u043e\u0434\u0430 PVS-Studio, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043a\u0440\u0430\u0441\u043e\u0442\u0435. \u041e \u043a\u0440\u0430\u0441\u043e\u0442\u0435 \u0431\u0430\u0433\u043e\u0432. \u041d\u0430\u043c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0437\u044f\u0449\u0435\u0441\u0442\u0432\u043e \u0432 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0438\u0445, \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0443\u0433\u0430\u0434\u0430\u0442\u044c, \u043a\u0430\u043a \u043e\u043d\u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c. \u0421\u0435\u0439\u0447\u0430\u0441 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043a\u043e\u0434\u0435 \u0441\u043f\u0443\u0442\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"oshibka-iz-proekta-lfortran\">\u041e\u0448\u0438\u0431\u043a\u0430 \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 LFortran<\/h2>\n<p>  <\/p>\n<p>\u0423\u0441\u043b\u044b\u0448\u0430\u0432 \u043e \u0432\u044b\u0445\u043e\u0434\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e <a href=\"https:\/\/cppcast.com\/lfortran\/\">CppCast \u043d\u0430 \u0442\u0435\u043c\u0443 LFortran<\/a>, \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 LFortran. \u041f\u0440\u043e\u0435\u043a\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0437\u043d\u0430\u0435\u043c, \u043d\u0430\u0431\u0435\u0440\u0435\u0442\u0441\u044f \u043b\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0434\u043b\u044f <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/inspections\/\">\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439<\/a> \u0441\u0442\u0430\u0442\u044c\u0438 \u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u0433\u043b\u0430\u0437\u0430 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043f\u0430\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0438. \u041d\u0430 \u043d\u0430\u0448 \u0432\u043a\u0443\u0441, \u043e\u0448\u0438\u0431\u043a\u0430 \u043e\u0447\u0435\u043d\u044c \u043c\u0438\u043b\u0430\u044f.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 LFortran \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 (\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f) \u0434\u0432\u0443\u0445 \u0441\u0442\u0440\u043e\u043a \u0432 \u043d\u043e\u0432\u043e\u043c \u0431\u0443\u0444\u0435\u0440\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void _lfortran_strcat(char** s1, char** s2, char** dest) {     int cntr = 0;     char trmn = '\\0';     int s1_len = strlen(*s1);     int s2_len = strlen(*s2);     int trmn_size = strlen(&amp;trmn);     char* dest_char = (char*)malloc(s1_len+s2_len+trmn_size);     for (int i = 0; i &lt; s1_len; i++) {         dest_char[cntr] = (*s1)[i];         cntr++;     }     for (int i = 0; i &lt; s2_len; i++) {         dest_char[cntr] = (*s2)[i];         cntr++;     }     dest_char[cntr] = trmn;     *dest = &amp;(dest_char[0]); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0430\u043c\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0439\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0443. \u0427\u0442\u043e\u0431\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435, \u0432\u0441\u0442\u0430\u0432\u043b\u044e \u0434\u043b\u0438\u043d\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 :). \u0415\u0441\u0442\u044c \u043c\u0435\u043c &#171;\u0434\u043b\u0438\u043d\u043d\u043e\u043a\u043e\u0442&#187;. \u0410 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 &#171;\u0434\u043b\u0438\u043d\u043d\u043e\u0435\u0434\u0438\u043d\u043e\u0440\u043e\u0433&#187; :).<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/e01\/b24\/3ed\/e01b243ed1238f072076f98b14dca3eb.png\" alt=\"\u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0435\u0434\u0438\u043d\u043e\u0440\u043e\u0433\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e01\/b24\/3ed\/e01b243ed1238f072076f98b14dca3eb.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0433\u043e \u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043e\u0431\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/terms\/0088\/\">\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u043e\u043b\u044c<\/a>. \u0412\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0443\u0444\u0435\u0440, \u0432 \u043d\u0435\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u043e\u043b\u044c. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0443\u0444\u0435\u0440 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430. \u0415\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0430 1 \u0431\u0430\u0439\u0442 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u043e\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0443\u0436\u0435 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u043f\u0438\u0441\u0430\u0432\u0448\u0438\u0439 \u043a\u043e\u0434, \u0443\u0432\u043b\u0451\u043a\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>strlen<\/em> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0435\u0451 \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0443\u043b\u044f. \u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0443\u043b\u044f) \u0438 \u0434\u043b\u0438\u043d\u043e\u0439 \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u042d\u0442\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u0438 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434. \u041d\u043e \u043d\u0430 \u043d\u0430\u0448 \u0432\u0437\u0433\u043b\u044f\u0434, \u044d\u0442\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">char trmn = '\\0'; int trmn_size = strlen(&amp;trmn);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0438\u043c\u0432\u043e\u043b <em>trmn<\/em> \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430. \u0415\u0451 \u0434\u043b\u0438\u043d\u0430 \u043d\u0443\u043b\u0435\u0432\u0430\u044f. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <em>trmn_size<\/em>, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0443\u043b\u044f, \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u0430 0.<\/p>\n<p>  <\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0430 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <em>sizeof<\/em>, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0439\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void _lfortran_strcat(char** s1, char** s2, char** dest) {     int cntr = 0;     char trmn = '\\0';     int s1_len = strlen(*s1);     int s2_len = strlen(*s2);      int trmn_size = sizeof(trmn);  \/\/ &lt;=      char* dest_char = (char*)malloc(s1_len+s2_len+trmn_size);     for (int i = 0; i &lt; s1_len; i++) {         dest_char[cntr] = (*s1)[i];         cntr++;     }     for (int i = 0; i &lt; s2_len; i++) {         dest_char[cntr] = (*s2)[i];         cntr++;     }     dest_char[cntr] = trmn;     *dest = &amp;(dest_char[0]); }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"obnaruzhenie-oshibki\">\u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/h2>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u043e\u0448\u0438\u0431\u043a\u0430 \u0431\u044b\u043b\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043a\u043e\u0434\u0430 <a href=\"https:\/\/pvs-studio.com\/ru\/pvs-studio\/\">PVS-Studio<\/a>. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043e\u043d \u043d\u0435 \u0441\u043c\u043e\u0433 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0430\u043a \u0432\u044b\u0445\u043e\u0434 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u042d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e. \u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0441\u043c\u043e\u0433 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043a\u0430\u043a \u0441\u0432\u044f\u0437\u0430\u043d \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 <em>dest_char<\/em> \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>cntr<\/em>, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0430\u0445. \u041e\u0448\u0438\u0431\u043a\u0430 \u0431\u044b\u043b\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0430 \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c.<\/p>\n<p>  <\/p>\n<p>PVS-Studio \u0432\u044b\u0434\u0430\u043b \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435: <a href=\"https:\/\/pvs-studio.com\/ru\/docs\/warnings\/v742\/\">V742<\/a> [CWE-170, CERT-EXP37-C] Function receives an address of a &#8216;char&#8217; type variable instead of pointer to a buffer. Inspect the first argument. lfortran_intrinsics.c 550<\/p>\n<p>  <\/p>\n<p>\u041e\u0447\u0435\u043d\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>strlen<\/em>, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0435\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b. \u0418 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043d\u0430\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u043c \u0431\u0430\u0433\u043e\u043c. \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u2014 \u044d\u0442\u043e \u043a\u0440\u0443\u0442\u043e!<\/p>\n<p>  <\/p>\n<h2 id=\"prodolzhaem-uluchshat-kod\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c \u043a\u043e\u0434<\/h2>\n<p>  <\/p>\n<p>\u0412\u044b\u0448\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0430\u043a \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u043a\u043e\u0434\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0443 \u043a\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440. \u0418 \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0443 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>malloc<\/em>. <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/posts\/cpp\/0558\/\">\u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e<\/a>. \u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435: V522 [CWE-690, CERT-MEM52-CPP] There might be dereferencing of a potential null pointer &#8216;dest_char&#8217;. Check lines: 553, 551. lfortran_intrinsics.c 553<\/p>\n<p>  <\/p>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0451\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 \u043d\u0430 \u0442\u0435\u043c\u0443 <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/terms\/0002\/\">64-\u0431\u0438\u0442\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a<\/a>. \u041a\u043e\u0434 \u043d\u0435 \u0433\u043e\u0442\u043e\u0432 \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438, \u0434\u043b\u0438\u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 <em>INT_MAX<\/em> \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u044d\u043a\u0437\u043e\u0442\u0438\u043a\u0430, \u043d\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435\u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0430\u0441\u043d\u043e. \u041b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f <em>size_t<\/em> \u0432\u043c\u0435\u0441\u0442\u043e <em>int<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void _lfortran_strcat(const char** s1, const char** s2, char** dest) {     if (s1 == NULL || *s1 == NULL ||         s2 == NULL || *s2 == NULL || dest == NULL)     {       \/\/ \u041a\u0430\u043a\u0430\u044f-\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043a\u0438, \u0443\u043c\u0435\u0441\u0442\u043d\u0430\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.       ....     }     size_t cntr = 0;     const char trmn = '\\0';     const size_t s1_len = strlen(*s1);     const size_t s2_len = strlen(*s2);     char* dest_char = (char*)malloc((s1_len+s2_len+1)*sizeof(char));     if (dest_char == NULL)     {       \/\/ \u041a\u0430\u043a\u0430\u044f-\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043a\u0438, \u0443\u043c\u0435\u0441\u0442\u043d\u0430\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.       ....     }      for (size_t i = 0; i &lt; s1_len; i++) {         dest_char[cntr] = (*s1)[i];         cntr++;     }     for (size_t i = 0; i &lt; s2_len; i++) {         dest_char[cntr] = (*s2)[i];         cntr++;     }     dest_char[cntr] = trmn;     *dest = dest_char; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u043e\u043d \u0441\u0442\u0430\u043b \u044f\u0432\u043d\u043e \u043b\u0443\u0447\u0448\u0435. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u0418 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0435 <a href=\"https:\/\/pvs-studio.com\/ru\/pvs-studio-download\/?promo=pvs_ak\">\u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c PVS-Studio<\/a> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<h2 id=\"dopolnitelnye-ssylki\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/pvs-studio.com\/ru\/blog\/posts\/cpp\/0723\/\">\u041d\u0430\u0447\u0430\u043b\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a>.<\/li>\n<li><a href=\"https:\/\/pvs-studio.com\/ru\/blog\/posts\/cpp\/0824\/\">\u0422\u0435\u043f\u0435\u0440\u044c PVS-Studio \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u0430 \u0437\u0432\u0435\u0440\u044c \u0442\u0430\u043a\u043e\u0439 \u2013 strlen<\/a>.<\/li>\n<li><a href=\"https:\/\/pvs-studio.com\/ru\/blog\/lessons\/full\/\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 64-\u0431\u0438\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/a>.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u0441 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0435\u0439, \u0442\u043e \u043f\u0440\u043e\u0448\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434: Andrey Karpov. <a href=\"https:\/\/habr.com\/en\/company\/pvs-studio\/blog\/569010\/\">A Beautiful Error in the Implementation of the String Concatenation Function<\/a>.<\/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\/569012\/\"> https:\/\/habr.com\/ru\/articles\/569012\/<\/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<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/d62\/10f\/0c1\/d6210f0c1830fb71760de7026aa51b39.png\" alt=\"strlen \u0438 sizeof\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d62\/10f\/0c1\/d6210f0c1830fb71760de7026aa51b39.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0423 \u043d\u0430\u0441, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043a\u043e\u0434\u0430 PVS-Studio, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043a\u0440\u0430\u0441\u043e\u0442\u0435. \u041e \u043a\u0440\u0430\u0441\u043e\u0442\u0435 \u0431\u0430\u0433\u043e\u0432. \u041d\u0430\u043c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0437\u044f\u0449\u0435\u0441\u0442\u0432\u043e \u0432 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0438\u0445, \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0443\u0433\u0430\u0434\u0430\u0442\u044c, \u043a\u0430\u043a \u043e\u043d\u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c. \u0421\u0435\u0439\u0447\u0430\u0441 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043a\u043e\u0434\u0435 \u0441\u043f\u0443\u0442\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/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-411296","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/411296","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=411296"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/411296\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=411296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=411296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=411296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}