1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-21 22:50:08 +03:00

Fix return value of xmlCharEncOutput

Commit 407b393d introduced a regression caused by xmlCharEncOutput
returning 0 in case of success instead of the number of bytes written.
Always use its return value for nbchars in xmlOutputBufferWrite.

Fixes #166.
This commit is contained in:
Nick Wellnhofer 2020-06-15 14:49:22 +02:00
parent af893a58c6
commit a697ed1e24
2 changed files with 7 additions and 19 deletions

View File

@ -2394,7 +2394,7 @@ xmlCharEncOutput(xmlOutputBufferPtr output, int init)
{
int ret;
size_t written;
size_t writtentot = 0;
int writtentot = 0;
size_t toconv;
int c_in;
int c_out;
@ -2427,7 +2427,7 @@ retry:
xmlGenericError(xmlGenericErrorContext,
"initialized encoder\n");
#endif
return(0);
return(c_out);
}
/*
@ -2540,7 +2540,7 @@ retry:
goto retry;
}
}
return(ret);
return(writtentot ? writtentot : ret);
}
#endif

20
xmlIO.c
View File

@ -3401,18 +3401,12 @@ xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *buf) {
out->error = XML_IO_ENCODER;
return(-1);
}
if (out->writecallback)
nbchars = xmlBufUse(out->conv);
else
nbchars = ret;
nbchars = ret >= 0 ? ret : 0;
} else {
ret = xmlBufAdd(out->buffer, (const xmlChar *) buf, chunk);
if (ret != 0)
return(-1);
if (out->writecallback)
nbchars = xmlBufUse(out->buffer);
else
nbchars = chunk;
nbchars = chunk;
}
buf += chunk;
len -= chunk;
@ -3599,19 +3593,13 @@ xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str,
out->error = XML_IO_ENCODER;
return(-1);
}
if (out->writecallback)
nbchars = xmlBufUse(out->conv);
else
nbchars = ret;
nbchars = ret >= 0 ? ret : 0;
} else {
ret = escaping(xmlBufEnd(out->buffer), &chunk, str, &cons);
if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */
return(-1);
xmlBufAddLen(out->buffer, chunk);
if (out->writecallback)
nbchars = xmlBufUse(out->buffer);
else
nbchars = chunk;
nbchars = chunk;
}
str += cons;
len -= cons;