|
From: | Philipp Stephani |
Subject: | Re: [PATCH] Improve error reporting when serializing non-Unicode strings to JSON |
Date: | Sat, 23 Dec 2017 16:58:30 +0000 |
> From: Philipp Stephani <address@hidden>
> Date: Sat, 23 Dec 2017 16:20:04 +0000
> Cc: address@hidden, address@hidden
>
> static void
> json_check_utf8 (Lisp_Object string)
> {
> eassert (!STRING_MULTIBYTE (string));
> struct coding_system coding;
> setup_coding_system (Qutf_8_unix, &coding);
> /* We initialize only the fields that check_utf_8 accesses. */
> coding.src_pos = 0;
> coding.src_pos_byte = 0;
> coding.src_chars = SCHARS (string);
> coding.src_bytes = SBYTES (string);
> coding.src_object = string;
> coding.eol_seen = EOL_SEEN_NONE;
> CHECK_TYPE (check_utf_8 (&coding) >= 0, Qutf_8_string_p, string);
> }
>
> This apparently fails to detect the unibyte string "u\xFFv" as invalid UTF-8.
How can that be? 0xFF shouldn't pass any of the
UTF_8_n_OCTET_LEADING_P tests, so it should end up in 'else', where
the function returns -1. Right?
You also need to initialize the head_ascii member, I think. Maybe its
being uninitialized explains the failure.
[Prev in Thread] | Current Thread | [Next in Thread] |