To: vim_dev@googlegroups.com Subject: Patch 8.2.2515 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2515 Problem: Memory access error when truncating an empty message. Solution: Check for an empty string. (Dominique Pellé, closes #7841) Files: src/message.c, src/message_test.c *** ../vim-8.2.2514/src/message.c 2021-02-03 15:58:09.084690899 +0100 --- src/message.c 2021-02-14 15:36:04.553806035 +0100 *************** *** 248,253 **** --- 248,260 ---- int i; int n; + if (*s == NUL) + { + if (buflen > 0) + *buf = NUL; + return; + } + if (room_in < 3) room = 0; half = room / 2; *** ../vim-8.2.2514/src/message_test.c 2020-04-20 16:12:06.039159143 +0200 --- src/message_test.c 2021-02-14 15:37:11.045652004 +0100 *************** *** 49,54 **** --- 49,63 ---- char_u *buf; /*allocated every time to find uninit errors */ char_u *s; + // Should not write anything to destination if buflen is 0. + trunc_string((char_u *)"", NULL, 1, 0); + + // Truncating an empty string does nothing. + buf = alloc(1); + trunc_string((char_u *)"", buf, 1, 1); + assert(buf[0] == NUL); + vim_free(buf); + // in place buf = alloc(40); STRCPY(buf, "text"); *** ../vim-8.2.2514/src/version.c 2021-02-14 14:07:31.369787927 +0100 --- src/version.c 2021-02-14 15:36:23.697761682 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2515, /**/ -- BLACK KNIGHT: Come on you pansy! [hah] [parry thrust] [ARTHUR chops the BLACK KNIGHT's right arm off] ARTHUR: Victory is mine! [kneeling] We thank thee Lord, that in thy merc- [Black Knight kicks Arthur in the head while he is praying] The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///