patch 8.1.1344: Coverity complains about possibly using a NULL pointer
Problem: Coverity complains about possibly using a NULL pointer and copying
a string into a fixed size buffer.
Solution: Check for NULL, even though it should not happen. Use
vim_strncpy() instead of strcpy().
diff --git a/src/memline.c b/src/memline.c
index 006a8b5..8772c4a 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -1874,7 +1874,7 @@
}
}
- /* check for out-of-memory */
+ // check for out-of-memory
for (i = 0; i < num_names; ++i)
{
if (names[i] == NULL)
@@ -2101,7 +2101,7 @@
# endif
/* MSVC returns NULL for an invalid value of seconds. */
if (curtime == NULL)
- STRCPY(buf, _("(Invalid)"));
+ vim_strncpy((char_u *)buf, (char_u *)_("(Invalid)"), sizeof(buf) - 1);
else
(void)strftime(buf, sizeof(buf) - 1, "%a %b %d %H:%M:%S %Y", curtime);
#else
@@ -3374,7 +3374,8 @@
if (newline != NULL)
{
mch_memmove(newline, line, len);
- mch_memmove(newline + len, curbuf->b_ml.ml_line_ptr + oldtextlen, textproplen);
+ mch_memmove(newline + len, curbuf->b_ml.ml_line_ptr
+ + oldtextlen, textproplen);
vim_free(line);
line = newline;
len += (colnr_T)textproplen;