neovim/neovim — pull request #1660 by equalsraf (2014-12-13 02:08:42+00:00)
Title: [RFC] SIGSEV: event_init called too late

Earlier today I got a SIGSEV when running in Windows (Wine/Mingw) - I can't replicate in Unix, but the issue still seems valid without my changes. Here is a trace

```
Program received signal SIGSEGV, Segmentation fault.
0x00000000005c99fa in kl_shift_Event (kl=0x0, d=0x33f860) at /home/raf/Code/neovim/src/nvim/os/event.c:28
28 KLIST_INIT(Event, Event, _destroy_event)
(gdb) bt
#0 0x00000000005c99fa in kl_shift_Event (kl=0x0, d=0x33f860) at /home/raf/Code/neovim/src/nvim/os/event.c:28
#1 0x00000000005c9dc1 in process_events_from (queue=0x0) at /home/raf/Code/neovim/src/nvim/os/event.c:173
#2 0x00000000005c9c6e in event_poll (ms=2000) at /home/raf/Code/neovim/src/nvim/os/event.c:135
#3 0x00000000005cf44f in os_delay (milliseconds=2000, ignoreinput=true)
at /home/raf/Code/neovim/src/nvim/os/time.c:48
#4 0x0000000000453a50 in set_termname (term=0x638ca6 "win32")
at /home/raf/Code/neovim/src/nvim/term.c:1329
#5 0x00000000004541c2 in termcapinit (name=0x0) at /home/raf/Code/neovim/src/nvim/term.c:1803
#6 0x0000000000543e1e in main (argc=1, argv=0xa51960) at /home/raf/Code/neovim/src/nvim/main.c:282
```

Which seems to happen because that failing call to `termcapinit()` happens before `event_init()` is called - resulting in NULL pointer being passed to process_events.

The minimal fix I added just moves the call to `event_init()`, but we could be more defensive and check the pointer, or add function attributes or an assert in process_events.