From 7ebcf5eac7047b1eef2443eda1786672b5c70f51 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 13 Jul 2015 10:55:49 +1000 Subject: [PATCH] syscall: warn not to use FormatMessage Fixes #11147 Change-Id: Ib31160946a53f6f9b11daea211ff04d186b51b3f Reviewed-on: https://go-review.googlesource.com/12067 Reviewed-by: Ian Lance Taylor --- src/syscall/syscall_windows.go | 14 +++++++++++--- src/syscall/zsyscall_windows.go | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index 23035ac3872..1006a9b72a6 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -82,6 +82,14 @@ type Errno uintptr func langid(pri, sub uint16) uint32 { return uint32(sub)<<10 | uint32(pri) } +// FormatMessage is deprecated (msgsrc should be uintptr, not uint32, but can +// not be changed due to the Go 1 compatibility guarantee). +// +// Deprecated: Use FormatMessage from golang.org/x/sys/windows instead. +func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) { + return formatMessage(flags, uintptr(msgsrc), msgid, langid, buf, args) +} + func (e Errno) Error() string { // deal with special go errors idx := int(e - APPLICATION_ERROR) @@ -91,9 +99,9 @@ func (e Errno) Error() string { // ask windows for the remaining errors var flags uint32 = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_IGNORE_INSERTS b := make([]uint16, 300) - n, err := FormatMessage(flags, 0, uint32(e), langid(LANG_ENGLISH, SUBLANG_ENGLISH_US), b, nil) + n, err := formatMessage(flags, 0, uint32(e), langid(LANG_ENGLISH, SUBLANG_ENGLISH_US), b, nil) if err != nil { - n, err = FormatMessage(flags, 0, uint32(e), 0, b, nil) + n, err = formatMessage(flags, 0, uint32(e), 0, b, nil) if err != nil { return "winapi error #" + itoa(int(e)) } @@ -136,7 +144,7 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys FreeLibrary(handle Handle) (err error) //sys GetProcAddress(module Handle, procname string) (proc uintptr, err error) //sys GetVersion() (ver uint32, err error) -//sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW +//sys formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW //sys ExitProcess(exitcode uint32) //sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW //sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) diff --git a/src/syscall/zsyscall_windows.go b/src/syscall/zsyscall_windows.go index ba62499f4ef..7879ba1aa5c 100644 --- a/src/syscall/zsyscall_windows.go +++ b/src/syscall/zsyscall_windows.go @@ -240,7 +240,7 @@ func GetVersion() (ver uint32, err error) { return } -func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) { +func formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) { var _p0 *uint16 if len(buf) > 0 { _p0 = &buf[0]