]> granicus.if.org Git - vim/commitdiff
patch 8.1.2119: memory access error for empty string v8.1.2119
authorBram Moolenaar <Bram@vim.org>
Sun, 6 Oct 2019 18:08:38 +0000 (20:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 6 Oct 2019 18:08:38 +0000 (20:08 +0200)
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)

src/macros.h
src/version.c

index d685deafb9ef2a659c9c36d1e2f7af13572c7d4a..5e047c873fea4628418cea0ffa8c82a51b0d6356 100644 (file)
  * 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 */
index 0fa8440e356f4e2f995c5d49480ca859985b814a..edbd0a717dc8b4c0560bb4f4d2878ccce530f57f 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2119,
 /**/
     2118,
 /**/