diff options
author | Shea Levy <shea@shealevy.com> | 2018-03-15T03·53-0400 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2018-03-15T03·53-0400 |
commit | cfdbfa6b2cc27ae5b98c5f27599bbc0fc6a104c1 (patch) | |
tree | fa0e753bcbb8091d6768b737eb6bf58897335d73 /src/libexpr | |
parent | d25d9f7cecad24e16b8e831077996e3b50c04468 (diff) |
Catch more possible instances of passing NULL to memcpy.
Actually fixes #1976.
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 6778023f506d..c88f677da085 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1601,12 +1601,16 @@ static void prim_partition(EvalState & state, const Pos & pos, Value * * args, V state.mkAttrs(v, 2); Value * vRight = state.allocAttr(v, state.sRight); - state.mkList(*vRight, right.size()); - memcpy(vRight->listElems(), right.data(), sizeof(Value *) * right.size()); + auto rsize = right.size(); + state.mkList(*vRight, rsize); + if (rsize) + memcpy(vRight->listElems(), right.data(), sizeof(Value *) * rsize); Value * vWrong = state.allocAttr(v, state.sWrong); - state.mkList(*vWrong, wrong.size()); - memcpy(vWrong->listElems(), wrong.data(), sizeof(Value *) * wrong.size()); + auto wsize = wrong.size(); + state.mkList(*vWrong, wsize); + if (wsize) + memcpy(vWrong->listElems(), wrong.data(), sizeof(Value *) * wsize); v.attrs->sort(); } |