mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
More CodeQL fixes
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -388,17 +389,18 @@ func (self *handler) switch_mode(mode Mode) {
|
|||||||
|
|
||||||
func (self *handler) handle_hex_key_event(event *loop.KeyEvent) {
|
func (self *handler) handle_hex_key_event(event *loop.KeyEvent) {
|
||||||
text := self.rl.AllText()
|
text := self.rl.AllText()
|
||||||
val, err := strconv.ParseUint(text, 16, 32)
|
uval, err := strconv.ParseUint(text, 16, 32)
|
||||||
new_val := -1
|
new_val := -1
|
||||||
if err != nil {
|
if err != nil || uval > math.MaxInt {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
val := int(uval)
|
||||||
if event.MatchesPressOrRepeat("tab") {
|
if event.MatchesPressOrRepeat("tab") {
|
||||||
new_val = int(val) + 10
|
new_val = val + 10
|
||||||
} else if event.MatchesPressOrRepeat("up") {
|
} else if event.MatchesPressOrRepeat("up") {
|
||||||
new_val = int(val) + 1
|
new_val = val + 1
|
||||||
} else if event.MatchesPressOrRepeat("down") {
|
} else if event.MatchesPressOrRepeat("down") {
|
||||||
new_val = utils.Max(32, int(val)-1)
|
new_val = max(32, val-1)
|
||||||
}
|
}
|
||||||
if new_val > -1 {
|
if new_val > -1 {
|
||||||
event.Handled = true
|
event.Handled = true
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@@ -59,8 +60,9 @@ func StringLiteral(val string) (string, error) {
|
|||||||
var state State
|
var state State
|
||||||
decode := func(base int) {
|
decode := func(base int) {
|
||||||
text := string(buf[:bufcount])
|
text := string(buf[:bufcount])
|
||||||
num, _ := strconv.ParseUint(text, base, 32)
|
if num, err := strconv.ParseUint(text, base, 32); err == nil && num <= utf8.MaxRune {
|
||||||
ans.WriteRune(rune(num))
|
ans.WriteRune(rune(num))
|
||||||
|
}
|
||||||
state = normal
|
state = normal
|
||||||
bufcount = 0
|
bufcount = 0
|
||||||
buflimit = 0
|
buflimit = 0
|
||||||
|
|||||||
@@ -806,7 +806,7 @@ func (f *Function) SetRegisterTo(self Register, val any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r Register) ARMId() uint32 {
|
func (r Register) ARMId() uint32 {
|
||||||
num, err := strconv.Atoi(r.Name[1:])
|
num, err := strconv.ParseUint(r.Name[1:], 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package loop
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ func KeyEventFromCSI(csi string) *KeyEvent {
|
|||||||
ans[i] = missing
|
ans[i] = missing
|
||||||
} else {
|
} else {
|
||||||
q, err := strconv.ParseUint(x, 10, 32)
|
q, err := strconv.ParseUint(x, 10, 32)
|
||||||
if err != nil {
|
if err != nil || q > math.MaxInt32 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ans[i] = int32(q)
|
ans[i] = int32(q)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -43,7 +44,10 @@ func ISO8601Parse(raw string) (time.Time, error) {
|
|||||||
text := raw[:num_digits]
|
text := raw[:num_digits]
|
||||||
raw = raw[num_digits:]
|
raw = raw[num_digits:]
|
||||||
ans, err := strconv.ParseUint(text, 10, 32)
|
ans, err := strconv.ParseUint(text, 10, 32)
|
||||||
return int(ans), err
|
if err == nil && ans <= math.MaxInt {
|
||||||
|
return int(ans), nil
|
||||||
|
}
|
||||||
|
return math.MaxInt, err
|
||||||
|
|
||||||
}
|
}
|
||||||
optional_separator := func(x byte) bool {
|
optional_separator := func(x byte) bool {
|
||||||
@@ -77,7 +81,8 @@ func ISO8601Parse(raw string) (time.Time, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var hour, minute, second, nsec int
|
var hour, minute, second int
|
||||||
|
var nsec int64
|
||||||
|
|
||||||
if len(raw) > 0 && (raw[0] == 'T' || raw[0] == ' ') {
|
if len(raw) > 0 && (raw[0] == 'T' || raw[0] == ' ') {
|
||||||
raw = raw[1:]
|
raw = raw[1:]
|
||||||
@@ -114,7 +119,7 @@ func ISO8601Parse(raw string) (time.Time, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errf("timestamp does not have a valid nanosecond field")
|
return errf("timestamp does not have a valid nanosecond field")
|
||||||
}
|
}
|
||||||
nsec = int(n)
|
nsec = int64(n)
|
||||||
for ; extra > 0; extra-- {
|
for ; extra > 0; extra-- {
|
||||||
nsec *= 10
|
nsec *= 10
|
||||||
}
|
}
|
||||||
@@ -158,7 +163,7 @@ func ISO8601Parse(raw string) (time.Time, error) {
|
|||||||
seconds := tzhour*3600 + tzminute*60
|
seconds := tzhour*3600 + tzminute*60
|
||||||
loc = time.FixedZone("", tzsign*seconds)
|
loc = time.FixedZone("", tzsign*seconds)
|
||||||
}
|
}
|
||||||
return time.Date(year, time.Month(month), day, hour, minute, second, nsec, loc), err
|
return time.Date(year, time.Month(month), day, hour, minute, second, int(nsec), loc), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ISO8601Format(x time.Time) string {
|
func ISO8601Format(x time.Time) string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@@ -38,7 +39,7 @@ func is_oct_char(ch rune) bool {
|
|||||||
func (self *ansi_c) write_digits(base int) {
|
func (self *ansi_c) write_digits(base int) {
|
||||||
if self.digit_idx > 0 {
|
if self.digit_idx > 0 {
|
||||||
text := string(self.digits[:self.digit_idx])
|
text := string(self.digits[:self.digit_idx])
|
||||||
if val, err := strconv.ParseUint(text, base, 32); err == nil && val <= 0x10ffff {
|
if val, err := strconv.ParseUint(text, base, 32); err == nil && val <= utf8.MaxRune {
|
||||||
self.output.WriteRune(rune(val))
|
self.output.WriteRune(rune(val))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user