1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-31 23:16:43 +02:00
Commit graph

402 commits

Author SHA1 Message Date
Christian Brabandt
220474d239
patch 9.1.0608: Coverity warns about a few potential issues
Problem:  Coverity warns about a few potential issues
Solution: Fix those issues (see details below)

1) Fix overflow warning in highlight.c
   This happens because we are comparing int with long
   and assign a potential long value to an int, which
   could cause an overflow. So add some casts to ensure
   the value fits into an int.

2) Fix Overflow warning in shift_line().
   This happens because we are performing a division/modulo
   operation of a long type by an int type and assign the result
   to an int, which could then overflow. So before performing
   the operation, trim the long to value to at most max int value,
   so that it can't overflow.

3) Fix overflow warning in syn_list_cluster in syntax.c
   This is essential the same issue as 1)

4) not checking the return value of vim_mkdir() in spellfile.c
   Creating the spell directory could fail. Handle this case
   and return early in this case.

5) qsort() may deref a NULL pointer when fuzzy match does not
   return a result. Fix this by checking that the accessed growarray
   fuzzy_indices actually contains  data. If not we can silently skip
   the qsort() and related logic.

closes: 

Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-07-20 13:26:44 +02:00
Christian Brabandt
22105fd1fe
patch 9.1.0589: vi: d{motion} and cw work differently than expected
Problem:  vi: d{motion} and cw command work differently than expected
Solution: add new cpo-z flag to make the behaviour configurable

There are two special vi compatible behaviours (or should I say bugs?):

1): cw behaves differently than dw. That is, because cw is special cased
    by Vim and is effectively aliased to ce.
    POSIX behaviour is documented here:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html#tag_20_152_13_81

2): d{motion} may make the whole delete operation linewise, if the start
    and end of the motion are on different lines and there are only
    blanks before the start and after the end of the motion.
    Did not find a related POSIX link that requires this behaviour.

Both behaviours can be considered inconsistent, but we cannot easily
change it, because it would be a backward incompatible change and also
incompatible to how classic vi behaved.

So let's add the new cpo flag "z", which when not included fixes both
behaviours and make them more consistent to what users would expect.

This has been requested several times:
https://groups.google.com/d/msg/vim_use/aaBqT6ECkA4/ALf4odKzEDgJ
https://groups.google.com/d/msg/vim_dev/Dpn3xtUF16I/T6JcOPKN6usJ
http://www.reddit.com/r/vim/comments/26nut8/why_does_cw_work_like_ce/
https://groups.google.com/d/msg/vim_use/vunNWLFWfQg/MmJh_ZGaAgAJ
https://github.com/vim/vim/issues/4390

So in summary, if you want to have the w motion work more consistent,
remove the 'z' from the cpo settings.

related: 
closes: 

Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-07-15 20:51:11 +02:00
distobs
25ac6d67d9
patch 9.1.0537: signed number detection for CTRL-X/A can be improved
Problem:  signed number detection for CTRL-X/A can be improved
          (Chris Patuzzo)
Solution: Add the new "blank" value for the 'nrformat' setting. This
          will make Vim assume a signed number only if there is a blank
          in front of the sign.
          (distobs)

fixes: 
closes: 

Signed-off-by: distobs <cuppotatocake@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-07-06 17:55:26 +02:00
Christian Brabandt
1fb9eae579
patch 9.1.0477: block_editing errors out when using <enter>
Problem:  block_editing errors out when using <enter>
          (Ali Rizvi-Santiago, after v9.1.0274)
Solution: Change ins_len from size_t to int so that the test
          if ins_len is negative actually works properly

Add a test, so that this doesn't regress.

fixes: 

Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-06-11 20:37:59 +02:00
Christian Brabandt
7737ce519b
patch 9.1.0458: Coverity complains about division by zero
Problem:  Coverity complains about division by zero
Solution: Check explicitly for sw_val being zero

Shouldn't happen, since tabstop value should always be larger than zero.
So just add this as a safety measure.

Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-06-02 16:04:43 +02:00
Gary Johnson
88d4f255b7
patch 9.1.0456: Left shift is incorrect with vartabstop and shiftwidth=0
Problem:  Left shift is incorrect with vartabstop and shiftwidth=0
Solution: make tabstop_at() function aware of shift direction
          (Gary Johnson)

The problem was that with 'vartabstop' set and 'shiftwidth' equal 0,
left shifts using << were shifting the line to the wrong column.  The
tabstop to the right of the first character in the line was being used
as the shift amount instead of the tabstop to the left of that first
character.

The reason was that the tabstop_at() function always returned the value
of the tabstop to the right of the given column and was not accounting
for the direction of the shift.

The solution was to make tabstop_at() aware of the direction of the
shift and to choose the tabtop accordingly.

A test was added to check this behavior and make sure it doesn't
regress.

While at it, also fix a few indentation/alignment issues.

fixes: 
closes: 

Signed-off-by: Gary Johnson <garyjohn@spocom.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-06-01 20:51:33 +02:00
Mike Williams
16b63bd002
patch 9.1.0455: MS-Windows: compiler warning for size_t to int conversion
Problem:  MS-Windows: compiler warning for size_t to int conversion
Solution: Add a few type casts to resolve warning on Windows
          (Mike Williams)

closes: 

Signed-off-by: Mike Williams <mrmrdubya@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-06-01 11:33:40 +02:00
zeertzjq
52a6f34887
patch 9.1.0430: getregionpos() doesn't handle one char selection
Problem:  getregionpos() doesn't handle one char selection.
Solution: Handle startspaces differently when is_oneChar is set.
          Also add a test for an exclusive charwise selection with
          multibyte chars (zeertzjq)

closes: 

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-05-22 16:42:44 +02:00
zeertzjq
c95e64f41f
patch 9.1.0423: getregionpos() wrong with blockwise mode and multibyte
Problem:  getregionpos() wrong with blockwise mode and multibyte.
Solution: Use textcol and textlen instead of start_vcol and end_vcol.
          Handle coladd properly (zeertzjq).

Also remove unnecessary buflist_findnr() in add_regionpos_range(), as
getregionpos() has already switched buffer.

closes: 

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-05-20 14:00:31 +02:00
Christian Brabandt
d5c8c0920e
patch 9.1.0399: block_editing errors out when using del
Problem:  block_editing errors out when using del
          (@Jamarley)
Solution: Change ins_len from size_t to int and
          properly check that it doesn't become negative

There is a check in os.c that verifies that `ins_len` does not become
negative:
```
if (pre_textlen >= 0 && (ins_len = len - pre_textlen - offset) > 0)
```
However this only works, if ins_len can actually become negative and
unfortunately, ins_len has been declared as `size_t` so instead of
becoming negative it will wrap around and be very large.

So let's define it as integer, after which the condition above
properly catches this condition.

fixes: 
closes: 

Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-05-08 22:17:19 +02:00
John Marriott
38b9f45253
patch 9.1.0373: ops.c code uses too many strlen() calls
Problem:  ops.c code uses too many strlen() calls
Solution: Refactor code and remove more strlen() calls
          (John Marriott)

closes: 

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-04-25 21:39:18 +02:00
Mike Williams
aca8f55596
patch 9.1.0274: MS-Windows: a few compiler warnings
Problem:  MS-Windows: a few compiler warnings
Solution: Change variable types to resolve compiler warnings
          (Mike Williams)

Windows compiles were reporting a few size_t to signed integer
conversion warnings that can be resolved by changing the variable
declarations to be size_t to start with.

closes: 

Signed-off-by: Mike Williams <mrmrdubya@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-04-07 18:26:22 +02:00
zeertzjq
8c55d60658
patch 9.1.0177: Coverity reports dead code
Problem:  Coverity reports dead code.
Solution: Remove the dead code. Also fix a mistake in ml_get_pos_len()
          and update some comments (zeertzjq).

closes: 

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-03-13 20:42:26 +01:00
zeertzjq
94b7c3233e
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem:  More code can use ml_get_buf_len() instead of STRLEN().
Solution: Change more STRLEN() calls to ml_get_buf_len().  Also do not
          set ml_line_textlen in ml_replace_len() if "has_props" is set,
          because "len_arg" also includes the size of text properties in
          that case. (zeertzjq)

closes: 

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-03-12 21:50:32 +01:00
zeertzjq
048761bcd4
patch 9.1.0132: "C" doesn't include composing chars with 'virtualedit'
Problem:  using "C" and 've=all' set, doesn't include composing chars
          when changing a line, keeps the composing chars for whatever
          is typed afterwards.
Solution: Use mb_head_off() and mb_ptr2len() instead of mb_tail_off().
          (zeertzjq)

closes: 

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-02-24 14:21:39 +01:00
Shougo Matsushita
3f905ab3c4
patch 9.1.0120: hard to get visual region using Vim script
Problem:  hard to get visual region using Vim script
Solution: Add getregion() Vim script function
          (Shougo Matsushita, Jakub Łuczyński)

closes: 
closes: 

Co-authored-by: =?UTF-8?q?Jakub=20=C5=81uczy=C5=84ski?= <doubleloop@o2.pl>
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-02-21 00:02:45 +01:00
glepnir
bd1232a1fa
patch 9.1.0101: upper-case of German sharp s should be U+1E9E
Problem:  upper-case of ß should be U+1E9E (CAPITAL LETTER SHARP S)
          (fenuks)
Solution: Make gU, ~ and g~ convert the U+00DF LATIN SMALL LETTER SHARP S (ß)
          to U+1E9E LATIN CAPITAL LETTER SHARP S (ẞ), update tests
          (glepnir)

This is part of Unicode 5.1.0 from April 2008, so should be fairly safe
to use now and since 2017 is part of the German standard orthography,
according to Wikipedia:
https://en.wikipedia.org/wiki/Capital_%E1%BA%9E#cite_note-auto-12

There is however one exception: UnicodeData.txt for U+00DF
LATIN SMALL LETTER SHARP S does NOT define U+1E9E LATIN CAPITAL LETTER
SHARP S as its upper case version. Therefore, toupper() won't be able
to convert from lower sharp s to upper case sharp s (the other way
around however works, since U+00DF is considered the lower case
character of U+1E9E and therefore tolower() works correctly for the
upper case version).

fixes: 
closes: 

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-02-12 22:39:40 +01:00
Keith Thompson
184f71cc68
patch 9.1.0006: is*() and to*() function may be unsafe
Problem:  is*() and to*() function may be unsafe
Solution: Add SAFE_* macros and start using those instead
          (Keith Thompson)

Use SAFE_() macros for is*() and to*() functions

The standard is*() and to*() functions declared in <ctype.h> have
undefined behavior for negative arguments other than EOF.  If plain char
is signed, passing an unchecked value from argv for from user input
to one of these functions has undefined behavior.

Solution: Add SAFE_*() macros that cast the argument to unsigned char.

Most implementations behave sanely for negative arguments, and most
character values in practice are non-negative, but it's still best
to avoid undefined behavior.

The change from  has been omitted, as this has already been
separately fixed in commit ac709e2fc0
(v9.0.2054)

fixes: 
closes: 

Signed-off-by: Keith Thompson <Keith.S.Thompson@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2024-01-04 21:19:04 +01:00
Ernie Rael
fda700cb04
patch 9.0.2138: Overflow logic requires long long
Problem:  Overflow logic requires long long
Solution: Define vimlong_T data type to make life easier
          for porters

closes: 

Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-11-30 18:20:00 +01:00
Ernie Rael
2b0882fa65
patch 9.0.2124: INT overflow detection logic can be simplified
Problem:  INT overflow logic can be simplified
Solution: introduce trim_to_int() function

closes: 

Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-11-23 20:33:05 +01:00
Christian Brabandt
3770574e4a
patch 9.0.2122: [security]: prevent overflow in indenting
Problem:  [security]: prevent overflow in indenting
Solution: use long long and remove cast to (int)

The shiftwidth option values are defined as being long. However, when
calculating the actual amount of indent, we cast down to (int), which
may cause the shiftwidth value to become negative and later it may even
cause Vim to try to allocate a huge amount of memory.

We already use long and long long variable types to calculate the indent
(and detect possible overflows), so the cast to (int) seems superfluous
and can be safely removed. So let's just remove the (int) cast and
calculate the indent using longs.

Additionally, the 'shiftwidth' option value is also used when determining
the actual 'cino' options. There it can again cause another overflow, so
make sure it is safe in parse_cino() as well.

fixes: 
closes: 

Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-11-22 22:18:35 +01:00
Christian Brabandt
22a97fc241
patch 9.0.2113: Coverity warns for another overflow in shift_line()
Problem:  Coverity warns for another overflow in shift_line()
Solution: Test for INT_MAX after the if condition, cast integer values
          to (long long) before multiplying.

Signed-off-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: Michael Henry <vim@drmikehenry.com>
Signed-off-by: Ernie Rael <errael@raelity.com>
2023-11-19 10:45:24 +01:00
Christian Brabandt
6bf131888a
patch 9.0.2112: [security]: overflow in shift_line
Problem:  [security]: overflow in shift_line
Solution: allow a max indent of INT_MAX

[security]: overflow in shift_line

When shifting lines in operator pending mode and using a very large
value, we may overflow the size of integer. Fix this by using a long
variable, testing if the result would be larger than INT_MAX and if so,
indent by INT_MAX value.

Special case: We cannot use long here, since on 32bit architectures (or
on Windows?), it typically cannot take larger values than a plain int,
so we have to use long long count, decide whether the resulting
multiplication of the shiftwidth value * amount is larger than INT_MAX
and if so, we will store INT_MAX as possible larges value in the long
long count variable.

Then we can safely cast it back to int when calling the functions to set
the indent (set_indent() or change_indent()). So this should be safe.

Add a test that when using a huge value in operator pending mode for
shifting, we will shift by INT_MAX

closes: 

Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-11-16 22:04:38 +01:00
Christian Brabandt
4bca4897a1
patch 9.0.2075: TextChangedI may not always trigger
Problem:  TextChangedI may not always trigger
Solution: trigger it in more cases: for insert/
          append/change operations, and when
          opening a new line,

fixes: 
closes: 

Signed-off-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
2023-10-27 19:26:49 +02:00
Christian Brabandt
ffb13674d1
patch 9.0.1899: potential buffer overflow in PBYTE macro
Problem:  potential buffer overflow in PBYTE macro
Solution: Check returned memline length

closes: 

the PBYTE macro is used to put byte c at a position lp of the returned
memline. However, in case of unexpected errors ml_get_buf() may return
either "???" or an empty line in which case it is quite likely that we
are causing a buffer overrun.

Therefore, switch the macro PBYTE (which is only used in ops.c anyhow)
to a function, that verifies that we will only try to access within the
given length of the buffer.

Also, since the macro is only used in ops.c, move the definition from
macros.h to ops.c

Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-09-15 20:22:02 +02:00
Christian Brabandt
889f6af371
patch 9.0.1847: [security] potential oob write in do_addsub()
Problem:  potential oob write in do_addsub()
Solution: don't overflow buf2, check size in for loop()

Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-09-02 19:43:33 +02:00
zeertzjq
30b6d6104c patch 9.0.1521: failing redo of command with control characters
Problem:    Failing redo of command with control characters.
Solution:   Use AppendToRedobuffLit() for colon commands. (closes )
2023-05-07 17:39:23 +01:00
zeertzjq
3ab3a86481 patch 9.0.1516: cannot use special keys in <Cmd> mapping
Problem:    Cannot use special keys in <Cmd> mapping.
Solution:   Do allow for special keys in <Cmd> and <ScriptCmd> mappings.
            (closes )
2023-05-06 16:22:04 +01:00
Bram Moolenaar
5fb78c3fa5 patch 9.0.1380: CTRL-X on 2**64 subtracts two
Problem:    CTRL-X on 2**64 subtracts two. (James McCoy)
Solution:   Correct computation for large number. (closes )
2023-03-04 20:47:39 +00:00
Yegappan Lakshmanan
af93691b53 patch 9.0.1330: handling new value of an option has a long "else if" chain
Problem:    Handling new value of an option has a long "else if" chain.
Solution:   Use a function pointer. (Yegappan Lakshmanan, closes )
2023-02-20 12:16:39 +00:00
Yegappan Lakshmanan
f2e30d0c44 patch 9.0.1262: the did_set_string_option function is too long
Problem:    The did_set_string_option function is too long.
Solution:   Split off functionality to individual functions.  (Yegappan
            Lakshmanan, Lewis Russell, closes )
2023-01-30 13:04:42 +00:00
Yegappan Lakshmanan
a41e221935 patch 9.0.1208: code is indented more than necessary
Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes )
2023-01-16 18:19:05 +00:00
Bram Moolenaar
24fe33a83a patch 9.0.0934: various code formatting issues
Problem:    Various code formatting issues.
Solution:   Improve code formatting.
2022-11-24 00:09:02 +00:00
zeertzjq
cdeb65729d patch 9.0.0884: mouse shape remains in op-pending mode after failed change
Problem:    Mouse shape remains in op-pending mode after failed change.
Solution:   Reset finish_op and restore it. (closes )
2022-11-15 13:46:12 +00:00
Bram Moolenaar
9954dc39ea patch 9.0.0861: solution for "!!sort" in closed fold is not optimal
Problem:    Solution for "!!sort" in closed fold is not optimal.
Solution:   Use a different range instead of the subtle difference in handling
            a range with an offset. (issue )
2022-11-11 22:58:36 +00:00
Bram Moolenaar
c8b6735573 patch 9.0.0764: indent and option tests fail
Problem:    Indent and option tests fail.
Solution:   Change OP_INDENT.  Add entry to options test table.
2022-10-15 16:41:53 +01:00
Bram Moolenaar
c9121f798f patch 9.0.0751: 'scrolloff' does not work well with 'smoothscroll'
Problem:    'scrolloff' does not work well with 'smoothscroll'.
Solution:   Make positioning the cursor a bit better.  Rename functions.
2022-10-14 20:09:04 +01:00
Bram Moolenaar
bf499c0e6f patch 9.0.0699: tiny build fails
Problem:    Tiny build fails.
Solution:   Add #ifdef.
2022-10-08 17:55:32 +01:00
Bram Moolenaar
16dab41537 patch 9.0.0697: cursor in wrong position with Visual substitute
Problem:    Cursor in wrong position with Visual substitute.
Solution:   When restoring 'linebreak' mark the virtual column as invalid.
            (closes , closes )
2022-10-08 16:41:32 +01:00
Bram Moolenaar
c249913edc patch 9.0.0483: illegal memory access when replacing in virtualedit mode
Problem:    Illegal memory access when replacing in virtualedit mode.
Solution:   Check for replacing NUL after Tab.
2022-09-16 22:16:59 +01:00
Yegappan Lakshmanan
6b085b9d73 patch 9.0.0376: clang warns for dead assignments
Problem:    Clang warns for dead assignments.
Solution:   Adjust the code. (Yegappan Lakshmanan, closes )
2022-09-04 12:47:21 +01:00
Yegappan Lakshmanan
c99e182e1f patch 9.0.0364: clang static analyzer gives warnings
Problem:    Clang static analyzer gives warnings.
Solution:   Avoid the warnings. (Yegappan Lakshmanan, closes )
2022-09-03 10:52:24 +01:00
Bram Moolenaar
a2a8973e51 patch 9.0.0340: the 'cmdheight' zero support causes too much trouble
Problem:    The 'cmdheight' zero support causes too much trouble.
Solution:   Revert support for 'cmdheight' being zero.
2022-08-31 14:46:18 +01:00
Bram Moolenaar
a4d158b3c8 patch 9.0.0206: redraw flags are not named specifically
Problem:    Redraw flags are not named specifically.
Solution:   Prefix "UPD_" to the flags, for UPDate_screen().
2022-08-14 14:17:45 +01:00
Bram Moolenaar
7d0f7e9524 patch 9.0.0154: text properties wrong after splitting a line
Problem:    Text properties wrong after splitting a line.
Solution:   Check for text properties after the line. (closes )
2022-08-06 17:10:57 +01:00
Bram Moolenaar
e175dc6911 patch 9.0.0133: virtual text after line moves to joined line
Problem:    Virtual text after line moves to joined line. (Yegappan
            Lakshmanan)
Solution:   When joining lines only keep virtual text after the last line.
2022-08-01 22:18:50 +01:00
Shougo Matsushita
f39cfb7262 patch 9.0.0114: the command line takes up space even when not used
Problem:    The command line takes up space even when not used.
Solution:   Allow for 'cmdheight' to be set to zero. (Shougo Matsushita,
            closes , closes )
2022-07-30 16:54:05 +01:00
Bram Moolenaar
7f9969c559 patch 9.0.0067: cannot show virtual text
Problem:    Cannot show virtual text.
Solution:   Initial changes for virtual text support, using text properties.
2022-07-25 18:13:54 +01:00
Bram Moolenaar
fa4873ccfc patch 9.0.0013: reproducing memory access errors can be difficult
Problem:    Reproducing memory access errors can be difficult.
Solution:   When testing, copy each line to allocated memory, so that valgrind
            can detect accessing memory before and/or after it.  Fix uncovered
            problems.
2022-06-30 22:13:59 +01:00
Bram Moolenaar
8e145b8246 patch 8.2.4993: smart/C/lisp indenting is optional
Problem:    smart/C/lisp indenting is optional, which makes the code more
            complex, while it only reduces the executable size a bit.
Solution:   Graduate FEAT_CINDENT, FEAT_SMARTINDENT and FEAT_LISP.
2022-05-21 20:17:31 +01:00