From 463fd3346a04d6d0c6ec4820fc701d9a1c160458 Mon Sep 17 00:00:00 2001
From: Daniel Veillard <veillard@redhat.com>
Date: Fri, 19 Aug 2011 11:05:04 +0800
Subject: [PATCH] Fix an off by one error in encoding
To: libvir-list@redhat.com
this off by one error doesn't seems to reproduce on linux
but the error is real.
Signed-off-by: Daniel Veillard <veillard@redhat.com>
---
encoding.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/encoding.c b/encoding.c
index d1140bf..fb0c38a 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1928,7 +1928,7 @@ xmlCharEncFirstLineInt(xmlCharEncodingHandler *handler, xmlBufferPtr out,
if (in == NULL) return(-1);
/* calculate space available */
- written = out->size - out->use;
+ written = out->size - out->use - 1; /* count '\0' */
toconv = in->use;
/*
* echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
@@ -2059,7 +2059,7 @@ xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out,
toconv = in->use;
if (toconv == 0)
return (0);
- written = out->size - out->use;
+ written = out->size - out->use -1; /* count '\0' */
if (toconv * 2 >= written) {
xmlBufferGrow(out, out->size + toconv * 2);
written = out->size - out->use - 1;
--
1.7.11.4