Skip to content

Fix panic for Value.As(**big.Float). #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2021
Merged

Conversation

paddycarver
Copy link
Contributor

*big.Float is a pointer type that will never really appear as anything
except a pointer. So when using code like this:

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.

@paddycarver paddycarver added the bug Something isn't working label May 31, 2021
@paddycarver paddycarver requested a review from a team May 31, 2021 20:58
*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.
@paddycarver paddycarver force-pushed the paddy_fix_big_float branch from 33ea956 to 808fead Compare May 31, 2021 20:59
paddycarver added a commit to hashicorp/terraform-plugin-framework that referenced this pull request May 31, 2021
Relies on hashicorp/terraform-plugin-go#85, which fixes a bug in using
`tftypes.Value.As` to convert to a *big.Float.
@paddycarver paddycarver merged commit 1df2217 into main Jun 1, 2021
@paddycarver paddycarver deleted the paddy_fix_big_float branch June 1, 2021 16:46
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants