Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: printf %q segfault

lolilolicon wrote on Sun, Oct 16, 2016 at 22:58:14 +0800:
> The following produces segmentation fault:
>     printf '%q' 你
> produced with zsh 5.2.
> Ask if you need any more info.

With latest master it doesn't segfault, but it's not correct, either:

% printf '%q' 你 | xxd
0000000: 2427 5c33 3434 2724 275c 3237 3527 a0    $'\344'$'\275'.

The UTF-8 encoding of your character is E4 BD A0, however, the low byte
(0xA0) is output literally.  Since a lone 0xA0 is not a valid UTF-8
sequence, my terminal renders it [if I remove the |xxd pipe] as a U+FFFD

This also reproduces with «printf '%q\n' $'\U00A0'», which should print
either « » (a non-breaking-space) or «$'\302'$'\240'» (the quotestring()
representation of the UTF-8 encoding of U+00A0; that encoding is C2 A0).

Bottom line: the byte 0xA0 should not be printed literally but escaped.

The reason 0xA0 is output literally is that the code takes the "if (itok(*u))"
branch in quotestring(); if it didn't take that branch, it'd behave



Messages sorted by: Reverse Date, Date, Thread, Author