The attached patch fixes an XML_ERROR_UNEXPECTED_STATE when encountering '%' at the end of an entity value.
Thanks for the contribution.
Could you please also submit a bug report with steps how to reproduce the error.
Updated patch to fix segfault in xmlwf (?!)
Applied in xmltok_impl.c rev. 1.16.