From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani
> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Sat, 23 Dec 2017 16:20:04 +0000
> Cc: phst@google.c= om, emacs-deve= l@gnu.org
>
> static void
> json_check_utf8 (Lisp_Object string)
> {
>=C2=A0 =C2=A0eassert (!STRING_MULTIBYTE (string));
>=C2=A0 =C2=A0struct coding_system coding;
>=C2=A0 =C2=A0setup_coding_system (Qutf_8_unix, &coding);
>=C2=A0 =C2=A0/* We initialize only the fields that check_utf_8 accesses= .=C2=A0 */
>=C2=A0 =C2=A0coding.src_pos =3D 0;
>=C2=A0 =C2=A0coding.src_pos_byte =3D 0;
>=C2=A0 =C2=A0coding.src_chars =3D SCHARS (string);
>=C2=A0 =C2=A0coding.src_bytes =3D SBYTES (string);
>=C2=A0 =C2=A0coding.src_object =3D string;
>=C2=A0 =C2=A0coding.eol_seen =3D EOL_SEEN_NONE;
>=C2=A0 =C2=A0CHECK_TYPE (check_utf_8 (&coding) >=3D 0, Qutf_8_st= ring_p, string);
> }
>
> This apparently fails to detect the unibyte string "u\xFFv" = as invalid UTF-8.
How can that be?=C2=A0 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.=C2=A0 Right?
You also need to initialize the head_ascii member, I think.=C2=A0 Maybe its=
being uninitialized explains the failure.