From 74bb4f707dca03555ee59a476755c7caa7182002 Mon Sep 17 00:00:00 2001 From: Sauyon Lee Date: Mon, 10 Feb 2020 12:45:13 -0800 Subject: [PATCH] Make rune literal string value its value --- ql/src/semmle/go/Expr.qll | 6 +++++- .../library-tests/semmle/go/Expr/ConstantValues.expected | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ql/src/semmle/go/Expr.qll b/ql/src/semmle/go/Expr.qll index 857a7e487ef..b264d21d0db 100644 --- a/ql/src/semmle/go/Expr.qll +++ b/ql/src/semmle/go/Expr.qll @@ -220,7 +220,11 @@ class ImagLit extends @imaglit, BasicLit { } /** * A character literal. */ -class CharLit extends @charlit, BasicLit { } +class CharLit extends @charlit, BasicLit { + // use the constant value of the literal as the string value, as the value we get from the + // compiler is an integer, meaning we would not otherwise have a string value for rune literals + override string getStringValue() { result = this.getValue() } +} /** * A string literal. diff --git a/ql/test/library-tests/semmle/go/Expr/ConstantValues.expected b/ql/test/library-tests/semmle/go/Expr/ConstantValues.expected index 6960266950d..0526762289d 100644 --- a/ql/test/library-tests/semmle/go/Expr/ConstantValues.expected +++ b/ql/test/library-tests/semmle/go/Expr/ConstantValues.expected @@ -18,7 +18,9 @@ | consts.go:32:29:32:36 | ...-... | 2.3 - 9.7i | (2.3 + -9.7i), (2589569785738035/1125899906842624 + -2730307274093363/281474976710656i) | | consts.go:32:33:32:36 | 9.7i | 9.7i | (0 + 9.7i), (0 + 97/10i) | | consts.go:33:3:33:5 | 'a' | 'a' | 97, 97 | +| consts.go:33:3:33:5 | 'a' | 'a' | a | | consts.go:33:8:33:13 | '\\x8b' | '\\x8b' | 139, 139 | +| consts.go:33:8:33:13 | '\\x8b' | '\\x8b' | \ufffd | | consts.go:33:16:33:38 | 3.141592653589793238462 | 3.141592653589793238462 | 3.141593, 1570796326794896619231/500000000000000000000 | | consts.go:33:16:33:40 | ...*... | 3.141592653589793238462 * 8 | 25.132741, 884279719003555/35184372088832 | | consts.go:33:40:33:40 | 8 | 8 | 8, 8 |