aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/JSBuffer.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-05 12:05:16 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-05 12:05:16 -0800
commite23832d1ce9dc21265ef627e2d5deedf74642738 (patch)
tree3c3c94059967495f893c0d1706854ed253951494 /src/bun.js/bindings/JSBuffer.cpp
parent9665d7d21636b0eb344bc83c104f1796e96809bf (diff)
downloadbun-e23832d1ce9dc21265ef627e2d5deedf74642738.tar.gz
bun-e23832d1ce9dc21265ef627e2d5deedf74642738.tar.zst
bun-e23832d1ce9dc21265ef627e2d5deedf74642738.zip
Fix regression
Diffstat (limited to 'src/bun.js/bindings/JSBuffer.cpp')
-rw-r--r--src/bun.js/bindings/JSBuffer.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp
index b3e5f0b4e..29774f3c5 100644
--- a/src/bun.js/bindings/JSBuffer.cpp
+++ b/src/bun.js/bindings/JSBuffer.cpp
@@ -1151,12 +1151,17 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JS
case WebCore::BufferEncodingType::ucs2:
case WebCore::BufferEncodingType::utf16le: {
UChar* data = nullptr;
- size_t u16length = length > 1 ? length / 2 : 1;
- auto str = String::createUninitialized(u16length, data);
- // always zero out the last byte of the string incase the buffer is not a multiple of 2
- data[u16length - 1] = 0;
- memcpy(data, reinterpret_cast<const char*>(castedThis->typedVector() + offset), length);
- ret = JSC::JSValue::encode(JSC::jsString(vm, WTFMove(str)));
+ size_t u16length = length / 2;
+ if (u16length == 0) {
+ ret = JSC::JSValue::encode(JSC::jsEmptyString(vm));
+ } else {
+ auto str = String::createUninitialized(u16length, data);
+ // always zero out the last byte of the string incase the buffer is not a multiple of 2
+ data[u16length - 1] = 0;
+ memcpy(data, reinterpret_cast<const char*>(castedThis->typedVector() + offset), length);
+ ret = JSC::JSValue::encode(JSC::jsString(vm, WTFMove(str)));
+ }
+
break;
}