cmd/ncdu: use negative values for key runes

The previous version used values after the maximum Unicode code-point
to encode a key. This could lead to an overflow since a key is a int16,
a rune is int32 and the maximum Unicode code-point is larger than int16.

A better solution is to simply use negative runes for keys.
This commit is contained in:
eNV25 2022-11-27 03:32:45 +05:30 committed by Nick Craig-Wood
parent a4c65532ea
commit 7672cde4f3

View File

@ -1032,8 +1032,7 @@ outer:
return nil return nil
} }
// key returns a rune representing the key k. It is larger than the maximum Unicode code-point. // key returns a rune representing the key k. It is a negative value, to not collide with Unicode code-points.
func key(k tcell.Key) rune { func key(k tcell.Key) rune {
// This is the maximum possible Unicode code point. Anything greater fails to compile as a Go quoted rune literal. return rune(-k)
return '\U0010FFFF' + rune(k)
} }