Skip to content

Commit

Permalink
Make error value a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
awnumar committed Aug 8, 2019
1 parent f342255 commit 583d79f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
3 changes: 1 addition & 2 deletions memcall.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package memcall

import (
"errors"
"runtime"
)

Expand Down Expand Up @@ -33,7 +32,7 @@ func ReadWrite() MemoryProtectionFlag {
}

// ErrInvalidFlag indicates that a given memory protection flag is undefined.
var ErrInvalidFlag = errors.New("<memguard::memcall> memory protection flag is undefined")
const ErrInvalidFlag = "<memguard::memcall> memory protection flag is undefined"

// Wipes a given byte slice.
func wipe(buf []byte) {
Expand Down
3 changes: 2 additions & 1 deletion memcall_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package memcall

import (
"errors"
"fmt"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -73,7 +74,7 @@ func Protect(b []byte, mpf MemoryProtectionFlag) error {
} else if mpf.flag == NoAccess().flag {
prot = unix.PROT_NONE
} else {
return ErrInvalidFlag
return errors.New(ErrInvalidFlag)
}

// Change the protection value of the byte slice.
Expand Down
3 changes: 2 additions & 1 deletion memcall_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package memcall

import (
"errors"
"fmt"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -70,7 +71,7 @@ func Protect(b []byte, mpf MemoryProtectionFlag) error {
} else if mpf.flag == NoAccess().flag {
prot = unix.PROT_NONE
} else {
return ErrInvalidFlag
return errors.New(ErrInvalidFlag)
}

// Change the protection value of the byte slice.
Expand Down
3 changes: 2 additions & 1 deletion memcall_osx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package memcall

import (
"errors"
"fmt"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -69,7 +70,7 @@ func Protect(b []byte, mpf MemoryProtectionFlag) error {
} else if mpf.flag == NoAccess().flag {
prot = unix.PROT_NONE
} else {
return ErrInvalidFlag
return errors.New(ErrInvalidFlag)
}

// Change the protection value of the byte slice.
Expand Down
2 changes: 1 addition & 1 deletion memcall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestProtect(t *testing.T) {
if err := Protect(buffer, NoAccess()); err != nil {
t.Error(err)
}
if err := Protect(buffer, MemoryProtectionFlag{4}); err != ErrInvalidFlag {
if err := Protect(buffer, MemoryProtectionFlag{4}); err.Error() != ErrInvalidFlag {
t.Error("expected error")
}
Free(buffer)
Expand Down
3 changes: 2 additions & 1 deletion memcall_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package memcall

import (
"errors"
"fmt"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -73,7 +74,7 @@ func Protect(b []byte, mpf MemoryProtectionFlag) error {
} else if mpf.flag == NoAccess().flag {
prot = unix.PROT_NONE
} else {
return ErrInvalidFlag
return errors.New(ErrInvalidFlag)
}

// Change the protection value of the byte slice.
Expand Down
3 changes: 2 additions & 1 deletion memcall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package memcall

import (
"errors"
"fmt"
"unsafe"

Expand Down Expand Up @@ -76,7 +77,7 @@ func Protect(b []byte, mpf MemoryProtectionFlag) error {
} else if mpf.flag == NoAccess().flag {
prot = 0x1 // PAGE_NOACCESS
} else {
return ErrInvalidFlag
return errors.New(ErrInvalidFlag)
}

var oldProtect uint32
Expand Down

0 comments on commit 583d79f

Please sign in to comment.