summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2023-03-08 14:14:51 -0600
committerCase Duckworth2023-03-08 14:14:51 -0600
commit50142e9bbcfc2ab2c83c99bae5669cf606c47014 (patch)
treecc770ead1fb02d4cf3101f0d8ef5f17feb7a6130
parentRewrite readc to work with ash (diff)
downloadvellum-50142e9bbcfc2ab2c83c99bae5669cf606c47014.tar.gz
vellum-50142e9bbcfc2ab2c83c99bae5669cf606c47014.zip
Fix arithmetic error in scroll causing crash
-rwxr-xr-xvellum18
1 files changed, 12 insertions, 6 deletions
diff --git a/vellum b/vellum index aee12d5..8cd03c2 100755 --- a/vellum +++ b/vellum
@@ -1,8 +1,8 @@
1#!/bin/sh 1set +x
2 2
3readc() { # arg: <variable-name> 3readc() { # arg: <variable-name>
4 # adapted from https://unix.stackexchange.com/a/464963 4 # adapted from https://unix.stackexchange.com/a/464963
5 if [ -t 0 ]; then 5 if test -t 0 ; then
6 # if stdin is a tty device, put it out of icanon, set min and 6 # if stdin is a tty device, put it out of icanon, set min and
7 # time to sane value, but don't otherwise touch other input or 7 # time to sane value, but don't otherwise touch other input or
8 # or local settings (echo, isig, icrnl...). Take a backup of the 8 # or local settings (echo, isig, icrnl...). Take a backup of the
@@ -97,8 +97,9 @@ notify_flush() { # notify_flush
97} 97}
98 98
99scroll() { # scroll nlines -- MUTATES GLOBAL STATE 99scroll() { # scroll nlines -- MUTATES GLOBAL STATE
100 case "${1:-0}" in 100 arg="${1:-0}"
101 \+*|\-*) n=$((n+$1)) ;; 101 case "$arg" in
102 +*|-*) n=$((n+${arg#+})) ;;
102 0) ;; 103 0) ;;
103 *) n=$1 ;; 104 *) n=$1 ;;
104 esac 105 esac
@@ -116,7 +117,7 @@ scroll() { # scroll nlines -- MUTATES GLOBAL STATE
116 fi 117 fi
117 118
118 m=$((n+l)) 119 m=$((n+l))
119 if $m -ge $max 120 if test $m -ge $max
120 then 121 then
121 m=$max 122 m=$max
122 fi 123 fi
@@ -125,8 +126,13 @@ scroll() { # scroll nlines -- MUTATES GLOBAL STATE
125 126
126ctty() { # ctty 127ctty() { # ctty
127 ## Get the controlling TTY interface. 128 ## Get the controlling TTY interface.
128 tty <&2 || # only works if not redirecting stderr 129 if test -t 2
130 then
131 # only works if not redirecting stderr
132 tty <&2
133 else
129 echo /proc/self/fd/1 # probably only works on linux 134 echo /proc/self/fd/1 # probably only works on linux
135 fi
130} 136}
131 137
132winch() { 138winch() {