summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-10-06 20:08:38 +0200
committerBram Moolenaar <Bram@vim.org>2019-10-06 20:08:38 +0200
commit524f3b19ae16e08350010b5effe38d0637349285 (patch)
treed9c8c147f89b0961474a4b5dcda2321bca36a53d
parenteb66328bd78c3001d71138306325718cb1c94712 (diff)
downloadvim-git-524f3b19ae16e08350010b5effe38d0637349285.tar.gz
patch 8.1.2119: memory access error for empty stringv8.1.2119
Problem: memory access error for empty string when 'encoding' is a single byte encoding. Solution: Check for empty string when getting the length. (Dominique Pelle, closes #5021, closes #5007)
-rw-r--r--src/macros.h6
-rw-r--r--src/version.c2
2 files changed, 5 insertions, 3 deletions
diff --git a/src/macros.h b/src/macros.h
index d685deafb..5e047c873 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -230,11 +230,11 @@
* PTR2CHAR(): get character from pointer.
*/
/* Get the length of the character p points to, including composing chars */
-#define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1)
+#define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : (*p == NUL ? 0 : 1))
/* Advance multi-byte pointer, skip over composing chars. */
-#define MB_PTR_ADV(p) p += has_mbyte ? (*mb_ptr2len)(p) : 1
+#define MB_PTR_ADV(p) p += has_mbyte ? (*mb_ptr2len)(p) : (*p == NUL ? 0 : 1)
/* Advance multi-byte pointer, do not skip over composing chars. */
-#define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1
+#define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : (*p == NUL ? 0 : 1)
/* Backup multi-byte pointer. Only use with "p" > "s" ! */
#define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1
/* get length of multi-byte char, not including composing chars */
diff --git a/src/version.c b/src/version.c
index 0fa8440e3..edbd0a717 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2119,
+/**/
2118,
/**/
2117,