neovim/test/unit
James McCoy ac055d677a os_stat: return ENOENT on NULL filename arg
Closes #4370

Explication:

    In the backtrace in #4370, we see that `buf_write()` was called with
    non-NULL `fname` and `sfname` arguments, but they've since _become_
    NULL.

    #7  0x00000000004de09d in buf_write (buf=0x1dee040, fname=0x0, fname@entry=0x1e985b0 "/home/sean/src/github.com/snczl/virta/pkg/meld/segment.go",
                                         sfname=0x0, sfname@entry=0x1ddfa60 "segment.go", start=1, end=72, eap=eap@entry=0x7ffc6b032e60, append=0,
                                         forceit=0, reset_changed=1, filtering=0)
    at /home/travis/build/neovim/bot-ci/build/neovim/src/nvim/fileio.c:2576

    This is most likely due to the code that restores those values from
    `buf`, which happens just before the fatal call to `os_fileinfo`

    ```c
        /*
         * The autocommands may have changed the name of the buffer, which may
         * be kept in fname, ffname and sfname.
         */
        if (buf_ffname)
          ffname = buf->b_ffname;
        if (buf_sfname)
          sfname = buf->b_sfname;
        if (buf_fname_f)
          fname = buf->b_ffname;
        if (buf_fname_s)
          fname = buf->b_sfname;
    ```

    It's worth noting that at this point `ffname` is still non-NULL, so
    it _could_ be used.  However, our current code is purely more strict
    than Vim in this area, which has caused us problems before (e.g.,
    `getdigits()`).  The commentary for `struct file_buffer` clearly
    indicate that all of `b_ffname`, `b_sfname`, and `b_fname` may be
    NULL:

    ```c
      /*
       * b_ffname has the full path of the file (NULL for no name).
       * b_sfname is the name as the user typed it (or NULL).
       * b_fname is the same as b_sfname, unless ":cd" has been done,
       *		then it is the same as b_ffname (NULL for no name).
       */
      char_u      *b_ffname;        /* full path file name */
      char_u      *b_sfname;        /* short file name */
      char_u      *b_fname;         /* current file name */
    ```

    Vim directly calls `stat(2)` which, although it is annotated to tell
    the compiler that the path argument is non-NULL, does handle a NULL
    pointer by returning a `-1` value and setting `errno` to `EFAULT`.
    This satisfies Vim's check, since it treats any `-1` return from
    `stat(2)` to mean the file doesn't exist (at least in this code
    path).

    Note that Vim's mch_stat() implementations on win32 and solaris
    clearly cannot accept NULL `name`. But the codepaths that call
    mch_stat will NULL `name` tend to be unix-only (eg: u_read_undo)!
2017-08-10 00:56:07 +02:00
..
api unittests: Fix linter errors 2017-03-11 23:48:16 +03:00
eval unittests: Fix allocation ordering for tv_dict_add_str() 2017-07-02 20:24:39 +03:00
fixtures *: Add comment to all C files 2017-04-19 19:11:50 +03:00
os os_stat: return ENOENT on NULL filename arg 2017-08-10 00:56:07 +02:00
buffer_spec.lua unittests: Check core dumps in after_each, like in functests 2017-03-11 23:23:49 +03:00
fileio_spec.lua unittests: Check core dumps in after_each, like in functests 2017-03-11 23:23:49 +03:00
formatc.lua unittest: Move nil checks to Gcc:preprocess 2017-01-03 22:54:54 +03:00
garray_spec.lua unittests: Do not import libnvim or headers in main process 2017-03-11 23:23:49 +03:00
helpers.lua unittests: Move checking cores to check_child_err 2017-04-08 04:48:58 +03:00
mbyte_spec.lua unittests: Check core dumps in after_each, like in functests 2017-03-11 23:23:49 +03:00
memory_spec.lua unittests: Check core dumps in after_each, like in functests 2017-03-11 23:23:49 +03:00
message_spec.lua unittests: Update test/unit/message_spec.lua 2017-03-11 23:26:33 +03:00
multiqueue_spec.lua unittests: Use more adequate names for some functions 2017-03-12 02:54:23 +03:00
option_spec.lua unittests: Check core dumps in after_each, like in functests 2017-03-11 23:23:49 +03:00
path_spec.lua startup: v:progpath fallback: path_guess_exepath 2017-05-15 15:01:52 +02:00
preload.lua unittests: Check core dumps in after_each, like in functests 2017-03-11 23:23:49 +03:00
preprocess.lua buffer: Hide one of the asserts from lua parser 2017-02-25 00:22:46 +03:00
profile_spec.lua unittests: Do not import libnvim or headers in main process 2017-03-11 23:23:49 +03:00
rbuffer_spec.lua unittests: Use more adequate names for some functions 2017-03-12 02:54:23 +03:00
set.lua unittests: Move filtering cdefs to main process 2017-03-12 03:02:14 +03:00
strings_spec.lua tests: Add tests for vim_strchr 2017-05-09 14:41:23 +03:00
tempfile_spec.lua unittests: avoid using pattern matching on file names 2017-03-16 06:58:15 -04:00
testtest_spec.lua unittests: Collect traces 2017-04-01 12:25:10 +03:00