diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-02-14 15:37:30 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-02-14 15:37:30 +0100 |
commit | 6281815eccc3ded54960f7798833ceb39561b9a0 (patch) | |
tree | 72c092d24c42b3e01f2dc184ba05c71e61bddf3a /src/message_test.c | |
parent | 2379f87eb48a4ee6a1d0fc7df964e12a3efe4fd5 (diff) | |
download | vim-git-6281815eccc3ded54960f7798833ceb39561b9a0.tar.gz |
patch 8.2.2515: memory access error when truncating an empty messagev8.2.2515
Problem: Memory access error when truncating an empty message.
Solution: Check for an empty string. (Dominique Pellé, closes #7841)
Diffstat (limited to 'src/message_test.c')
-rw-r--r-- | src/message_test.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/message_test.c b/src/message_test.c index 85a29b471..88335de26 100644 --- a/src/message_test.c +++ b/src/message_test.c @@ -49,6 +49,15 @@ test_trunc_string(void) 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"); |