dawn/node: Handle printf() erroring

printf() can return -1 on error. In this situation, don't adjust msg with a negative offset.

Fixes a spurious crash when emitting lots of text.

Change-Id: Id1e9402bbbe3dd49cf08e660dea0cf67c5369516
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116289
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2023-01-10 14:13:50 +00:00 committed by Dawn LUCI CQ
parent e0254998cf
commit e45bf9f3d6
1 changed files with 2 additions and 2 deletions

View File

@ -77,12 +77,12 @@ const char* str(WGPUErrorType ty) {
}
// There's something broken with Node when attempting to write more than 65536 bytes to cout.
// Split the string up into writes of 4k chunks .
// Split the string up into writes of 4k chunks.
// Likely related: https://github.com/nodejs/node/issues/12921
void chunkedWrite(const char* msg) {
while (true) {
auto n = printf("%.4096s", msg);
if (n == 0) {
if (n <= 0) {
break;
}
msg += n;