| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 240de93 commit 68bb1e9
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -287,18 +287,19 @@ size_t StringBytes::WriteUCS2(Isolate* isolate, | |||
| 287 | 287 | CHECK_EQ(reinterpret_cast<uintptr_t>(aligned_dst) % sizeof(*dst), 0); | |
| 288 | 288 | ||
| 289 | 289 | // Write all but the last char | |
| 290 | + max_chars = std::min(max_chars, static_cast<size_t>(str->Length())); | ||
| 291 | + if (max_chars == 0) return 0; | ||
| 290 | 292 | nchars = str->Write(isolate, aligned_dst, 0, max_chars - 1, flags); | |
| 293 | + CHECK_EQ(nchars, max_chars - 1); | ||
| 291 | 294 | ||
| 292 | 295 | // Shift everything to unaligned-left | |
| 293 | 296 | memmove(dst, aligned_dst, nchars * sizeof(*dst)); | |
| 294 | 297 | ||
| 295 | 298 | // One more char to be written | |
| 296 | 299 | uint16_t last; | |
| 297 | - if (nchars == max_chars - 1 && | ||
| 298 | - str->Write(isolate, &last, nchars, 1, flags) != 0) { | ||
| 299 | - memcpy(buf + nchars * sizeof(*dst), &last, sizeof(last)); | ||
| 300 | - nchars++; | ||
| 301 | - } | ||
| 300 | + CHECK_EQ(str->Write(isolate, &last, nchars, 1, flags), 1); | ||
| 301 | + memcpy(buf + nchars * sizeof(*dst), &last, sizeof(last)); | ||
| 302 | + nchars++; | ||
| 302 | 303 | ||
| 303 | 304 | *chars_written = nchars; | |
| 304 | 305 | return nchars * sizeof(*dst); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,3 +91,11 @@ assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0); | |||
| 91 | 91 | // Large overrun could corrupt the process | |
| 92 | 92 | assert.strictEqual(Buffer.alloc(4) | |
| 93 | 93 | .write('ыыыыыы'.repeat(100), 3, 'utf16le'), 0); | |
| 94 | + | ||
| 95 | + { | ||
| 96 | + // .write() does not affect the byte after the written-to slice of the Buffer. | ||
| 97 | + // Refs: https://github.com/nodejs/node/issues/26422 | ||
| 98 | + const buf = Buffer.alloc(8); | ||
| 99 | + assert.strictEqual(buf.write('ыы', 1, 'utf16le'), 4); | ||
| 100 | + assert.deepStrictEqual([...buf], [0, 0x4b, 0x04, 0x4b, 0x04, 0, 0, 0]); | ||
| 101 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments