Unsafe rules.

This commit is contained in:
Nuno Cruces 2021-09-15 13:54:35 +01:00
parent a899c69072
commit e03e9df189
3 changed files with 6 additions and 9 deletions

View File

@ -3,7 +3,6 @@ package zenity
import ( import (
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime"
"syscall" "syscall"
"unicode/utf16" "unicode/utf16"
"unsafe" "unsafe"
@ -315,9 +314,8 @@ func browseForFolder(opts options) (string, []string, error) {
args.Title = syscall.StringToUTF16Ptr(*opts.title) args.Title = syscall.StringToUTF16Ptr(*opts.title)
} }
if opts.filename != "" { if opts.filename != "" {
args.LParam = strptr(opts.filename) args.LParam = syscall.StringToUTF16Ptr(opts.filename)
args.CallbackFunc = syscall.NewCallback(browseForFolderCallback) args.CallbackFunc = syscall.NewCallback(browseForFolderCallback)
defer runtime.KeepAlive(opts.filename)
} }
if opts.ctx != nil { if opts.ctx != nil {
@ -420,7 +418,7 @@ type _BROWSEINFO struct {
Title *uint16 Title *uint16
Flags uint32 Flags uint32
CallbackFunc uintptr CallbackFunc uintptr
LParam uintptr LParam *uint16
Image int32 Image int32
} }

View File

@ -2,7 +2,6 @@ package zenity
import ( import (
"context" "context"
"runtime"
"syscall" "syscall"
"unsafe" "unsafe"
) )
@ -53,13 +52,12 @@ func message(kind messageKind, text string, opts options) error {
defer unhook() defer unhook()
} }
var title uintptr var title *uint16
if opts.title != nil { if opts.title != nil {
title = strptr(*opts.title) title = syscall.StringToUTF16Ptr(*opts.title)
defer runtime.KeepAlive(*opts.title)
} }
s, _, err := messageBox.Call(0, strptr(text), title, flags) s, _, err := messageBox.Call(0, strptr(text), uintptr(unsafe.Pointer(title)), flags)
if opts.ctx != nil && opts.ctx.Err() != nil { if opts.ctx != nil && opts.ctx.Err() != nil {
return opts.ctx.Err() return opts.ctx.Err()

View File

@ -525,6 +525,7 @@ func uuid(s string) uintptr {
type _COMObject struct{} type _COMObject struct{}
//go:uintptrescapes
func (o *_COMObject) Call(trap uintptr, a ...uintptr) (r1, r2 uintptr, lastErr error) { func (o *_COMObject) Call(trap uintptr, a ...uintptr) (r1, r2 uintptr, lastErr error) {
switch nargs := uintptr(len(a)); nargs { switch nargs := uintptr(len(a)); nargs {
case 0: case 0: