From d23a5da890f106bf45898801000904d06c5a045a Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 10 Dec 2021 23:11:48 +0100 Subject: vim-patch:8.2.3777: spell file write error not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Spell file write error not checked. Solution: Check writing the prefix conditions. (Björn Linse, closes vim/vim#9323) --- src/nvim/spellfile.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index c65fcc1180..3840b0db86 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -4447,10 +4447,10 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) putc(SN_PREFCOND, fd); // putc(SNF_REQUIRED, fd); // - size_t l = (size_t)write_spell_prefcond(NULL, &spin->si_prefcond); + size_t l = (size_t)write_spell_prefcond(NULL, &spin->si_prefcond, &fwv); put_bytes(fd, l, 4); // - write_spell_prefcond(fd, &spin->si_prefcond); + write_spell_prefcond(fd, &spin->si_prefcond, &fwv); } // SN_REP: ... @@ -5794,7 +5794,7 @@ static int set_spell_finish(spelltab_T *new_st) // Write the table with prefix conditions to the .spl file. // When "fd" is NULL only count the length of what is written. -static int write_spell_prefcond(FILE *fd, garray_T *gap) +static int write_spell_prefcond(FILE *fd, garray_T *gap, size_t *fwv) { assert(gap->ga_len >= 0); @@ -5802,8 +5802,7 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap) put_bytes(fd, (uintmax_t)gap->ga_len, 2); // } size_t totlen = 2 + (size_t)gap->ga_len; // and bytes - size_t x = 1; // collect return value of fwrite() - for (int i = 0; i < gap->ga_len; ++i) { + for (int i = 0; i < gap->ga_len; i++) { // : char_u *p = ((char_u **)gap->ga_data)[i]; if (p != NULL) { @@ -5811,7 +5810,7 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap) if (fd != NULL) { assert(len <= INT_MAX); fputc((int)len, fd); - x &= fwrite(p, len, 1, fd); + *fwv &= fwrite(p, len, 1, fd); } totlen += len; } else if (fd != NULL) { -- cgit