Mercurial > vim
comparison src/screen.c @ 29457:53d8ef8442d8 v9.0.0070
patch 9.0.0070: using utfc_ptr2char_len() when length is negative
Commit: https://github.com/vim/vim/commit/4dc513a22c017b3061287deac74fa55f70a3214c
Author: zeertzjq <zeertzjq@outlook.com>
Date: Mon Jul 25 19:42:02 2022 +0100
patch 9.0.0070: using utfc_ptr2char_len() when length is negative
Problem: Using utfc_ptr2char_len() when length is negative.
Solution: Check value of length. (closes https://github.com/vim/vim/issues/10760)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 25 Jul 2022 20:45:02 +0200 |
parents | 34e93e046526 |
children | 8a243ecfe2dd |
comparison
equal
deleted
inserted
replaced
29456:7242f365caad | 29457:53d8ef8442d8 |
---|---|
1569 { | 1569 { |
1570 c = *ptr; | 1570 c = *ptr; |
1571 // check if this is the first byte of a multibyte | 1571 // check if this is the first byte of a multibyte |
1572 if (has_mbyte) | 1572 if (has_mbyte) |
1573 { | 1573 { |
1574 if (enc_utf8 && len > 0) | 1574 mbyte_blen = enc_utf8 && len > 0 |
1575 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); | 1575 ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) |
1576 else | 1576 : (*mb_ptr2len)(ptr); |
1577 mbyte_blen = (*mb_ptr2len)(ptr); | |
1578 if (enc_dbcs == DBCS_JPNU && c == 0x8e) | 1577 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
1579 mbyte_cells = 1; | 1578 mbyte_cells = 1; |
1580 else if (enc_dbcs != 0) | 1579 else if (enc_dbcs != 0) |
1581 mbyte_cells = mbyte_blen; | 1580 mbyte_cells = mbyte_blen; |
1582 else // enc_utf8 | 1581 else // enc_utf8 |
1583 { | 1582 { |
1584 if (len >= 0) | 1583 u8c = len >= 0 |
1585 u8c = utfc_ptr2char_len(ptr, u8cc, | 1584 ? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)) |
1586 (int)((text + len) - ptr)); | 1585 : utfc_ptr2char(ptr, u8cc); |
1587 else | |
1588 u8c = utfc_ptr2char(ptr, u8cc); | |
1589 mbyte_cells = utf_char2cells(u8c); | 1586 mbyte_cells = utf_char2cells(u8c); |
1590 #ifdef FEAT_ARABIC | 1587 #ifdef FEAT_ARABIC |
1591 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | 1588 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
1592 { | 1589 { |
1593 // Do Arabic shaping. | 1590 // Do Arabic shaping. |
1597 nc = NUL; | 1594 nc = NUL; |
1598 nc1 = NUL; | 1595 nc1 = NUL; |
1599 } | 1596 } |
1600 else | 1597 else |
1601 { | 1598 { |
1602 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, | 1599 nc = len >= 0 |
1603 (int)((text + len) - ptr - mbyte_blen)); | 1600 ? utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
1601 (int)((text + len) - ptr - mbyte_blen)) | |
1602 : utfc_ptr2char(ptr + mbyte_blen, pcc); | |
1604 nc1 = pcc[0]; | 1603 nc1 = pcc[0]; |
1605 } | 1604 } |
1606 pc = prev_c; | 1605 pc = prev_c; |
1607 prev_c = u8c; | 1606 prev_c = u8c; |
1608 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); | 1607 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |