diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-02-26 02:43:06 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-02-28 12:48:21 +0100 |
commit | 900e96781f09f5e4d6b89be07391b35fcec1d1f4 (patch) | |
tree | 7ebfe0b25291808ef6d6272679f9f468a3f227bc | |
parent | 89515304e4eb81ff9eb65f3a582136fc658de139 (diff) | |
download | rneovim-900e96781f09f5e4d6b89be07391b35fcec1d1f4.tar.gz rneovim-900e96781f09f5e4d6b89be07391b35fcec1d1f4.tar.bz2 rneovim-900e96781f09f5e4d6b89be07391b35fcec1d1f4.zip |
clint: check env functions
-rwxr-xr-x | src/clint.py | 38 | ||||
-rw-r--r-- | src/nvim/os/pty_process_unix.c | 10 |
2 files changed, 40 insertions, 8 deletions
diff --git a/src/clint.py b/src/clint.py index 34af5d15fd..1ef31820ee 100755 --- a/src/clint.py +++ b/src/clint.py @@ -29,10 +29,10 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -"""Does neovim-lint on c files. +"""Lints C files in the Neovim source tree. The goal of this script is to identify places in the code that *may* -be in non-compliance with neovim style. It does not attempt to fix +be in non-compliance with Neovim style. It does not attempt to fix up these problems -- the point is to educate. It does also not attempt to find all problems, or to ensure that everything it does find is legitimately a problem. @@ -88,7 +88,7 @@ Syntax: clint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...] * [whitespace/braces] { should almost always be at the end of the previous line * [build/include] Include the directory when naming .h files - * [runtime/int] Use int16/int64/etc, rather than the C type. + * [runtime/int] Use int16_t/int64_t/etc, rather than the C type. Every problem is given a confidence score from 1-5, with 5 meaning we are certain of the problem, and 1 meaning it could be a legitimate construct. @@ -1487,6 +1487,37 @@ def CheckMemoryFunctions(filename, clean_lines, linenum, error): '...) instead of ' + function + '...).') +os_functions = ( + ('setenv(', 'os_setenv('), + ('getenv(', 'os_getenv('), + ('_wputenv(', 'os_setenv('), + ('_putenv_s(', 'os_setenv('), + ('putenv(', 'os_setenv('), + ('unsetenv(', 'os_unsetenv('), +) + + +def CheckOSFunctions(filename, clean_lines, linenum, error): + """Checks for calls to invalid functions. + + Args: + filename: The name of the current file. + clean_lines: A CleansedLines instance containing the file. + linenum: The number of the line to check. + error: The function to call with any errors found. + """ + line = clean_lines.elided[linenum] + for function, suggested_function in os_functions: + ix = line.find(function) + # Comparisons made explicit for clarity -- pylint: + # disable=g-explicit-bool-comparison + if ix >= 0 and (ix == 0 or (not line[ix - 1].isalnum() and + line[ix - 1] not in ('_', '.', '>'))): + error(filename, linenum, 'runtime/os_fn', 2, + 'Use ' + suggested_function + + '...) instead of ' + function + '...).') + + # Matches invalid increment: *count++, which moves pointer instead of # incrementing a value. _RE_PATTERN_INVALID_INCREMENT = re.compile( @@ -3370,6 +3401,7 @@ def ProcessLine(filename, file_extension, clean_lines, line, nesting_state, error) CheckPosixThreading(filename, clean_lines, line, error) CheckMemoryFunctions(filename, clean_lines, line, error) + CheckOSFunctions(filename, clean_lines, line, error) for check_fn in extra_check_functions: check_fn(filename, clean_lines, line, error) diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index 9ff0399511..5fdf0e6181 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -157,11 +157,11 @@ static void init_child(PtyProcess *ptyproc) // New session/process-group. #6530 setsid(); - unsetenv("COLUMNS"); - unsetenv("LINES"); - unsetenv("TERMCAP"); - unsetenv("COLORTERM"); - unsetenv("COLORFGBG"); + os_unsetenv("COLUMNS"); + os_unsetenv("LINES"); + os_unsetenv("TERMCAP"); + os_unsetenv("COLORTERM"); + os_unsetenv("COLORFGBG"); signal(SIGCHLD, SIG_DFL); signal(SIGHUP, SIG_DFL); |