Skip to content

Commit 3286ead

Browse files
bozaromvdan
authored andcommitted
internal/core/adt: fix nil pointer dereference
We had a nil check on envYield.node, but we accessed a node field right before that nil check for apparently no good reason. Fixes #2550. Closes #2551 as merged as of commit f2dc179. Signed-off-by: Artem V. Navrotskiy <[email protected]> Change-Id: I0206d02d8c32ee82bc71e0c9b686965ed4f41399 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1167596 Reviewed-by: Paul Jolly <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent a1038f7 commit 3286ead

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

cue/testdata/eval/issue2550.txtar

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- in.cue --
2+
foo: string
3+
bar: close({})
4+
5+
if bar.missing == "x" {
6+
let _bar = bar
7+
foo: _bar
8+
}
9+
-- out/compile --
10+
--- in.cue
11+
{
12+
foo: string
13+
bar: close({})
14+
if (〈0;bar〉.missing == "x") {
15+
let _bar#1 = 〈1;bar〉
16+
foo: 〈0;let _bar#1〉
17+
}
18+
}
19+
-- out/eval/stats --
20+
Leaks: 1
21+
Freed: 4
22+
Reused: 1
23+
Allocs: 4
24+
Retain: 5
25+
26+
Unifications: 5
27+
Conjuncts: 5
28+
Disjuncts: 9
29+
-- out/eval --
30+
(_|_){
31+
// [incomplete] undefined field: missing:
32+
// ./in.cue:4:8
33+
foo: (_|_){
34+
// [incomplete] undefined field: missing:
35+
// ./in.cue:4:8
36+
}
37+
bar: (#struct){
38+
}
39+
let _bar#1 = (_){ _ }
40+
}

internal/core/adt/comprehension.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ func (n *nodeContext) processComprehension(d *envYield, state vertexStatus) *Bot
397397
}
398398

399399
// continue to collect other errors.
400-
d.node.state.addBottom(err)
401400
d.done = true
402401
d.inserted = true
403402
if d.node != nil {
403+
d.node.state.addBottom(err)
404404
ctx.PopArc(d.node)
405405
}
406406
return nil

0 commit comments

Comments
 (0)