File tree 1 file changed +9
-0
lines changed
1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -98,9 +98,18 @@ uint32_t writeInto(jsg::Lock& js,
98
98
return result.written ;
99
99
}
100
100
case Encoding::UTF16LE: {
101
+ #if __has_feature(undefined_behavior_sanitizer)
102
+ // UBSan warns about unaligned writes, but this can be hard to avoid if dest is unaligned.
103
+ // Use temp variable to perform aligned write instead.
104
+ kj::Array<uint16_t > tmpBuf = kj::heapArray<uint16_t >(dest.size () / sizeof (uint16_t ));
105
+ auto result = string.writeInto (js, tmpBuf, flags);
106
+ kj::ArrayPtr<uint16_t > buf (reinterpret_cast <uint16_t *>(dest.begin ()), result.written );
107
+ buf.copyFrom (tmp);
108
+ #else
101
109
kj::ArrayPtr<uint16_t > buf (
102
110
reinterpret_cast <uint16_t *>(dest.begin ()), dest.size () / sizeof (uint16_t ));
103
111
auto result = string.writeInto (js, buf, flags);
112
+ #endif
104
113
return result.written * sizeof (uint16_t );
105
114
}
106
115
case Encoding::BASE64:
You can’t perform that action at this time.
0 commit comments