the actual buffer size of the xmlBuffer is b->use, not b->size. you're so obvious libxml2