Various fixes to make CodeQL happy

This commit is contained in:
Kovid Goyal
2025-04-20 21:18:23 +05:30
parent c84b894a89
commit adfcffa5d7
5 changed files with 27 additions and 20 deletions

View File

@@ -69,7 +69,7 @@ func Abspath(path string) string {
var KittyExe = sync.OnceValue(func() string {
if kitty_pid := os.Getenv("KITTY_PID"); kitty_pid != "" {
if kp, err := strconv.Atoi(kitty_pid); err == nil {
if kp, err := strconv.ParseInt(kitty_pid, 10, 32); err == nil {
if p, err := process.NewProcess(int32(kp)); err == nil {
if exe, err := p.Exe(); err == nil && filepath.IsAbs(exe) && filepath.Base(exe) == "kitty" {
return exe

View File

@@ -38,8 +38,7 @@ func is_oct_char(ch rune) bool {
func (self *ansi_c) write_digits(base int) {
if self.digit_idx > 0 {
text := string(self.digits[:self.digit_idx])
val, err := strconv.ParseUint(text, base, 32)
if err == nil {
if val, err := strconv.ParseUint(text, base, 32); err == nil && val <= 0x10ffff {
self.output.WriteRune(rune(val))
}
}

View File

@@ -35,6 +35,10 @@ func (self sgr_color) as_sgr(base int) string {
return fmt.Sprintf("%d:2:%d:%d:%d", base+8, self.color.Red, self.color.Green, self.color.Blue)
}
func as_uint8(x int) uint8 {
return uint8(uint(x) & 0xff)
}
func (self *sgr_color) from_extended(nums []int) bool {
switch nums[0] {
case 5:
@@ -45,9 +49,9 @@ func (self *sgr_color) from_extended(nums []int) bool {
case 2:
if len(nums) > 3 {
self.number = -1
self.color.Red = uint8(nums[1])
self.color.Green = uint8(nums[2])
self.color.Blue = uint8(nums[3])
self.color.Red = as_uint8(nums[1])
self.color.Green = as_uint8(nums[2])
self.color.Blue = as_uint8(nums[3])
return true
}
}