emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Improve error reporting when serializing non-Unicode strings


From: Philipp Stephani
Subject: Re: [PATCH] Improve error reporting when serializing non-Unicode strings to JSON
Date: Sat, 23 Dec 2017 16:20:04 +0000



Eli Zaretskii <address@hidden> schrieb am Sa., 23. Dez. 2017 um 16:34 Uhr:
> From: Philipp Stephani <address@hidden>
> Date: Sat, 23 Dec 2017 15:19:17 +0000
> Cc: address@hidden, address@hidden
>
>  So let's use check_utf_8, as its downsides don't sound serious to me,
>
> Well it needs to be rewritten significantly to take a char*, length argument instead of the coding_system
> struct.

But creating a coding_system struct requires a single call to
setup_coding_system, which doesn't sound too bad.

Unfortunately it's not that easy. coding_system has many fields that setup_coding_system doesn't initialize.
I've tried using check_utf_8, but it doesn't seem to work:

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]