Mercurial > vim
comparison src/misc2.c @ 28893:aa44d5842d6c v8.2.4969
patch 8.2.4969: changing text in Visual mode may cause invalid memory access
Commit: https://github.com/vim/vim/commit/7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon May 16 19:40:59 2022 +0100
patch 8.2.4969: changing text in Visual mode may cause invalid memory access
Problem: Changing text in Visual mode may cause invalid memory access.
Solution: Check the Visual position after making a change.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 16 May 2022 20:45:03 +0200 |
parents | d0241e74bfdb |
children | 057c26b5c33a |
comparison
equal
deleted
inserted
replaced
28892:4df932719c00 | 28893:aa44d5842d6c |
---|---|
618 void | 618 void |
619 check_cursor(void) | 619 check_cursor(void) |
620 { | 620 { |
621 check_cursor_lnum(); | 621 check_cursor_lnum(); |
622 check_cursor_col(); | 622 check_cursor_col(); |
623 } | |
624 | |
625 /* | |
626 * Check if VIsual position is valid, correct it if not. | |
627 * Can be called when in Visual mode and a change has been made. | |
628 */ | |
629 void | |
630 check_visual_pos(void) | |
631 { | |
632 if (VIsual.lnum > curbuf->b_ml.ml_line_count) | |
633 { | |
634 VIsual.lnum = curbuf->b_ml.ml_line_count; | |
635 VIsual.col = 0; | |
636 VIsual.coladd = 0; | |
637 } | |
638 else | |
639 { | |
640 int len = (int)STRLEN(ml_get(VIsual.lnum)); | |
641 | |
642 if (VIsual.col > len) | |
643 { | |
644 VIsual.col = len; | |
645 VIsual.coladd = 0; | |
646 } | |
647 } | |
623 } | 648 } |
624 | 649 |
625 #if defined(FEAT_TEXTOBJ) || defined(PROTO) | 650 #if defined(FEAT_TEXTOBJ) || defined(PROTO) |
626 /* | 651 /* |
627 * Make sure curwin->w_cursor is not on the NUL at the end of the line. | 652 * Make sure curwin->w_cursor is not on the NUL at the end of the line. |
2414 else | 2439 else |
2415 vim_strncpy(buf, username, len - 1); | 2440 vim_strncpy(buf, username, len - 1); |
2416 return OK; | 2441 return OK; |
2417 } | 2442 } |
2418 | 2443 |
2419 #if defined(EXITFREE) || defined(PROTOS) | 2444 #if defined(EXITFREE) || defined(PROTO) |
2420 /* | 2445 /* |
2421 * Free the memory allocated by get_user_name() | 2446 * Free the memory allocated by get_user_name() |
2422 */ | 2447 */ |
2423 void | 2448 void |
2424 free_username(void) | 2449 free_username(void) |