From 7672cde4f348c6485c7de39795ef7d538737b46f Mon Sep 17 00:00:00 2001 From: eNV25 Date: Sun, 27 Nov 2022 03:32:45 +0530 Subject: [PATCH] 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. --- cmd/ncdu/ncdu.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/ncdu/ncdu.go b/cmd/ncdu/ncdu.go index edf0a570c..f6de22f1a 100644 --- a/cmd/ncdu/ncdu.go +++ b/cmd/ncdu/ncdu.go @@ -1032,8 +1032,7 @@ outer: 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 { - // This is the maximum possible Unicode code point. Anything greater fails to compile as a Go quoted rune literal. - return '\U0010FFFF' + rune(k) + return rune(-k) }