Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 90518bf

Browse files
committed
Return of snprintf is not the number of written bytes
1 parent f49f545 commit 90518bf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Process.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,16 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
414414
if (indent & (1U << i))
415415
maxIndent = i+1;
416416
for (int i = 0; i < maxIndent - 1; i++) {
417-
int written;
417+
int written, ret;
418418
if (indent & (1 << i))
419-
written = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
419+
ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
420420
else
421-
written = snprintf(buf, n, " ");
421+
ret = snprintf(buf, n, " ");
422+
if (ret < 0 || ret >= n) {
423+
written = n;
424+
} else {
425+
written = ret;
426+
}
422427
buf += written;
423428
n -= written;
424429
}

0 commit comments

Comments
 (0)