aboutsummaryrefslogtreecommitdiffstats
path: root/vm
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2025-01-17 10:28:16 +0100
committerDmitry Vyukov <dvyukov@google.com>2025-01-17 10:02:07 +0000
commit5d04aae8969f6c72318ce0a4cde4f027766b1a55 (patch)
tree8f1b632847c431407090f0fe1335522ff2195a37 /vm
parentf9e07a6e597b68d3397864e6ee4550f9065c3518 (diff)
all: use min/max functions
They are shorter, more readable, and don't require temp vars.
Diffstat (limited to 'vm')
-rw-r--r--vm/vm.go14
-rw-r--r--vm/vmimpl/console.go5
2 files changed, 4 insertions, 15 deletions
diff --git a/vm/vm.go b/vm/vm.go
index 7d580e837..522cf5aa8 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -445,9 +445,7 @@ func (mon *monitor) appendOutput(out []byte) (*report.Report, bool) {
}
mon.matchPos--
}
- if mon.matchPos < 0 {
- mon.matchPos = 0
- }
+ mon.matchPos = max(mon.matchPos, 0)
return nil, false
}
@@ -510,14 +508,8 @@ func (mon *monitor) createReport(defaultError string) *report.Report {
Type: typ,
}
}
- start := rep.StartPos - mon.beforeContext
- if start < 0 {
- start = 0
- }
- end := rep.EndPos + afterContext
- if end > len(rep.Output) {
- end = len(rep.Output)
- }
+ start := max(rep.StartPos-mon.beforeContext, 0)
+ end := min(rep.EndPos+afterContext, len(rep.Output))
rep.Output = rep.Output[start:end]
rep.StartPos -= start
rep.EndPos -= start
diff --git a/vm/vmimpl/console.go b/vm/vmimpl/console.go
index a2dedeb5c..200c44f73 100644
--- a/vm/vmimpl/console.go
+++ b/vm/vmimpl/console.go
@@ -61,10 +61,7 @@ func (t *tty) Read(buf []byte) (int, error) {
return 0, io.EOF
}
n, err := syscall.Read(t.fd, buf)
- if n < 0 {
- n = 0
- }
- return n, err
+ return max(n, 0), err
}
func (t *tty) Close() error {