Workaround 'potential non-terminated string' false positive in cordbscs
authorIvan Maidanski <ivmai@mail.ru>
Mon, 12 Nov 2018 08:12:09 +0000 (11:12 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 12 Nov 2018 17:45:19 +0000 (20:45 +0300)
* cordbscs.c [LINT2] (CORD_cat_char_star): Pass lenx+1 to memcpy()
instead of lenx; add comment.

cord/cordbscs.c

index ff0d239..a92ab63 100644 (file)
@@ -170,7 +170,13 @@ CORD CORD_cat_char_star(CORD x, const char * y, size_t leny)
             char * result = (char *)GC_MALLOC_ATOMIC(result_len + 1);
 
             if (result == 0) OUT_OF_MEMORY;
-            memcpy(result, x, lenx);
+#           ifdef LINT2
+                memcpy(result, x, lenx + 1);
+#           else
+                memcpy(result, x, lenx);
+                                /* No need to copy the terminating zero */
+                                /* as result[lenx] is written below.    */
+#           endif
             memcpy(result + lenx, y, leny);
             result[result_len] = '\0';
             return((CORD) result);