summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/globalfilter/filter.go7
-rw-r--r--internal/globalfilter/filter_test.go35
-rw-r--r--internal/ior.go6
-rw-r--r--internal/tui/filterstack.go6
4 files changed, 48 insertions, 6 deletions
diff --git a/internal/globalfilter/filter.go b/internal/globalfilter/filter.go
index 689a728..2bc96a7 100644
--- a/internal/globalfilter/filter.go
+++ b/internal/globalfilter/filter.go
@@ -35,11 +35,14 @@ func NewEqFilter(value int64) *NumericFilter {
// represents an exact-match constraint (Op == OpEq and Value > 0).
// Returns (0, false) when the filter is nil, uses a different operator,
// or has a non-positive value.
-func (f *NumericFilter) EqValue() (int, bool) {
+// The return type is int64 to avoid silent truncation on 32-bit architectures
+// where converting int64 to int would silently discard the high 32 bits for
+// values that exceed math.MaxInt32.
+func (f *NumericFilter) EqValue() (int64, bool) {
if f == nil || f.Op != OpEq || f.Value <= 0 {
return 0, false
}
- return int(f.Value), true
+ return f.Value, true
}
type StringFilter struct {
diff --git a/internal/globalfilter/filter_test.go b/internal/globalfilter/filter_test.go
index c386673..2dce7f9 100644
--- a/internal/globalfilter/filter_test.go
+++ b/internal/globalfilter/filter_test.go
@@ -1,6 +1,7 @@
package globalfilter
import (
+ "math"
"testing"
)
@@ -158,3 +159,37 @@ func TestFilterEqual(t *testing.T) {
t.Fatalf("expected missing numeric filter to compare unequal")
}
}
+
+// TestEqValueReturnsInt64PreservesLargeValues verifies that EqValue returns
+// int64 so that values larger than math.MaxInt32 are not silently truncated on
+// 32-bit architectures (where int is 32 bits wide).
+func TestEqValueReturnsInt64PreservesLargeValues(t *testing.T) {
+ // A value that would be truncated to a different number if cast to int32.
+ large := int64(math.MaxInt32) + 1
+ f := &NumericFilter{Op: OpEq, Value: large}
+ got, ok := f.EqValue()
+ if !ok {
+ t.Fatalf("EqValue() returned ok=false for a valid positive value")
+ }
+ if got != large {
+ t.Fatalf("EqValue() = %d, want %d (int64 value must not be truncated)", got, large)
+ }
+
+ // Nil filter must return (0, false).
+ var nilFilter *NumericFilter
+ if v, ok := nilFilter.EqValue(); ok || v != 0 {
+ t.Fatalf("EqValue() on nil filter: got (%d, %v), want (0, false)", v, ok)
+ }
+
+ // Non-OpEq filter must return (0, false).
+ neqFilter := &NumericFilter{Op: OpNeq, Value: 1}
+ if v, ok := neqFilter.EqValue(); ok || v != 0 {
+ t.Fatalf("EqValue() on OpNeq filter: got (%d, %v), want (0, false)", v, ok)
+ }
+
+ // Non-positive value must return (0, false).
+ zeroFilter := &NumericFilter{Op: OpEq, Value: 0}
+ if v, ok := zeroFilter.EqValue(); ok || v != 0 {
+ t.Fatalf("EqValue() on zero value: got (%d, %v), want (0, false)", v, ok)
+ }
+}
diff --git a/internal/ior.go b/internal/ior.go
index 6e8111a..433484d 100644
--- a/internal/ior.go
+++ b/internal/ior.go
@@ -341,10 +341,12 @@ func applyTraceScopeFromGlobalFilter(cfg *flags.Config, filter globalfilter.Filt
cfg.PidFilter = -1
cfg.TidFilter = -1
if pid, ok := filter.PID.EqValue(); ok {
- cfg.PidFilter = pid
+ // EqValue returns int64; PID values are always within int range (Linux PID_MAX ≤ 4194304).
+ cfg.PidFilter = int(pid)
}
if tid, ok := filter.TID.EqValue(); ok {
- cfg.TidFilter = tid
+ // EqValue returns int64; TID values are always within int range (Linux PID_MAX ≤ 4194304).
+ cfg.TidFilter = int(tid)
}
}
diff --git a/internal/tui/filterstack.go b/internal/tui/filterstack.go
index 28667d9..b60f322 100644
--- a/internal/tui/filterstack.go
+++ b/internal/tui/filterstack.go
@@ -87,15 +87,17 @@ func (f *filterStack) rebindProcessFilters(pid, tid int) {
// pidFromFilter extracts the PID equality value from the active filter.
// Returns -1 (meaning "no filter") when no equality constraint is set.
func (f *filterStack) pidFromFilter() int {
+ // EqValue returns int64; PID values are always within int range (Linux PID_MAX ≤ 4194304).
pid, _ := f.global.PID.EqValue()
- return selectedPIDFilter(pid)
+ return selectedPIDFilter(int(pid))
}
// tidFromFilter extracts the TID equality value from the active filter.
// Returns -1 (meaning "no filter") when no equality constraint is set.
func (f *filterStack) tidFromFilter() int {
+ // EqValue returns int64; TID values are always within int range (Linux PID_MAX ≤ 4194304).
tid, _ := f.global.TID.EqValue()
- return selectedPIDFilter(tid)
+ return selectedPIDFilter(int(tid))
}
// labelStack returns the current human-readable filter label stack (read-only).