From cd55f91ad2075d5ebb506950dfbc4161cab22db5 Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Mon, 25 Nov 2019 12:37:14 +0000 Subject: [PATCH 1/2] Ensure enough space in attrset bindings when using both __overrides and dynamic attributes --- src/libexpr/eval.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 62812f90a..3a9b7a3c0 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -875,7 +875,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v) if (hasOverrides) { Value * vOverrides = (*v.attrs)[overrides->second.displ].value; state.forceAttrs(*vOverrides); - Bindings * newBnds = state.allocBindings(v.attrs->size() + vOverrides->attrs->size()); + Bindings * newBnds = state.allocBindings(v.attrs->capacity() + vOverrides->attrs->size()); for (auto & i : *v.attrs) newBnds->push_back(i); for (auto & i : *vOverrides->attrs) { From cdadbf770855e828a0f64d70a47db43e920ad137 Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Mon, 25 Nov 2019 13:03:54 +0000 Subject: [PATCH 2/2] Add testcase for attrset using __overrides and dynamic attrs --- tests/lang/eval-okay-attrs6.exp | 1 + tests/lang/eval-okay-attrs6.nix | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 tests/lang/eval-okay-attrs6.exp create mode 100644 tests/lang/eval-okay-attrs6.nix diff --git a/tests/lang/eval-okay-attrs6.exp b/tests/lang/eval-okay-attrs6.exp new file mode 100644 index 000000000..b46938032 --- /dev/null +++ b/tests/lang/eval-okay-attrs6.exp @@ -0,0 +1 @@ +{ __overrides = { bar = "qux"; }; bar = "qux"; foo = "bar"; } diff --git a/tests/lang/eval-okay-attrs6.nix b/tests/lang/eval-okay-attrs6.nix new file mode 100644 index 000000000..2e5c85483 --- /dev/null +++ b/tests/lang/eval-okay-attrs6.nix @@ -0,0 +1,4 @@ +rec { + "${"foo"}" = "bar"; + __overrides = { bar = "qux"; }; +}