Segfault using `watch -c` with ANSI escapes in output

Brian Inglis
Wed Apr 19 09:14:00 GMT 2017

On 2017-04-18 06:36, Adam Dinwoodie wrote:
> I'm seeing a segfault from using `watch -c` with commands that output
> ANSI colour sequences, which is a bit sad given the whole point of the
> `-c` is to get the ANSI colour sequences to be displayed.
> Simple test case:
>     $ echo -e '\e[0;32mGreen\e[0;0m' >escapes
>     $ cat escapes  # Text is green in my terminal
>     Green
>     $ xxd escapes
>     00000000: 1b5b 303b 3332 6d47 7265 656e 1b5b 303b  .[0;32mGreen.[0;
>     00000010: 306d 0a                                  0m.
>     $ watch -c cat escapes
>     Segmentation fault (core dumped)

Dies on me too: 
$ uname -srvmo
CYGWIN_NT-10.0 2.8.0(0.309/5/3) 2017-04-01 20:47 x86_64 Cygwin
$ watch --version
watch from procps-ng 3.3.11

gdb crashes with dumper .core.

$ gdb watch
Reading symbols from watch...(no debugging symbols found)...done.
(gdb) run -c cat e
Starting program: /usr/bin/watch -c cat e
[New Thread 436.0x19dc]
[New Thread 436.0x1e44]
[New Thread 436.0x834]
[New Thread 436.0x12d0]
[New Thread 436.0x1508]
[New Thread 436.0xa24]

Program received signal SIGSEGV, Segmentation fault.
0x00000001004029b0 in ?? ()
(gdb) bt
#0  0x00000001004029b0 in ?? ()
#1  0x0000000180047812 in _cygwin_exit_return () at /usr/src/debug/cygwin-2.8.0-1/winsup/cygwin/
#2  0x00000001800455e3 in _cygtls::call2 (this=0xffffce00, func=0x1800468d0 <dll_crt0_1(void*)>, arg=0x0,
    buf=buf@entry=0xffffcdf0) at /usr/src/debug/cygwin-2.8.0-1/winsup/cygwin/
#3  0x0000000180045694 in _cygtls::call (func=<optimized out>, arg=<optimized out>)
    at /usr/src/debug/cygwin-2.8.0-1/winsup/cygwin/
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) q
A debugging session is active.

        Inferior 1 [process 436] will be killed.

Quit anyway? (y or n) y

> This works as expected when using `watch` without the `-c` option, and
> when using `watch -c` with output that doesn't include any ANSI colour
> sequences.

Same here e.g. $ watch cat e; watch -c cat -A e both work okay.

Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list