forked from rosa/hakurei
ext: integer limit values
For portably using C integers without cgo. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -26,7 +26,9 @@ func TestSyscallResolveName(t *testing.T) {
|
|||||||
|
|
||||||
func TestRuleType(t *testing.T) {
|
func TestRuleType(t *testing.T) {
|
||||||
assertKind[ext.Uint, scmpUint](t)
|
assertKind[ext.Uint, scmpUint](t)
|
||||||
|
assertOverflow(t, ext.Uint(ext.MaxUint))
|
||||||
assertKind[ext.Int, scmpInt](t)
|
assertKind[ext.Int, scmpInt](t)
|
||||||
|
assertOverflow(t, ext.Int(ext.MaxInt))
|
||||||
|
|
||||||
assertSize[std.NativeRule, syscallRule](t)
|
assertSize[std.NativeRule, syscallRule](t)
|
||||||
assertKind[std.ScmpDatum, scmpDatum](t)
|
assertKind[std.ScmpDatum, scmpDatum](t)
|
||||||
@@ -62,3 +64,14 @@ func assertKind[native, equivalent any](t *testing.T) {
|
|||||||
t.Fatalf("%s: %s, want %s", nativeType.Name(), nativeType.Kind(), equivalentType.Kind())
|
t.Fatalf("%s: %s, want %s", nativeType.Name(), nativeType.Kind(), equivalentType.Kind())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assertOverflow asserts that incrementing m overflows.
|
||||||
|
func assertOverflow[T ~int32 | ~uint32](t *testing.T, m T) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
old := m
|
||||||
|
m++
|
||||||
|
if m > old {
|
||||||
|
t.Fatalf("unexpected value %#x", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package ext
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"iter"
|
"iter"
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,6 +16,12 @@ type (
|
|||||||
Int = int32
|
Int = int32
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Integer limit values.
|
||||||
|
const (
|
||||||
|
MaxUint = math.MaxUint32
|
||||||
|
MaxInt = math.MaxInt32
|
||||||
|
)
|
||||||
|
|
||||||
// SyscallNum represents an architecture-specific, Linux syscall number.
|
// SyscallNum represents an architecture-specific, Linux syscall number.
|
||||||
type SyscallNum Int
|
type SyscallNum Int
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user