reflect: fix (u)int -> string conversions for invalid code points

This commit is contained in:
Damian Gryski
2026-05-26 14:28:08 -07:00
committed by Damian Gryski
parent e111b489ec
commit 364ac2dcb2
3 changed files with 96 additions and 7 deletions
+13 -6
View File
@@ -1690,20 +1690,27 @@ func makeComplex(flags valueFlags, f complex128, t *RawType) Value {
func stringFromUnicode(x rune) string
func cvtIntString(v Value, t *RawType) Value {
b := stringFromUnicode(rune(v.Int()))
s := "\uFFFD"
if x := v.Int(); int64(rune(x)) == x {
s = string(rune(x))
}
return Value{
typecode: t,
value: unsafe.Pointer(&b),
flags: v.flags,
value: unsafe.Pointer(&s),
flags: v.flags | valueFlagRO,
}
}
func cvtUintString(v Value, t *RawType) Value {
b := stringFromUnicode(rune(v.Uint()))
s := "\uFFFD"
if x := v.Uint(); uint64(rune(x)) == x {
s = string(rune(x))
}
return Value{
typecode: t,
value: unsafe.Pointer(&b),
flags: v.flags,
value: unsafe.Pointer(&s),
flags: v.flags | valueFlagRO,
}
}