Skip to content

Commit 33ea956

Browse files
committed
Fix panic for Value.As(**big.Float).
*big.Float is a pointer type that will never really appear as anything except a pointer. So when using code like this: ```go var foo *big.Float err := value.As(&foo) ``` the target of `As` is actually a **big.Float. But our code dereferences it and calls `As` on the target of the pointer, but the target of the pointer is actually a nil pointer. This code fixes that by instantiating a new value for the pointer to point to, setting the pointer to that, and then calling `As` on the new value.
1 parent 26c9b68 commit 33ea956

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

tftypes/value.go

+3
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ func (val Value) As(dst interface{}) error {
432432
*target = nil
433433
return nil
434434
}
435+
if *target == nil {
436+
*target = big.NewFloat(0)
437+
}
435438
return val.As(*target)
436439
case *bool:
437440
if val.IsNull() {

tftypes/value_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func TestValueAs(t *testing.T) {
9393
as: numberPointerPointer(big.NewFloat(0)),
9494
expected: numberPointerPointer(big.NewFloat(123)),
9595
},
96+
"uninstantiated-number-pointer": {
97+
in: NewValue(Number, big.NewFloat(123)),
98+
as: numberPointerPointer(nil),
99+
expected: numberPointerPointer(big.NewFloat(123)),
100+
},
96101
"number-pointer-null": {
97102
in: NewValue(Number, nil),
98103
as: numberPointerPointer(big.NewFloat(123)),

0 commit comments

Comments
 (0)