Return of snprintf is not the number of written bytes

This commit is contained in:
Hisham Muhammad 2019-02-10 00:36:34 +01:00
parent f49f545813
commit 90518bfc84
1 changed files with 8 additions and 3 deletions

View File

@ -414,11 +414,16 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
if (indent & (1U << i)) if (indent & (1U << i))
maxIndent = i+1; maxIndent = i+1;
for (int i = 0; i < maxIndent - 1; i++) { for (int i = 0; i < maxIndent - 1; i++) {
int written; int written, ret;
if (indent & (1 << i)) if (indent & (1 << i))
written = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]); ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
else else
written = snprintf(buf, n, " "); ret = snprintf(buf, n, " ");
if (ret < 0 || ret >= n) {
written = n;
} else {
written = ret;
}
buf += written; buf += written;
n -= written; n -= written;
} }