aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/expressions.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-11-23 17:48:28 -0800
committerIan Lance Taylor <iant@golang.org>2020-11-25 08:02:39 -0800
commit4aff491ffcb1312c7745758301df6d22c0c70200 (patch)
tree99abab43b95764f90644c04d9657f018914ae529 /gcc/go/gofrontend/expressions.cc
parent049ce9d233e2d865dc81a5042b1c28ee21d1c9d8 (diff)
downloadgcc-4aff491ffcb1312c7745758301df6d22c0c70200.zip
gcc-4aff491ffcb1312c7745758301df6d22c0c70200.tar.gz
gcc-4aff491ffcb1312c7745758301df6d22c0c70200.tar.bz2
compiler: avoid silent truncation for string(1 << 32)
In the conversion of a constant integer to a string type, the value of the constant integer was being silently truncated from unsigned long to unsigned int, producing the wrong string value. Add an explicit overflow check to avoid this problem. For golang/go#42790 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/272611
Diffstat (limited to 'gcc/go/gofrontend/expressions.cc')
-rw-r--r--gcc/go/gofrontend/expressions.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 6bc9348..448888b 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -4024,8 +4024,16 @@ Type_conversion_expression::do_string_constant_value(std::string* val) const
unsigned long ival;
if (nc.to_unsigned_long(&ival) == Numeric_constant::NC_UL_VALID)
{
+ unsigned int cval = static_cast<unsigned int>(ival);
+ if (static_cast<unsigned long>(cval) != ival)
+ {
+ go_warning_at(this->location(), 0,
+ "unicode code point 0x%lx out of range",
+ ival);
+ cval = 0xfffd; // Unicode "replacement character."
+ }
val->clear();
- Lex::append_char(ival, true, val, this->location());
+ Lex::append_char(cval, true, val, this->location());
return true;
}
}