Commit Graph

149 Commits

Author SHA1 Message Date
Jurica Bradaric
ee56470157 vim-patch:7.4.704
Problem:    Searching for a character matches an illegal byte and causes
            invalid memory access. (Dominique Pelle)
Solution:   Do not match an invalid byte when search for a character in a
            string.  Fix equivalence classes using negative numbers, which
            result in illegal bytes.

d82a2a990b
2016-01-24 09:15:30 +01:00
Jurica Bradaric
f583e51209 vim-patch:7.4.685
Problem:    When there are illegal utf-8 characters the old regexp engine may
            go past the end of a string.
Solution:   Only advance to the end of the string. (Dominique Pelle)

0e462411ca
2016-01-23 13:57:07 +01:00
Michael Ennen
39ef219535 vim-patch:7.4.714
Problem:    Illegal memory access when there are illegal bytes.
Solution:   Check the byte length of the character. (Dominique Pelle)

069dd08d8d
2016-01-13 16:52:44 -07:00
Marco Hinz
3df37a8424 vim-patch:7.4.776 #3062
Problem:  Equivalence class for 'd' does not work correctly.
Solution: Fix 0x1e0f and 0x1d0b. (Dominique Pelle)

Original patch:
  https://code.google.com/p/vim/source/detail?r=94b17958585153641ad1e813fa144cad57c7170f
2015-08-09 21:09:28 -04:00
Michael Reed
4f444ae4f8 Remove POSIX 'cpoptions': '\' 2015-07-19 15:14:22 -04:00
cztchoice
c80ebfff82 vim-patch:7.4.736 #2998
Problem:    Invalid memory access.
Solution:   Avoid going over the end of a NUL terminated string. (Dominique
            Pelle)

https://github.com/vim/vim/commit/v7-4-736
2015-07-11 22:38:17 -04:00
David Bürgin
f04bc91c2f vim-patch:7.4.593 #2657
Problem:    Crash when searching for "x\{0,90000}". (Dominique Pelle)
Solution:   Bail out from the NFA engine when the max limit is much higher
            than the min limit.

https://github.com/vim/vim/commit/v7-4-593

See https://groups.google.com/d/msg/vim_dev/c7owwoseba8/ZETgSNZ6p10J
2015-06-13 21:38:39 -04:00
Michael Reed
3c5864772f Remove char_u: message:smsg() 2015-05-13 15:29:50 -04:00
David Bürgin
83a2a638a9 vim-patch:7.4.526 #2562
Problem:    matchstr() fails on long text. Daniel Hahler)
Solution:   Return NFA_TOO_EXPENSIVE from regexec_nl(). (Christian Brabandt)

https://github.com/vim/vim/commit/v7-4-526

Helped-by: Michael Reed <m.reed@mykolab.com>
2015-05-07 00:26:07 -04:00
David Bürgin
b3519ca73b vim-patch:7.4.519
Problem:    Crash when using syntax highlighting.
Solution:   When regprog is freed and replaced, store the result.

https://github.com/vim/vim/tree/v7-4-519

Helped-by: Scott Prager <splinterofchaos@gmail.com>
2015-04-27 01:41:42 -04:00
Felipe Oliveira Carvalho
2ca8afc74e Replace vim_isxdigit() with to ascii_isxdigit() defined in ascii.h 2015-04-24 20:37:13 -03:00
Felipe Oliveira Carvalho
caabcae0b7 Replace VIM_ISDIGIT() and vim_isdigit() with ascii_isdigit() defined in ascii.h 2015-04-24 20:37:13 -03:00
Felipe Oliveira Carvalho
93bf201119 Replace vim_iswhite with ascii_iswhite() defined in ascii.h 2015-04-24 20:37:13 -03:00
Thiago de Arruda
34c48aaf12 memory: Add free wrapper and refactor project to use it
We already use wrappers for allocation, the new `xfree` function is the
equivalent for deallocation and provides a way to fully replace the malloc
implementation used by Neovim.
2015-04-13 08:22:44 -03:00
David Bürgin
d3bb177f1e vim-patch:7.4.497 #2295
Problem:    With some regexp patterns the NFA engine uses many states and
            becomes very slow.  To the user it looks like Vim freezes.
Solution:   When the number of states reaches a limit fall back to the old
            engine. (Christian Brabandt)

https://github.com/vim/vim/releases/tag/v7-4-497

Helped-by: David Bürgin <676c7473@gmail.com>
Helped-by: Justin M. Keyes <justinkz@gmail.com>
Helped-by: Scott Prager <splinterofchaos@gmail.com>
2015-04-05 19:24:58 -04:00
Eliseo Martínez
7dd48d7af0 Enable -Wconversion: mark.c.
Refactoring summary:
- MB_STRNICMP: Inlined.
- MB_STRNCMP: Inlined.
2015-02-18 20:54:13 -05:00
Eliseo Martínez
2ceb1c74d5 Remove long_u: regexp: Refactor long_u. 2015-01-19 19:47:28 +01:00
Michael Reed
d86ebc7afb Macro cleanup: PROTO
Regarding dict_lookup() in eval.c: both definitions are the same, the
only difference being the spacing between the indirection operator and
the indentation level.
2015-01-14 15:07:16 -05:00
Eliseo Martínez
7f7262e933 Cleanup: Rename getdigits() family functions. 2015-01-11 21:04:08 +01:00
Eliseo Martínez
04c0658024 Cleanup: Refactor getdigits().
Problem  : getdigits() currently returns a long, but at most places,
           return value is casted (unsafely) into an int. Making casts
           safe would introduce a lot of fuss in the form of assertions
           checking for limits.
Note     : We cannot just change return type to int, because, at some
           places, legitimate long values are used. For example, in
           diff.c, for line numbers.
Solution : Introduce new functions:
           - get_digits()      : Gets an intmax_t from a string.
           - get_int_digits()  : Wrapper for ints.
           - get_long_digits() : Wrapper for longs.
           And replace getdigits() invocations by the appropiate
           wrapper invocations.
2015-01-11 17:18:39 +01:00
Felipe Oliveira Carvalho
3c857900fe Define and use the ARRAY_SIZE macro
A similar macro is defined in the Linux kernel [1].

To refactor the code I used a slightly modified Coccinelle script I found in
[2].

```diff
// Use the macro ARRAY_SIZE when possible
//
// Confidence: High
// Copyright: (C) Gilles Muller, Julia Lawall, EMN, DIKU.  GPLv2.
// URL: http://www.emn.fr/x-info/coccinelle/rules/array.html
// Options: -I ... -all_includes can give more complete results

@@
type T;
T[] E;
@@

- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)

@@
type T;
T[] E;
@@

- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)

@@
type T;
T[] E;
@@

- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)

@n@
identifier AS,E;
@@

- #define AS(E) ARRAY_SIZE(E)

@@
expression E;
identifier n.AS;
@@

- AS(E)
+ ARRAY_SIZE(E)
```

`spatch --in-place --sp-file array_size.cocci -I src/ -I build/include/ -I build/src/nvim/auto/ src/nvim/*.c`

[1] http://lxr.free-electrons.com/source/include/linux/kernel.h#L54
[2] http://www.emn.fr/z-info/coccinelle/rules/#macros
2014-12-18 15:41:37 -03:00
Felipe Oliveira Carvalho
77135447e0 Reduce indentation level by early returning or continuing loop
Replace code like this

```c
func() {
    if (cond) {
	...
	...
	...
    }
    return ret;
}
```

```c
for (...) {
    if (cond) {
	...
	...
	...
    }
}
```

with

```c
func() {
    if (!cond) {
	return ret;
    }
    ...
    ...
    ...
}
```

```c
for (...) {
    if (!cond) {
	continue;
    }
    ...
    ...
    ...
}
```
2014-12-13 23:36:11 -03:00
Scott Prager
ca7c509ae0 vim-patch:7.4.437
Problem:    New and old regexp engine are not consistent.
Solution:   Also give an error for "\ze*" for the old regexp engine.

https://code.google.com/p/vim/source/detail?r=v7-4-437
2014-11-13 11:38:19 -05:00
Eliseo Martínez
997c0b3939 Fix warnings: regexp.c: match_with_backref(): Nonnull violation: FP.
Problem: Argument with 'nonnull' attribute passed null @ 5632.
         http://neovim.org/doc/reports/clang/report-041a0e.html#EndPath.

Diagnostic: False positive.
Rationale : `p = reg_getline(clnum)` above should not be null, because
            `clnum` starts at `start_lnum` and only increments after
            that.
Resolution: Assert p not null.
2014-11-06 09:51:45 +01:00
Eliseo Martínez
22475b5ae8 Fix warnings: regexp.c: br_regcomp(): Np dereference: MI.
Problem: Dereference of null pointer @ 1312.
         http://neovim.org/doc/reports/clang/report-b1d09a.html#EndPath

Diagnostic: Multithreading issue.
Rationale : Suggested error path contains two succesive calls to
            `regnext(scan)`, first of which returning nonnull, the
            second one returning null. This can only occur if global
            `reg_toolong` accesed in `regnext()` changes between the
            calls.
Resolution: Use local variable to cache first `regnext(scan)` result.
            Note that this change alters function semantics, as now
            function only issues one call instead of two, reusing the
            result for the second time.
            This shouldn't be a problem, though, as new semantics should
            be in fact be better.
2014-11-06 09:51:44 +01:00
Eliseo Martínez
336aab5eef Fix warnings: regexp.c: skip_regexp: Np dereference: FP.
Problem: Derefence of null pointer @ 1208.
         http://neovim.org/doc/reports/clang/report-24b5ca.html#Path10

Diagnostic: False positive.
Rationale : Error is reported to happen  if after `if (*newp == NULL) {`
            body, `*newp` continues being NULL, and false branch of
            following `if (*newp != NULL)` is taken. Now, `vim_strsave`
            cannot return NULL, so error cannot happen.
Resolution: Remove dead code (leftover since OOM refactors).
2014-11-06 09:51:44 +01:00
André Twupack
e1517d4f53 vim-patch:7.4.360
Problem:    In a regexp pattern a "$" followed by \v or \V is not seen as the
            end-of-line.
Solution:   Handle the situation. (Ozaki Kiichi)

https://code.google.com/p/vim/source/detail?r=v7-4-360
2014-09-21 01:08:03 +02:00
Damián Silvani
9ea28e1903 vim-patch:7.4.293
Problem:    It is not possible to ignore composing characters at a
            specific point in a pattern.
Solution:   Add the %C item.

https://code.google.com/p/vim/source/detail?r=10fc95f48546f438648b8357062e93c9c2c0a377
2014-08-14 23:06:52 -03:00
Pavel Platto
f42a4be834 Remove SMALL_MALLOC. Used on MSDOS and WIN16. 2014-08-02 09:17:00 +03:00
Nicolas Hillegeer
db7cd61f62 profiling: implement on top of os_hrtime()
Should be better than gettimeofday() since libuv uses higher resolution
clocks on most UNIX platforms. Libuv also tries to use monotonic clocks,
kernel bugs notwithstanding, which is another win over gettimeofday().

Necessary for Windows, which doesn't have gettimeofday(). In vanilla vim,
Windows uses QueryPerformanceCounter, which is the correct primitive for
this sort of things, but that was removed when slimming up the codebase.
Libuv uses QueryPerformanceCounter to implement uv_hrtime() on Windows so
the behaviour of vim profiling on Windows should now be the same.

The behaviour on Linux should be different (better) though, libuv uses more
accurate primitives than gettimeofday().

Other misc. changes:
- Added function attributes where relevant (const, pure, ...)
- Convert functions to receive scalars: Now that proftime_T is always a
  (uint64_t) scalar (and not a struct), it's clearer to convert the
  functions to receive it as such instead of a pointer to a scalar.
- Extract profiling funcs to profile.c: make everything clearer and reduces
  the size of the "catch-all" ex_cmds2.c
- Add profile.{c,h} to clint and -Wconv:
  - Don't use sprintf, use snprintf
  - Don't use long, use int16_t/int32_t/...
2014-07-16 17:12:34 +02:00
Pavel Platto
47084ea765 Use strict function prototypes #945
`-Wstrict-prototypes` warn if a function is declared or defined without
specifying the argument types.

This warning disallow function prototypes with empty parameter list.
In C, a function declared with an empty parameter list accepts an
arbitrary number of arguments when being called. This is for historic
reasons; originally, C functions didn't have prototypes, as C evolved
from B, a typeless language. When prototypes were added, the original
typeless declarations were left in the language for backwards
compatibility.
Instead we should provide `void` in argument list to state
that function doesn't have arguments.

Also this warning disallow declaring type of the parameters after the
parentheses because Neovim header generator produce no declarations for
old-stlyle prototypes: it expects to find `{` after prototype.
2014-07-14 20:28:40 +02:00
oni-link
3e8314abaa vim-patch:7.4.291 #879
Problem:    Compiler warning for int to pointer of different size when DEBUG
            is defined.
Solution:   use smsg() instead of EMSG3().

https://code.google.com/p/vim/source/detail?r=b5972833add9de714f4651e26fd9ea63ec4a880c
2014-07-11 16:29:21 -04:00
Brandon Coleman
bf219e1442 move <inttypes.h> include out of vim.h 2014-07-09 00:18:19 +02:00
Brandon Coleman
82b71a3056 move ascii.h include out of vim.h 2014-07-09 00:18:18 +02:00
Brandon Coleman
a4f441e547 remove stdbool.h include from vim.h and globals.h 2014-07-09 00:18:17 +02:00
Felipe Oliveira Carvalho
5ed74cfb7c Introduce ga_append_via_ptr() and GA_APPEND_VIA_PTR()
Similar to GA_APPEND(). Replaces this pattern:

    ga_grow(&ga, 1);
    item_type *p = ((item_type *)ga.ga_data) + ga.ga_len;
    p->field1 = v1;
    p->field2 = v2;
    ga.ga_len++;
2014-06-30 03:57:50 -04:00
Felipe Oliveira Carvalho
be3a4b6ca8 ga_growsize should be >= 1
I know it could be 0 sometimes. Running the tests with
`assert(gap->ga_growsize > 0)` in ga_grow() crashes nvim while running the
tests.

 - Add a setter for ga_growsize that checks whether the value passed is >=1 (log
	 in case it's not)
 - log when ga_grow() tries to use a ga_growsize that's not >=1
 - use GA_EMPTY_INIT_VALUE is many places
2014-06-30 03:57:50 -04:00
Felipe Oliveira Carvalho
8234f2839f No OOM in vim_strsave_escaped[_ext]() 2014-06-16 01:36:31 -03:00
Douglas Schneider
e554ea2036 Replace vim_strncpy calls: regexp.c 2014-06-13 18:08:21 -04:00
oni-link
37fe5aa444 vim-patch:7.4.292 #754
Problem:    Searching for "a" does not match accented "a" with new regexp
            engine, does match with old engine. (David Bürgin)
            "ca" does not match "ca" with accented "a" with either engine.
Solution:   Change the old engine, check for following composing character
            also for single-byte patterns.

https://code.google.com/p/vim/source/detail?r=60cdaa05a6ad31cef55eb6b3dc1f57ecac6fcf79
2014-06-06 18:39:31 -04:00
ZyX
70929f7e16 Add automatic generation of headers
- The 'stripdecls.py' script replaces declarations in all headers by includes to
  generated headers.
  `ag '#\s*if(?!ndef NEOVIM_).*((?!#\s*endif).*\n)*#ifdef INCLUDE_GENERATED'`
  was used for this.
- Add and integrate gendeclarations.lua into the build system to generate the
  required includes.
- Add -Wno-unused-function
- Made a bunch of old-style definitions ANSI

This adds a requirement: all type and structure definitions must be present
before INCLUDE_GENERATED_DECLARATIONS-protected include.

Warning: mch_expandpath (path.h.generated.h) was moved manually. So far it is
the only exception.
2014-06-02 11:04:17 -03:00
Hinidu
a29b94e2f9 Remove FEAT_EVAL
Support for VimScript, :let, :if, etc.
2014-05-28 13:08:54 -04:00
Felipe Oliveira Carvalho
21784aeb00 Replace alloc() with xmalloc() and remove immediate OOM checks 2014-05-19 14:50:23 -03:00
Felipe Oliveira Carvalho
a80d7e86c1 Remove NULL/non-NULL tests after calls to vim_str(n)save() 2014-05-19 14:50:23 -03:00
Felipe Oliveira Carvalho
5209d2271b Replace ga->ga_len == 0 checks with GA_EMPTY(ga)
Used Coccinelle to perform the changes

@@
expression E;
@@

<...
(
// E.ga_len == 0 is isomorphic to !E.ga_len
- E.ga_len == 0
+ GA_EMPTY(&E)
|
- E->ga_len == 0
+ GA_EMPTY(E)
)
...>
2014-05-17 07:02:44 -03:00
Felipe Oliveira Carvalho
b4efff6523 Replace ga->ga_len > 0 checks with !GA_EMPTY(ga)
Used Coccinelle to perform the changes

```diff
@@
expression E;
@@

<...
(
- E.ga_len > 0
+ !GA_EMPTY(&E)
|
- E->ga_len > 0
+ !GA_EMPTY(E)
)
...>
```

`spatch --in-place --sp-file ga_empty.cocci <C_FILE>`
2014-05-17 07:02:44 -03:00
Eliseo Martínez
762a8ad0f3 Introduce nvim namespace: Fix unmasked strings.h issue.
Problem:  Now that nvim/strings.h is correctly namespaced, an issue
          that had been masked until now arises:

          When compiling, we get a lot of errors because of everywhere
          the functions in nvim/strings.h are used, there's no include
          to import them.

          But, how could this compile and work previously, then? It
          turns out that:
          - In every such case, we are also including vim.h, which in
            turn includes os_unix_defs.h.
          - os_unix_defs.h includes <string.h> and also <strings.h> in
            some systems (e.g. OSX).
          - Build had been modified previously to (even when importing
            system headers), prefer equally-named local ones. That was
            in fact done as a previous attempt to solve the same issue
            we are trying to solve another way now.

          So, we were including our "strings.h" as a side-effect of
          including <strings.h> through "vim.h" --> "os_unix_defs.h".

Solution: Correctly include "nvim/strings.h" in every file needing it.
2014-05-15 20:46:02 +02:00
Eliseo Martínez
409cc138f2 Introduce nvim namespace: Fix project-local includes.
Prepend 'nvim/' in all project-local (non-system) includes.
2014-05-15 20:46:01 +02:00
Eliseo Martínez
da51dc9cf2 Introduce nvim namespace: Move files.
Move files from src/ to src/nvim/.
- src/nvim/ becomes the new root dir for nvim executable sources.
- src/libnvim/ is planned to become root dir of the neovim library.
2014-05-15 20:46:01 +02:00