diff options
author | HiPhish <hiphish@Aleksandars-iMac.local> | 2016-04-26 18:10:36 +0200 |
---|---|---|
committer | HiPhish <hiphish@Aleksandars-iMac.local> | 2016-04-27 18:53:00 +0200 |
commit | f644d8d88e621ab11dcb831b3cee6c5ea1df24b2 (patch) | |
tree | 7c3f56f56512401015b5727b1335cd767f8ccb41 /src/nvim/ex_docmd.h | |
parent | 6bb4b9f57f5011db0c895370e00f2351422a2c25 (diff) | |
download | rneovim-f644d8d88e621ab11dcb831b3cee6c5ea1df24b2.tar.gz rneovim-f644d8d88e621ab11dcb831b3cee6c5ea1df24b2.tar.bz2 rneovim-f644d8d88e621ab11dcb831b3cee6c5ea1df24b2.zip |
Fix coverity errors in haslocaldir() and getcwd.
The Vim function `haslocaldir()` would crash if the users called it with
the two arguments `-1, -1`. Now it returns `0` in that case.
The coverity issue was complaining about a NULL dereference, but there
can never be a case where the pointer `tp` is NULL and being
dereferenced. An assertion has been put in place to satisfy coverity.
Furthermore the functions themselves have been cleaned up. First of all
the documentation comment for the different scopes has been extended and
a macro for the minimum scope has been introduced. In both functions any
time a scope is used as a range (e.g. in a loop) macros instead of
actuals scopes are used, that makes the functions more robust if new
scopes are added.
Second, in the implementation of `getcwd()` there was a superfluous
loop, it has been removed completely. I also changed all `goto end` to
plaing `return` statements by moving the allocation of `cwd` down, that
way there is no need for `goto` anymore.
Diffstat (limited to 'src/nvim/ex_docmd.h')
-rw-r--r-- | src/nvim/ex_docmd.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/nvim/ex_docmd.h b/src/nvim/ex_docmd.h index 7af3ee233c..dbfc64e2f1 100644 --- a/src/nvim/ex_docmd.h +++ b/src/nvim/ex_docmd.h @@ -19,16 +19,18 @@ #define EXMODE_NORMAL 1 #define EXMODE_VIM 2 -/// The scope of a command. +/// The scope of a working-directory command like `:cd`. /// -/// The lower a number, the deeper the scope. +/// Scopes are enumerated from lowest to highest. When adding a scope make sure +/// to update all functions using scopes as well, such as the implementation of +/// `getcwd()`. When using scopes as limits (e.g. in loops) don't use the scopes +/// directly, use `MIN_CD_SCOPE` and `MAX_CD_SCOPE` instead. typedef enum { kCdScopeWindow, ///< Affects one window. kCdScopeTab, ///< Affects one tab page. - kCdScopeGlobal, ///< Affects the entire instance of NeoVim. + kCdScopeGlobal, ///< Affects the entire instance of Neovim. } CdScope; - -/// Last `:cd` scope defined. +#define MIN_CD_SCOPE kCdScopeWindow #define MAX_CD_SCOPE kCdScopeGlobal #ifdef INCLUDE_GENERATED_DECLARATIONS |