Commit Graph

214 Commits

Author SHA1 Message Date
Eliseo Martínez
5c00f8c132 Fix warnings: eval.c: do_return(): Np dereference: FP.
Problem    : Dereference of null pointer @ 18841.
Diagnostic : False positive.
Rationale  : Suggested error path takes `reanimate` branch at 18827,
             assigning `rettv = current_funccal->rettv`. Then,
             inmediately after, it supposes rettv is null, which cannot
             happen, since current_funccal->rettv should always be non
             null.
Resolution : Assert current_funccal->rettv non null.
2014-11-18 22:00:03 +01:00
Eliseo Martínez
97be8d45f4 Fix warnings: eval.c: add_nr_var(): Out of bounds: FP.
Problem    : Out-of-bound array access @ 18737.
Diagnostic : False positive.
Rationale  : Situation is intentional. `dictitem_T` is a prefix all dict
             items whill share, but actual size of each item will be
             different depending on its key length. `di_key` array field
             is declared of size 1 just to have a field name, but real
             size will vary for each item.
Resolution : Make analyzer ignore it.
             This could be refactored to use C99-allowed variable length
             arrays, but eval.c is bound to dissappear, so no effort is
             done in that sense.
2014-11-18 22:00:02 +01:00
Eliseo Martínez
3bf32fe43f Fix warnings: eval.c: call_user_func(): Out of bounds: FP.
Problem    : Out-of-bound array access @ 18429.
Diagnostic : False positive.
Rationale  : Situation is intentional. `dictitem_T` is a prefix all dict
             items whill share, but actual size of each item will be
             different depending on its key length. `di_key` array field
             is declared of size 1 just to have a field name, but real
             size will vary for each item.
Resolution : Make analyzer ignore it.
             This could be refactored to use C99-allowed variable length
             arrays, but eval.c is bound to dissappear, so no effort is
             done in that sense.
2014-11-18 22:00:02 +01:00
Eliseo Martínez
34a4a01e4e Fix warnings: eval.c: get_user_func_name(): Np dereference: FP.
Problem    : Dereference of null pointer @ 18216.
Diagnostic : False positive.
Rationale  : `hi` and `done` are static. Intended usage is for the first
             call to have idx == 0, so that they are initialized.
Resolution : Assert hi after (optional) initialization.
2014-11-18 22:00:02 +01:00
Eliseo Martínez
eb15d8777b Fix warnings: eval.c: clear_tv(): Bad free: RI.
Problem    : Bad free @ 16076.
Diagnostic : Real issue.
Rationale  : A non-allocated string is set at 4127, which later on can
             be tried to be freed if aborting.
Resolution : Detect particular case (func with empty name) and don't
             free in that case.
             Another solution (use allocated string) was tried before,
             but it produced a leak difficult to solve.
             Finally applied solution works, but it produces a new false
             positive warning (Np dereference at 13763), deactivated by
             `assert(ptrs[i].item->li_next)`.
2014-11-18 22:00:01 +01:00
Eliseo Martínez
ece19651c6 Fix warnings: eval.c: item_compare(): Garbage value: MI.
Problem    : Result of operation is garbage or undefined @ 13565.
Diagnostic : Multithreading issue.
Rationale  : Problem occurs only if global (static) variable
             `item_compare_keep_zero` changes after being used by
             `do_sort_uniq` but before being used by `item_compare` or
             `item_compare2`.
Resolution : This is not an intra-function problem, as other MI's
             before, but rather an inter-function one. Thus, it can't be
             solved by using local copy of global. Therefore, we are
             forced to do a bit refactoring. We can't simply add a bool
             param to item_compare/item_compare2, as they couldn't be
             passed to qsort() that way. So, item_compare/item_compare2
             are added a bool param and curried versions of them are
             added and used in their place.
2014-11-18 21:57:49 +01:00
Eliseo Martínez
be90cdf4f9 Fix warnings: eval.c: dictitem_alloc(): Out-of-bounds access: FP.
Problem    : Out-of-bound array access @ 5737.
Diagnostic : False positive.
Rationale  : Situation is intentional. `dictitem_T` is a prefix all dict
             items whill share, but actual size of each item will be
             different depending on its key length. `di_key` array field
             is declared of size 1 just to have a field name, but real
             size will vary for each item.
Resolution : Make analyzer ignore it.
             This could be refactored to use C99-allowed variable length
             arrays, but eval.c is bound to dissappear, so no effort is
             done in that sense.
2014-11-18 21:57:48 +01:00
Eliseo Martínez
d3f413ba6a Fix warnings: eval.c: set_var_lval(): Np dereference: FP.
Problem    : Dereference of null pointer @ 2273.
Diagnostic : False positive.
Rationale  : Suggested error would happen when assigning an rvalue with
             more items than the lvalue. Then we would enter conditional
             at:
             ```
             if (lp->ll_li->li_next == NULL) {
               /* Need to add an empty item. */
               list_append_number(lp->ll_list, 0);
             }
             lp->ll_li = lp->ll_li->li_next;
             ```
             Analyzer thinks the value assigned to lp->ll_li is still
             NULL and is hit on the next iteration.
Resolution : Assert lp->ll_li->li_next is not null anymore after
             list_append_number().
2014-11-18 21:57:48 +01:00
Thiago de Arruda
17a4bfe007 Remove os/provider.{c,h} and all of its references 2014-11-18 07:56:58 -03:00
Thiago de Arruda
375db3b19a eval/ex_cmds2/ops: Implement providers with eval_call_provider
Replace references to provider_call/provider_has with the new functions
eval_call_provider/eval_has_provider.
2014-11-18 07:56:58 -03:00
Thiago de Arruda
268b2eff4a eval: Add eval_call_provider/eval_has_provider functions
These use autoloaded vimscript to replace the provider_call/provider_has
functions, moving the implementation of providers to pure vimscript(we lose
nothing since vimscript can also call msgpack-rpc functions).

When calling the rpcrequest function from a provider, temporarily switch to the
caller scope. This is required for compatibility with legacy plugins, because
they may depend on scope information that changes when "leaving" the C stack to
enter the vimscript stack.
2014-11-18 07:56:58 -03:00
Justin M. Keyes
7465fc6ee9 Merge pull request #1471 from splinterofchaos/fix-jobstart
jobstart: Check prg arguments for NULL.
2014-11-15 17:10:47 -05:00
Scott Prager
fa74c1ea71 jobstart: Check prg arguments for NULL. 2014-11-13 19:21:49 -05:00
Scott Prager
96be11f609 vim-patch:7.4.419
Problem:    Whan part of a list is locked it's possible to make changes.
Solution:   Check if any of the list items is locked before make a change.
            (ZyX)

https://code.google.com/p/vim/source/detail?r=v7-4-419
2014-11-11 12:05:51 -05:00
Thiago de Arruda
ab826d88f6 eval: Return an empty list from systemlist() when there's no output
This is the behavior on vim's `systemlist()`.
2014-11-10 18:47:03 -03:00
Scott Prager
fd36dc208e job: Let vimL jobsend() accept a list.
Use save_tv_as_string(), same as vimL system(). This also makes
jobsend() more liberal in what it can accept. For example,
`jobsend(j, 123)` is now valid.

Closes #1176
2014-11-07 13:34:56 -03:00
Scott Prager
e90973e035 job: Make v:job_data[2] a list.
Factor out string_to_list() from f_system()'s implementation
and use that to set job_data. This has the technical advantage of
preserving NULs, and may be more convenient for users.

Required for #1176.
2014-11-07 13:34:56 -03:00
Scott Prager
37cbafa5bb job: Read job data line-wise.
Only read up to the last newline in push_job_event().
2014-11-07 13:34:56 -03:00
Eliseo Martínez
e7a863e12c Remove long_u: eval: Replace with size_t.
Note: No effort is done on refactoring anything in eval module, as it
      will be eventually dropped.
2014-11-06 22:19:33 +01:00
Nicolas Hillegeer
8c5efd62ac iconv: re-enable
This seems to have been disabled in the transition from vim to neovim,
re-enable it.
2014-11-06 00:18:26 +01:00
Thiago de Arruda
a1dd70b1d0 event: Reintroduce the immediate event queue
Commit @264e0d872c("Remove automatic event deferral") removed the immediate
event queue because event deferral now had to be explicit. The problem is that
while some events don't need to be deferred, they still can result in recursive
`event_poll` calls, and recursion is not supported by libuv. Examples of those
are msgpack-rpc requests while a server->client request is pending, or signals
which can call `mch_exit`(and that will result in `uv_run` calls).

To fix the problem, this reintroduces the immediate event queue for events that
can potentially result in event loop recursion. The non-deferred events are
still processed in `event_poll`, but only after `uv_run` returns.
2014-11-02 16:47:50 -03:00
Thiago de Arruda
c92d17b4aa job: Let job_start callers to selectively ignore stdio
Passing NULL as the callback for stdout/stderr will result in job_start ignoring
stdout/stderr, respectively. A 'writable' boolean argument was also added, and
when false `job_start` will ignore stdin.

Also, refactor os_system to allow passing NULL as the `output` argument.
2014-10-31 22:52:10 -03:00
Justin M. Keyes
181e652ee1 Merge pull request #1312 from GokuITA/coverity1289
coverity/71507: Unchecked return value (CHECKED_RETURN)
2014-10-30 02:12:28 -04:00
Thiago de Arruda
94f59fc9be api: Implement vim_command_output function
This function can be used by API clients to execute a command and capture the
output.
2014-10-28 23:12:41 -04:00
Scott Prager
d10e83fec2 job/valgrind: Fix invalid reads/missing free.
The JobEvent structure may refer to a job after it has been freed. Apply
@tarruda's patch to extract the job data before pushing the event.

Also, fix the type, "data" -> "job", in on_job_exit() and free the job
name in the last job event.
2014-10-28 14:09:28 -03:00
Thiago de Arruda
72f028abcb eval: Defer execution of JobActivity autocommands
JobActivity autocommands run vimscript and must be executed on Nvim main loop.
Since the previous commit removed automatic calls to `event_push` on RStream/Job
callbacks, this adds it back, but in eval.c where job control is implemented.
2014-10-21 11:05:49 -03:00
Thiago de Arruda
b280308ac6 msgpack-rpc: Create subdirectory for msgpack-rpc modules
Create the msgpack_rpc subdirectory and move all modules that deal with
msgpack-rpc to it. Also merge msgpack_rpc.c into msgpack_rpc/helpers.c
2014-10-21 11:05:49 -03:00
Victor Fonseca
1be1964f34 coverity/71507: Unchecked return value (CHECKED_RETURN)
Don't check for err->set since object_to_vim always return false when error is set
2014-10-20 11:01:25 -02:00
Thiago de Arruda
68de5d79a2 rstream: Extract some RStream functionality to RBuffer
RBuffer instances represent the internal buffer used by RStreams.

This changes RStream constructor to receive RBuffer pointers and adds a set of
RBuffer methods that expose the lower level buffer manipulation to consumers of
the RStream API.
2014-10-18 08:42:49 -03:00
Justin M. Keyes
5e65e3eae0 Merge pull request #1208 from war1025/dev/remove_for_all_windows
Remove FOR_ALL_WINDOWS and replace with FOR_ALL_WINDOWS_IN_TAB(curtab)
2014-10-03 13:44:50 -04:00
Thiago de Arruda
ba1026c2c7 eval: Fix save_tv_as_string to handle non-string types 2014-10-01 21:42:00 -03:00
Scott Prager
01fc01e5d6 Implement save_tv_as_string to assist in #1176. 2014-09-30 20:53:26 -04:00
Scott Prager
3928acb032 Fix system() output truncation bug.
Replace NULs with SOH to restore the old behaviour of get_cmd_output().
2014-09-30 19:35:47 -04:00
Scott Prager
b0bda2ee87 vim-patch:7.4.256
Problem:    Using systemlist() may cause a crash and does not handle NUL
            characters properly.
Solution:   Increase the reference count, allocate memory by length. (Yasuhiro
            Matsumoto)

https://code.google.com/p/vim/source/detail?r=v7-4-256
2014-09-30 19:35:46 -04:00
Scott Prager
78979427d1 Return list from rettv_list_alloc. 2014-09-30 19:35:46 -04:00
Scott Prager
566ce93135 vim-patch:7.4.248
Problem:    Cannot distinguish between NL and NUL in output of system().
Solution:   Add systemlist(). (ZyX)

https://code.google.com/p/vim/source/detail?r=v7-4-248
2014-09-30 19:35:46 -04:00
Scott Prager
d3cd3d2b8f vim-patch:7.4.247
Problem:    When passing input to system() there is no way to keep NUL and
            NL characters separate.
Solution:   Optionally use a list for the system() input. (ZyX)

https://code.google.com/p/vim/source/detail?r=v7-4-247

Implement write_list_to_string() as well since write_list() only works
on files.
2014-09-30 19:35:46 -04:00
Wayne Rowcliffe
9b6f192693 Replace FOR_ALL_WINDOWS with FOR_ALL_WINDOWS_IN_TAB(curtab) 2014-09-24 19:00:50 -05:00
André Twupack
1a7c83d77d vim-patch:7.4.411
Problem:    "foo bar" sorts before "foo" with sort(). (John Little)
Solution:   Avoid putting quotes around strings before comparing them.

https://code.google.com/p/vim/source/detail?r=v7-4-411
2014-09-22 21:38:48 +02:00
Wayne Rowcliffe
683bc797a0 FOR_ALL_WINDOWS_IN_TAB and local variables in FOR_ALL_TAB_WINDOWS 2014-09-22 09:31:09 -05:00
Wayne Rowcliffe
b4ec6c1a4b FOR_ALL_TABS helper 2014-09-22 09:26:40 -05:00
Justin M. Keyes
0ed9f3ec83 Merge pull request #1197 from Shougo/vim-patch-7.4.392
vim-patch:7.4.392
2014-09-20 18:57:10 -04:00
Thiago de Arruda
4a8b52ea08 api/msgpack-rpc: Improve error infrastructure
- Add error type information to `Error`
- Rename `set_api_error` to `api_set_error` for consistency with other api_*
  functions/macros.
- Refactor the api_set_error macro to accept formatted strings and error types
- Improve error messages
- Wrap error messages with gettext macro
- Refactor msgpack-rpc serialization to transform Error instances into [type,
  message] arrays
- Add error type information to API metadata
- Normalize nvim->client and client->nvim error handling(change
  channel_send_call to accept an Error pointer instead of the `errored` boolean
  pointer)
- Use macro to initialize Error structures
2014-09-18 21:30:31 -03:00
Shougo Matsushita
b57d6ef09a vim-patch:7.4.392
Problem:    Not easy to detect type of command line window.
Solution:   Add the getcmdwintype() function. (Jacob Niehus)

https://code.google.com/p/vim/source/detail?r=v7-4-392
2014-09-18 20:44:36 +09:00
Justin M. Keyes
a447160a6c Merge pull request #953 from splinterofchaos/patch235-exepath
vim-patch:7.4.235
2014-09-17 01:28:35 -04:00
Scott Prager
9445eaa297 vim-patch:7.4.235
Problem:    It is not easy to get the full path of a command.
Solution:   Add the exepath() function.

https://code.google.com/p/vim/source/detail?r=5ab2946f7ce560985830fbc3c453bb0f7a01f385
2014-09-17 01:00:24 -04:00
Damián Silvani
e32d338c87 vim-patch:7.4.313
Problem:    Changing the return value of getpos() causes an error.  (Jie Zhu)
Solution:   Revert getpos() and add getcurpos().

https://code.google.com/p/vim/source/detail?r=332a5c2b2956d9b18d85268a724d01deea27ec83
2014-09-16 23:35:12 -03:00
Damián Silvani
27f423e734 vim-patch:7.4.310
Problem:    getpos()/setpos() don't include curswant.
Solution:   Add a fifth number when getting/setting the cursor.

https://code.google.com/p/vim/source/detail?r=ccac0aa34eeaf46dad4b831461a532fc3fe71096
2014-09-16 22:43:40 -03:00
Justin M. Keyes
3b7b79e37d Merge pull request #1140 from atwupack/vp-7.4.341
vim-patch:7.4.341, 7.4.347, 7.4.351, 7.4.358
2014-09-15 14:08:55 -04:00
Thiago de Arruda
037ca796a0 eval.c: Rename has('neovim') feature to has('nvim')
To follow the convention of 'nvim' for technical references
2014-09-15 08:21:31 -03:00