diff options
| author | Russ Cox <rsc@golang.org> | 2014-10-20 11:10:00 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2014-10-20 11:10:00 -0400 |
| commit | 3811c4d84aabc544f3431bf7fb59e9c57b183628 (patch) | |
| tree | 4a8d83a2c94c12e489cd10b5a91da40f39eeafcc /src/debug/pe | |
| parent | 0edafefc36b39dd456d3b6410f81dfcecfef6a3b (diff) | |
| download | go-3811c4d84aabc544f3431bf7fb59e9c57b183628.tar.xz | |
debug/pe: remove use of unsafe
Helps in environments with restricted support for unsafe.
LGTM=bradfitz
R=r, bradfitz
CC=dsymonds, golang-codereviews
https://golang.org/cl/156410044
Diffstat (limited to 'src/debug/pe')
| -rw-r--r-- | src/debug/pe/file.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/debug/pe/file.go b/src/debug/pe/file.go index ce6f1408fe..28a4bae113 100644 --- a/src/debug/pe/file.go +++ b/src/debug/pe/file.go @@ -13,7 +13,6 @@ import ( "io" "os" "strconv" - "unsafe" ) // A File represents an open PE file. @@ -125,6 +124,11 @@ func (f *File) Close() error { return err } +var ( + sizeofOptionalHeader32 = uintptr(binary.Size(OptionalHeader32{})) + sizeofOptionalHeader64 = uintptr(binary.Size(OptionalHeader64{})) +) + // NewFile creates a new File for accessing a PE binary in an underlying reader. func NewFile(r io.ReaderAt) (*File, error) { f := new(File) @@ -206,7 +210,7 @@ func NewFile(r io.ReaderAt) (*File, error) { var oh32 OptionalHeader32 var oh64 OptionalHeader64 switch uintptr(f.FileHeader.SizeOfOptionalHeader) { - case unsafe.Sizeof(oh32): + case sizeofOptionalHeader32: if err := binary.Read(sr, binary.LittleEndian, &oh32); err != nil { return nil, err } @@ -214,7 +218,7 @@ func NewFile(r io.ReaderAt) (*File, error) { return nil, fmt.Errorf("pe32 optional header has unexpected Magic of 0x%x", oh32.Magic) } f.OptionalHeader = &oh32 - case unsafe.Sizeof(oh64): + case sizeofOptionalHeader64: if err := binary.Read(sr, binary.LittleEndian, &oh64); err != nil { return nil, err } |
