- snprintf(error->text, JSON_ERROR_TEXT_LENGTH,
- "%s near end of file", text);
+ if(lex->stream.state == STREAM_STATE_ERROR) {
+ /* No context for UTF-8 decoding errors */
+ result = msg_text;
+ }
+ else {
+ snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
+ "%s near end of file", msg_text);
+ result = msg_with_context;
+ }