Skip to content

Commit

Permalink
Fix bug where range variable is improperly dereferenced (hashicorp#217)
Browse files Browse the repository at this point in the history
* Fix bug where range variable is improperly dereferenced

* Add comment explaining why a value is copied
  • Loading branch information
selmanj authored Jul 19, 2017
1 parent 6c27e07 commit 8f75c1c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion google/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func expandComputeMetadata(m map[string]string) []*compute.MetadataItems {

idx := 0
for key, value := range m {
metadata[idx] = &compute.MetadataItems{Key: key, Value: &value}
// Make a copy of value as we need a ptr type; if we directly use 'value' then all items will reference the same
// memory address
vtmp := value
metadata[idx] = &compute.MetadataItems{Key: key, Value: &vtmp}
idx++
}

Expand Down

0 comments on commit 8f75c1c

Please sign in to comment.