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

[bug] busy loop and memory exhaustion on {x..$'\80'} with nomultibyte



$ (limit cputime 10; TIMEFMT='%MMiB %U user %S sys'; time zsh +o multibyte -c ": {z..$'\x80'}")
3980MiB 8.84s user 1.40s sys

{$'\x80'..$'\xff} doesn't have the problem, but the  expansion is:

$ zsh +o multibyte -c "printf %s {$'\x80'..$'\xfe'}" | hexdump -C
00000000  5c 4d 2d 40 5c 4d 2d 41  5c 4d 2d 42 5c 4d 2d 43  |\M-@\M-A\M-B\M-C|
00000010  5c 4d 2d 44 5c 4d 2d 45  5c 4d 2d 46 5c 4d 2d 47  |\M-D\M-E\M-F\M-G|
00000020  5c 4d 2d 48 5c 4d 2d 49  5c 4d 2d 4a 5c 4d 2d 4b  |\M-H\M-I\M-J\M-K|
00000030  5c 4d 2d 4c 5c 4d 2d 4d  5c 4d 2d 4e 5c 4d 2d 4f  |\M-L\M-M\M-N\M-O|
00000040  5c 4d 2d 50 5c 4d 2d 51  5c 4d 2d 52 5c 4d 2d 53  |\M-P\M-Q\M-R\M-S|
00000050  5c 4d 2d 54 5c 4d 2d 55  5c 4d 2d 56 5c 4d 2d 57  |\M-T\M-U\M-V\M-W|
00000060  5c 4d 2d 58 5c 4d 2d 59  5c 4d 2d 5a 5c 4d 2d 5b  |\M-X\M-Y\M-Z\M-[|
00000070  5c 4d 2d 5c 5c 4d 2d 5d  5c 4d 2d 5e 5c 4d 2d 5f  |\M-\\M-]\M-^\M-_|
00000080  5c 4d 2d 60 5c 4d 2d 61  5c 4d 2d 62 5c 4d 2d 63  |\M-`\M-a\M-b\M-c|
00000090  5c 4d 2d 64 5c 4d 2d 65  5c 4d 2d 66 5c 4d 2d 67  |\M-d\M-e\M-f\M-g|
000000a0  5c 4d 2d 68 5c 4d 2d 69  5c 4d 2d 6a 5c 4d 2d 6b  |\M-h\M-i\M-j\M-k|
000000b0  5c 4d 2d 6c 5c 4d 2d 6d  5c 4d 2d 6e 5c 4d 2d 6f  |\M-l\M-m\M-n\M-o|
000000c0  5c 4d 2d 70 5c 4d 2d 71  5c 4d 2d 72 5c 4d 2d 73  |\M-p\M-q\M-r\M-s|
000000d0  5c 4d 2d 74 5c 4d 2d 75  5c 4d 2d 76 5c 4d 2d 77  |\M-t\M-u\M-v\M-w|
000000e0  5c 4d 2d 78 5c 4d 2d 79  5c 4d 2d 7a 5c 4d 2d 7b  |\M-x\M-y\M-z\M-{|
000000f0  5c 4d 2d 7c 5c 4d 2d 7d  5c 4d 2d 7e 5c 4d 2d 5e  |\M-|\M-}\M-~\M-^|
00000100  3f 5e 00 5e 01 5e 02 5e  03 5e 04 5e 05 5e 06 5e  |?^.^.^.^.^.^.^.^|
00000110  07 5e 08 5e 09 5e 0a 5e  0b 5e 0c 5e 0d 5e 0e 5e  |.^.^.^.^.^.^.^.^|
00000120  0f 5e 10 5e 11 5e 12 5e  13 5e 14 5e 15 5e 16 5e  |.^.^.^.^.^.^.^.^|
00000130  17 5e 18 5e 19 5e 1a 5e  1b 5e 1c 5e 1d 5e 1e 5e  |.^.^.^.^.^.^.^.^|
00000140  1f 5e 20 5e 21 5e 22 5e  23 5e 24 5e 25 5e 26 5e  |.^ ^!^"^#^$^%^&^|
00000150  27 5e 28 5e 29 5e 2a 5e  2b 5e 2c 5e 2d 5e 2e 5e  |'^(^)^*^+^,^-^.^|
00000160  2f 5e 30 5e 31 5e 32 5e  33 5e 34 5e 35 5e 36 5e  |/^0^1^2^3^4^5^6^|
00000170  37 5e 38 5e 39 5e 3a 5e  3b 5e 3c 5e 3d 5e 3e     |7^8^9^:^;^<^=^>|
0000017f

With {$'\x80'..$'\xff'}, we get:

$ zsh +o multibyte -c "printf %s {$'\x80'..$'\xff'}" | hd
00000000  7b 80 2e 2e ff 7d                                 |{....}|
00000006

One can always use:

() {set -o localoption +o multibyte; bytes=(${(#)@}); } {0..255}

and then

printf %s $^bytes[##x+1,0x81]

To get byte values from x to 0x80 in a {x..y} fashion as a work around

(BTW, the fact that it's MiB above instead of documented KiB on
systems other than Darwin/macos is a separate bug that has
already been reported at least a couple of times in the past).

-- 
Stephane




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