coverity/169163: decode_string: Null pointer deref

*** CID 169163:  Null pointer dereferences  (FORWARD_NULL)
    /src/nvim/eval/decode.c: 290 in decode_string()
    284         if (elw_ret == -1) {
    285           tv_clear(&tv);
    286           return (typval_T) { .v_type = VAR_UNKNOWN, .v_lock = VAR_UNLOCKED };
    287         }
    288         return tv;
    289       } else {
    >>>     CID 169163:  Null pointer dereferences  (FORWARD_NULL)
    >>>     Passing null pointer "s" to "xmemdupz", which dereferences it. (The dereference is assumed on the basis of the 'nonnull' parameter attribute.)
    290         return (typval_T) {
    291           .v_type = VAR_STRING,
    292           .v_lock = VAR_UNLOCKED,
    293           .vval = { .v_string = (char_u *)(
    294               s_allocated ? (char *)s : xmemdupz(s, len)) },
    295         };
This commit is contained in:
Justin M. Keyes
2018-01-11 01:32:41 +01:00
parent 911b1e49ab
commit 18d244eded

View File

@@ -285,7 +285,7 @@ typval_T decode_string(const char *const s, const size_t len,
.v_type = VAR_STRING, .v_type = VAR_STRING,
.v_lock = VAR_UNLOCKED, .v_lock = VAR_UNLOCKED,
.vval = { .v_string = (char_u *)( .vval = { .v_string = (char_u *)(
s_allocated ? (char *)s : xmemdupz(s, len)) }, (s == NULL || s_allocated) ? (char *)s : xmemdupz(s, len)) },
}; };
} }
} }