mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 05:23:40 +00:00
reflect: fix (u)int -> string conversions for invalid code points
This commit is contained in:
committed by
Damian Gryski
parent
e111b489ec
commit
364ac2dcb2
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user