mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-26 00:37:43 +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:
@@ -2394,7 +2394,7 @@ xmlCharEncOutput(xmlOutputBufferPtr output, int init)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t written;
|
size_t written;
|
||||||
size_t writtentot = 0;
|
int writtentot = 0;
|
||||||
size_t toconv;
|
size_t toconv;
|
||||||
int c_in;
|
int c_in;
|
||||||
int c_out;
|
int c_out;
|
||||||
@@ -2427,7 +2427,7 @@ retry:
|
|||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"initialized encoder\n");
|
"initialized encoder\n");
|
||||||
#endif
|
#endif
|
||||||
return(0);
|
return(c_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2540,7 +2540,7 @@ retry:
|
|||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(ret);
|
return(writtentot ? writtentot : ret);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
20
xmlIO.c
20
xmlIO.c
@@ -3401,18 +3401,12 @@ xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *buf) {
|
|||||||
out->error = XML_IO_ENCODER;
|
out->error = XML_IO_ENCODER;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (out->writecallback)
|
nbchars = ret >= 0 ? ret : 0;
|
||||||
nbchars = xmlBufUse(out->conv);
|
|
||||||
else
|
|
||||||
nbchars = ret;
|
|
||||||
} else {
|
} else {
|
||||||
ret = xmlBufAdd(out->buffer, (const xmlChar *) buf, chunk);
|
ret = xmlBufAdd(out->buffer, (const xmlChar *) buf, chunk);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return(-1);
|
return(-1);
|
||||||
if (out->writecallback)
|
nbchars = chunk;
|
||||||
nbchars = xmlBufUse(out->buffer);
|
|
||||||
else
|
|
||||||
nbchars = chunk;
|
|
||||||
}
|
}
|
||||||
buf += chunk;
|
buf += chunk;
|
||||||
len -= chunk;
|
len -= chunk;
|
||||||
@@ -3599,19 +3593,13 @@ xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str,
|
|||||||
out->error = XML_IO_ENCODER;
|
out->error = XML_IO_ENCODER;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (out->writecallback)
|
nbchars = ret >= 0 ? ret : 0;
|
||||||
nbchars = xmlBufUse(out->conv);
|
|
||||||
else
|
|
||||||
nbchars = ret;
|
|
||||||
} else {
|
} else {
|
||||||
ret = escaping(xmlBufEnd(out->buffer), &chunk, str, &cons);
|
ret = escaping(xmlBufEnd(out->buffer), &chunk, str, &cons);
|
||||||
if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */
|
if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */
|
||||||
return(-1);
|
return(-1);
|
||||||
xmlBufAddLen(out->buffer, chunk);
|
xmlBufAddLen(out->buffer, chunk);
|
||||||
if (out->writecallback)
|
nbchars = chunk;
|
||||||
nbchars = xmlBufUse(out->buffer);
|
|
||||||
else
|
|
||||||
nbchars = chunk;
|
|
||||||
}
|
}
|
||||||
str += cons;
|
str += cons;
|
||||||
len -= cons;
|
len -= cons;
|
||||||
|
|||||||
Reference in New Issue
Block a user