From 5d04aae8969f6c72318ce0a4cde4f027766b1a55 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 17 Jan 2025 10:28:16 +0100 Subject: all: use min/max functions They are shorter, more readable, and don't require temp vars. --- vm/vm.go | 14 +++----------- vm/vmimpl/console.go | 5 +---- 2 files changed, 4 insertions(+), 15 deletions(-) (limited to 'vm') 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 { -- cgit mrf-deployment