aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/spell.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/spell.c')
-rw-r--r--src/nvim/spell.c264
1 files changed, 121 insertions, 143 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 4759b4efa6..b8713909b8 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -287,6 +287,7 @@
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
+#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
@@ -6594,25 +6595,13 @@ static int rep_compare(const void *s1, const void *s2)
}
// Write the Vim .spl file "fname".
-// Return FAIL or OK;
+// Return OK/FAIL.
static int write_vim_spell(spellinfo_T *spin, char_u *fname)
{
- FILE *fd;
- int regionmask;
- int round;
- wordnode_T *tree;
- int nodecount;
- int i;
- int l;
- garray_T *gap;
- fromto_T *ftp;
- char_u *p;
- int rr;
int retval = OK;
- size_t fwv = 1; // collect return value of fwrite() to avoid
- // warnings from picky compiler
+ int regionmask;
- fd = mch_fopen((char *)fname, "w");
+ FILE *fd = mch_fopen((char *)fname, "w");
if (fd == NULL) {
EMSG2(_(e_notopen), fname);
return FAIL;
@@ -6620,7 +6609,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// <HEADER>: <fileID> <versionnr>
// <fileID>
- fwv &= fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd);
+ size_t fwv = fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, 1, fd);
if (fwv != (size_t)1)
// Catch first write error, don't try writing more.
goto theend;
@@ -6633,10 +6622,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
if (spin->si_info != NULL) {
putc(SN_INFO, fd); // <sectionID>
putc(0, fd); // <sectionflags>
-
- i = (int)STRLEN(spin->si_info);
- put_bytes(fd, (long_u)i, 4); // <sectionlen>
- fwv &= fwrite(spin->si_info, (size_t)i, (size_t)1, fd); // <infotext>
+ size_t i = STRLEN(spin->si_info);
+ put_bytes(fd, i, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_info, i, 1, fd); // <infotext>
}
// SN_REGION: <regionname> ...
@@ -6644,9 +6632,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
if (spin->si_region_count > 1) {
putc(SN_REGION, fd); // <sectionID>
putc(SNF_REQUIRED, fd); // <sectionflags>
- l = spin->si_region_count * 2;
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
- fwv &= fwrite(spin->si_region_name, (size_t)l, (size_t)1, fd);
+ size_t l = (size_t)spin->si_region_count * 2;
+ put_bytes(fd, l, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_region_name, l, 1, fd);
// <regionname> ...
regionmask = (1 << spin->si_region_count) - 1;
} else
@@ -6669,17 +6657,17 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SNF_REQUIRED, fd); // <sectionflags>
// Form the <folchars> string first, we need to know its length.
- l = 0;
- for (i = 128; i < 256; ++i) {
+ size_t l = 0;
+ for (size_t i = 128; i < 256; ++i) {
if (has_mbyte)
- l += mb_char2bytes(spelltab.st_fold[i], folchars + l);
+ l += (size_t)mb_char2bytes(spelltab.st_fold[i], folchars + l);
else
folchars[l++] = spelltab.st_fold[i];
}
- put_bytes(fd, (long_u)(1 + 128 + 2 + l), 4); // <sectionlen>
+ put_bytes(fd, 1 + 128 + 2 + l, 4); // <sectionlen>
fputc(128, fd); // <charflagslen>
- for (i = 128; i < 256; ++i) {
+ for (size_t i = 128; i < 256; ++i) {
flags = 0;
if (spelltab.st_isw[i])
flags |= CF_WORD;
@@ -6688,8 +6676,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
fputc(flags, fd); // <charflags>
}
- put_bytes(fd, (long_u)l, 2); // <folcharslen>
- fwv &= fwrite(folchars, (size_t)l, (size_t)1, fd); // <folchars>
+ put_bytes(fd, l, 2); // <folcharslen>
+ fwv &= fwrite(folchars, l, 1, fd); // <folchars>
}
// SN_MIDWORD: <midword>
@@ -6697,9 +6685,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_MIDWORD, fd); // <sectionID>
putc(SNF_REQUIRED, fd); // <sectionflags>
- i = (int)STRLEN(spin->si_midword);
- put_bytes(fd, (long_u)i, 4); // <sectionlen>
- fwv &= fwrite(spin->si_midword, (size_t)i, (size_t)1, fd);
+ size_t i = STRLEN(spin->si_midword);
+ put_bytes(fd, i, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_midword, i, 1, fd);
// <midword>
}
@@ -6708,8 +6696,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_PREFCOND, fd); // <sectionID>
putc(SNF_REQUIRED, fd); // <sectionflags>
- l = write_spell_prefcond(NULL, &spin->si_prefcond);
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
+ size_t l = (size_t)write_spell_prefcond(NULL, &spin->si_prefcond);
+ put_bytes(fd, l, 4); // <sectionlen>
write_spell_prefcond(fd, &spin->si_prefcond);
}
@@ -6721,7 +6709,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// round 1: SN_REP section
// round 2: SN_SAL section (unless SN_SOFO is used)
// round 3: SN_REPSAL section
- for (round = 1; round <= 3; ++round) {
+ for (unsigned int round = 1; round <= 3; ++round) {
+ garray_T *gap;
if (round == 1)
gap = &spin->si_rep;
else if (round == 2) {
@@ -6741,45 +6730,47 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
qsort(gap->ga_data, (size_t)gap->ga_len,
sizeof(fromto_T), rep_compare);
- i = round == 1 ? SN_REP : (round == 2 ? SN_SAL : SN_REPSAL);
+ int i = round == 1 ? SN_REP : (round == 2 ? SN_SAL : SN_REPSAL);
putc(i, fd); // <sectionID>
// This is for making suggestions, section is not required.
putc(0, fd); // <sectionflags>
// Compute the length of what follows.
- l = 2; // count <repcount> or <salcount>
- for (int i = 0; i < gap->ga_len; ++i) {
- ftp = &((fromto_T *)gap->ga_data)[i];
- l += 1 + (int)STRLEN(ftp->ft_from); // count <*fromlen> and <*from>
- l += 1 + (int)STRLEN(ftp->ft_to); // count <*tolen> and <*to>
+ size_t l = 2; // count <repcount> or <salcount>
+ assert(gap->ga_len >= 0);
+ for (size_t i = 0; i < (size_t)gap->ga_len; ++i) {
+ fromto_T *ftp = &((fromto_T *)gap->ga_data)[i];
+ l += 1 + STRLEN(ftp->ft_from); // count <*fromlen> and <*from>
+ l += 1 + STRLEN(ftp->ft_to); // count <*tolen> and <*to>
}
if (round == 2)
- ++l; // count <salflags>
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
+ ++l; // count <salflags>
+ put_bytes(fd, l, 4); // <sectionlen>
if (round == 2) {
- i = 0;
+ int i = 0;
if (spin->si_followup)
i |= SAL_F0LLOWUP;
if (spin->si_collapse)
i |= SAL_COLLAPSE;
if (spin->si_rem_accents)
i |= SAL_REM_ACCENTS;
- putc(i, fd); // <salflags>
+ putc(i, fd); // <salflags>
}
- put_bytes(fd, (long_u)gap->ga_len, 2); // <repcount> or <salcount>
- for (int i = 0; i < gap->ga_len; ++i) {
+ put_bytes(fd, (uintmax_t)gap->ga_len, 2); // <repcount> or <salcount>
+ for (size_t i = 0; i < (size_t)gap->ga_len; ++i) {
// <rep> : <repfromlen> <repfrom> <reptolen> <repto>
// <sal> : <salfromlen> <salfrom> <saltolen> <salto>
- ftp = &((fromto_T *)gap->ga_data)[i];
- for (rr = 1; rr <= 2; ++rr) {
- p = rr == 1 ? ftp->ft_from : ftp->ft_to;
- l = (int)STRLEN(p);
- putc(l, fd);
+ fromto_T *ftp = &((fromto_T *)gap->ga_data)[i];
+ for (unsigned int rr = 1; rr <= 2; ++rr) {
+ char_u *p = rr == 1 ? ftp->ft_from : ftp->ft_to;
+ l = STRLEN(p);
+ assert(l < INT_MAX);
+ putc((int)l, fd);
if (l > 0)
- fwv &= fwrite(p, l, (size_t)1, fd);
+ fwv &= fwrite(p, l, 1, fd);
}
}
@@ -6791,16 +6782,15 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_SOFO, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- l = (int)STRLEN(spin->si_sofofr);
- put_bytes(fd, (long_u)(l + STRLEN(spin->si_sofoto) + 4), 4);
- // <sectionlen>
+ size_t l = STRLEN(spin->si_sofofr);
+ put_bytes(fd, l + STRLEN(spin->si_sofoto) + 4, 4); // <sectionlen>
- put_bytes(fd, (long_u)l, 2); // <sofofromlen>
- fwv &= fwrite(spin->si_sofofr, l, (size_t)1, fd); // <sofofrom>
+ put_bytes(fd, l, 2); // <sofofromlen>
+ fwv &= fwrite(spin->si_sofofr, l, 1, fd); // <sofofrom>
- l = (int)STRLEN(spin->si_sofoto);
- put_bytes(fd, (long_u)l, 2); // <sofotolen>
- fwv &= fwrite(spin->si_sofoto, l, (size_t)1, fd); // <sofoto>
+ l = STRLEN(spin->si_sofoto);
+ put_bytes(fd, l, 2); // <sofotolen>
+ fwv &= fwrite(spin->si_sofoto, l, 1, fd); // <sofoto>
}
// SN_WORDS: <word> ...
@@ -6811,22 +6801,22 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// round 1: count the bytes
// round 2: write the bytes
- for (round = 1; round <= 2; ++round) {
- int todo;
- int len = 0;
+ for (unsigned int round = 1; round <= 2; ++round) {
+ size_t todo;
+ size_t len = 0;
hashitem_T *hi;
- todo = (int)spin->si_commonwords.ht_used;
+ todo = spin->si_commonwords.ht_used;
for (hi = spin->si_commonwords.ht_array; todo > 0; ++hi)
if (!HASHITEM_EMPTY(hi)) {
- l = (int)STRLEN(hi->hi_key) + 1;
+ size_t l = STRLEN(hi->hi_key) + 1;
len += l;
if (round == 2) // <word>
- fwv &= fwrite(hi->hi_key, (size_t)l, (size_t)1, fd);
+ fwv &= fwrite(hi->hi_key, l, 1, fd);
--todo;
}
if (round == 1)
- put_bytes(fd, (long_u)len, 4); // <sectionlen>
+ put_bytes(fd, len, 4); // <sectionlen>
}
}
@@ -6835,10 +6825,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
if (!GA_EMPTY(&spin->si_map)) {
putc(SN_MAP, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- l = spin->si_map.ga_len;
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
- fwv &= fwrite(spin->si_map.ga_data, (size_t)l, (size_t)1, fd);
- // <mapstr>
+ size_t l = (size_t)spin->si_map.ga_len;
+ put_bytes(fd, l, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_map.ga_data, l, 1, fd); // <mapstr>
}
// SN_SUGFILE: <timestamp>
@@ -6851,7 +6840,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
|| (spin->si_sofofr != NULL && spin->si_sofoto != NULL))) {
putc(SN_SUGFILE, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- put_bytes(fd, (long_u)8, 4); // <sectionlen>
+ put_bytes(fd, 8, 4); // <sectionlen>
// Set si_sugtime and write it to the file.
spin->si_sugtime = time(NULL);
@@ -6864,7 +6853,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
if (spin->si_nosplitsugs) {
putc(SN_NOSPLITSUGS, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- put_bytes(fd, (long_u)0, 4); // <sectionlen>
+ put_bytes(fd, 0, 4); // <sectionlen>
}
// SN_COMPOUND: compound info.
@@ -6874,28 +6863,27 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_COMPOUND, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- l = (int)STRLEN(spin->si_compflags);
- for (int i = 0; i < spin->si_comppat.ga_len; ++i) {
- l += (int)STRLEN(((char_u **)(spin->si_comppat.ga_data))[i]) + 1;
+ size_t l = STRLEN(spin->si_compflags);
+ assert(spin->si_comppat.ga_len >= 0);
+ for (size_t i = 0; i < (size_t)spin->si_comppat.ga_len; ++i) {
+ l += STRLEN(((char_u **)(spin->si_comppat.ga_data))[i]) + 1;
}
- put_bytes(fd, (long_u)(l + 7), 4); // <sectionlen>
+ put_bytes(fd, l + 7, 4); // <sectionlen>
putc(spin->si_compmax, fd); // <compmax>
putc(spin->si_compminlen, fd); // <compminlen>
putc(spin->si_compsylmax, fd); // <compsylmax>
putc(0, fd); // for Vim 7.0b compatibility
putc(spin->si_compoptions, fd); // <compoptions>
- put_bytes(fd, (long_u)spin->si_comppat.ga_len, 2);
- // <comppatcount>
- for (int i = 0; i < spin->si_comppat.ga_len; ++i) {
- p = ((char_u **)(spin->si_comppat.ga_data))[i];
+ put_bytes(fd, (uintmax_t)spin->si_comppat.ga_len, 2); // <comppatcount>
+ for (size_t i = 0; i < (size_t)spin->si_comppat.ga_len; ++i) {
+ char_u *p = ((char_u **)(spin->si_comppat.ga_data))[i];
+ assert(STRLEN(p) < INT_MAX);
putc((int)STRLEN(p), fd); // <comppatlen>
- fwv &= fwrite(p, (size_t)STRLEN(p), (size_t)1, fd);
- // <comppattext>
+ fwv &= fwrite(p, STRLEN(p), 1, fd); // <comppattext>
}
// <compflags>
- fwv &= fwrite(spin->si_compflags, (size_t)STRLEN(spin->si_compflags),
- (size_t)1, fd);
+ fwv &= fwrite(spin->si_compflags, STRLEN(spin->si_compflags), 1, fd);
}
// SN_NOBREAK: NOBREAK flag
@@ -6904,7 +6892,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(0, fd); // <sectionflags>
// It's empty, the presence of the section flags the feature.
- put_bytes(fd, (long_u)0, 4); // <sectionlen>
+ put_bytes(fd, 0, 4); // <sectionlen>
}
// SN_SYLLABLE: syllable info.
@@ -6914,10 +6902,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_SYLLABLE, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- l = (int)STRLEN(spin->si_syllable);
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
- fwv &= fwrite(spin->si_syllable, (size_t)l, (size_t)1, fd);
- // <syllable>
+ size_t l = STRLEN(spin->si_syllable);
+ put_bytes(fd, l, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_syllable, l, 1, fd); // <syllable>
}
// end of <SECTIONS>
@@ -6926,7 +6913,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// <LWORDTREE> <KWORDTREE> <PREFIXTREE>
spin->si_memtot = 0;
- for (round = 1; round <= 3; ++round) {
+ for (unsigned int round = 1; round <= 3; ++round) {
+ wordnode_T *tree;
if (round == 1)
tree = spin->si_foldroot->wn_sibling;
else if (round == 2)
@@ -6940,11 +6928,12 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// Count the number of nodes. Needed to be able to allocate the
// memory when reading the nodes. Also fills in index for shared
// nodes.
- nodecount = put_node(NULL, tree, 0, regionmask, round == 3);
+ size_t nodecount = (size_t)put_node(NULL, tree, 0, regionmask, round == 3);
// number of nodes in 4 bytes
- put_bytes(fd, (long_u)nodecount, 4); // <nodecount>
- spin->si_memtot += nodecount + nodecount * sizeof(int);
+ put_bytes(fd, nodecount, 4); // <nodecount>
+ assert(nodecount + nodecount * sizeof(int) < INT_MAX);
+ spin->si_memtot += (int)(nodecount + nodecount * sizeof(int));
// Write the nodes.
(void)put_node(fd, tree, 0, regionmask, round == 3);
@@ -7002,11 +6991,6 @@ put_node (
bool prefixtree // true for PREFIXTREE
)
{
- int newindex = idx;
- int siblingcount = 0;
- wordnode_T *np;
- int flags;
-
// If "node" is zero the tree is empty.
if (node == NULL)
return 0;
@@ -7015,7 +6999,8 @@ put_node (
node->wn_u1.index = idx;
// Count the number of siblings.
- for (np = node; np != NULL; np = np->wn_sibling)
+ int siblingcount = 0;
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling)
++siblingcount;
// Write the sibling count.
@@ -7023,7 +7008,7 @@ put_node (
putc(siblingcount, fd); // <siblingcount>
// Write each sibling byte and optionally extra info.
- for (np = node; np != NULL; np = np->wn_sibling) {
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) {
if (np->wn_byte == 0) {
if (fd != NULL) {
// For a NUL byte (end of word) write the flags etc.
@@ -7039,10 +7024,10 @@ put_node (
putc(np->wn_flags, fd); // <pflags>
}
putc(np->wn_affixID, fd); // <affixID>
- put_bytes(fd, (long_u)np->wn_region, 2); // <prefcondnr>
+ put_bytes(fd, (uintmax_t)np->wn_region, 2); // <prefcondnr>
} else {
// For word trees we write the flag/region items.
- flags = np->wn_flags;
+ int flags = np->wn_flags;
if (regionmask != 0 && np->wn_region != regionmask)
flags |= WF_REGION;
if (np->wn_affixID != 0)
@@ -7054,7 +7039,7 @@ put_node (
if (np->wn_flags >= 0x100) {
putc(BY_FLAGS2, fd); // <byte>
putc(flags, fd); // <flags>
- putc((unsigned)flags >> 8, fd); // <flags2>
+ putc((int)((unsigned)flags >> 8), fd); // <flags2>
} else {
putc(BY_FLAGS, fd); // <byte>
putc(flags, fd); // <flags>
@@ -7071,9 +7056,8 @@ put_node (
&& np->wn_child->wn_u2.wnode != node) {
// The child is written elsewhere, write the reference.
if (fd != NULL) {
- putc(BY_INDEX, fd); // <byte>
- // <nodeidx>
- put_bytes(fd, (long_u)np->wn_child->wn_u1.index, 3);
+ putc(BY_INDEX, fd); // <byte>
+ put_bytes(fd, (uintmax_t)np->wn_child->wn_u1.index, 3); // <nodeidx>
}
} else if (np->wn_child->wn_u2.wnode == NULL)
// We will write the child below and give it an index.
@@ -7089,10 +7073,10 @@ put_node (
// Space used in the array when reading: one for each sibling and one for
// the count.
- newindex += siblingcount + 1;
+ int newindex = idx + siblingcount + 1;
// Recursively dump the children of each sibling.
- for (np = node; np != NULL; np = np->wn_sibling)
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling)
if (np->wn_byte != 0 && np->wn_child->wn_u2.wnode == node)
newindex = put_node(fd, np->wn_child, newindex, regionmask,
prefixtree);
@@ -7440,16 +7424,8 @@ static int bytes2offset(char_u **pp)
// Write the .sug file in "fname".
static void sug_write(spellinfo_T *spin, char_u *fname)
{
- FILE *fd;
- wordnode_T *tree;
- int nodecount;
- int wcount;
- char_u *line;
- linenr_T lnum;
- int len;
-
// Create the file. Note that an existing file is silently overwritten!
- fd = mch_fopen((char *)fname, "w");
+ FILE *fd = mch_fopen((char *)fname, "w");
if (fd == NULL) {
EMSG2(_(e_notopen), fname);
return;
@@ -7471,7 +7447,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname)
// <SUGWORDTREE>
spin->si_memtot = 0;
- tree = spin->si_foldroot->wn_sibling;
+ wordnode_T *tree = spin->si_foldroot->wn_sibling;
// Clear the index and wnode fields in the tree.
clear_node(tree);
@@ -7479,28 +7455,31 @@ static void sug_write(spellinfo_T *spin, char_u *fname)
// Count the number of nodes. Needed to be able to allocate the
// memory when reading the nodes. Also fills in index for shared
// nodes.
- nodecount = put_node(NULL, tree, 0, 0, false);
+ size_t nodecount = (size_t)put_node(NULL, tree, 0, 0, false);
// number of nodes in 4 bytes
- put_bytes(fd, (long_u)nodecount, 4); // <nodecount>
- spin->si_memtot += nodecount + nodecount * sizeof(int);
+ put_bytes(fd, nodecount, 4); // <nodecount>
+ assert(nodecount + nodecount * sizeof(int) < INT_MAX);
+ spin->si_memtot += (int)(nodecount + nodecount * sizeof(int));
// Write the nodes.
(void)put_node(fd, tree, 0, 0, false);
// <SUGTABLE>: <sugwcount> <sugline> ...
- wcount = spin->si_spellbuf->b_ml.ml_line_count;
- put_bytes(fd, (long_u)wcount, 4); // <sugwcount>
+ linenr_T wcount = spin->si_spellbuf->b_ml.ml_line_count;
+ assert(wcount >= 0);
+ put_bytes(fd, (uintmax_t)wcount, 4); // <sugwcount>
- for (lnum = 1; lnum <= (linenr_T)wcount; ++lnum) {
+ for (linenr_T lnum = 1; lnum <= wcount; ++lnum) {
// <sugline>: <sugnr> ... NUL
- line = ml_get_buf(spin->si_spellbuf, lnum, FALSE);
- len = (int)STRLEN(line) + 1;
- if (fwrite(line, (size_t)len, (size_t)1, fd) == 0) {
+ char_u *line = ml_get_buf(spin->si_spellbuf, lnum, FALSE);
+ size_t len = STRLEN(line) + 1;
+ if (fwrite(line, len, 1, fd) == 0) {
EMSG(_(e_write));
goto theend;
}
- spin->si_memtot += len;
+ assert((size_t)spin->si_memtot + len <= INT_MAX);
+ spin->si_memtot += (int)len;
}
// Write another byte to check for errors.
@@ -8286,31 +8265,30 @@ static bool spell_iswordp_w(int *p, win_T *wp)
// When "fd" is NULL only count the length of what is written.
static int write_spell_prefcond(FILE *fd, garray_T *gap)
{
- char_u *p;
- int len;
- int totlen;
- size_t x = 1; // collect return value of fwrite()
+ assert(gap->ga_len >= 0);
if (fd != NULL)
- put_bytes(fd, (long_u)gap->ga_len, 2); // <prefcondcnt>
-
- totlen = 2 + gap->ga_len; // length of <prefcondcnt> and <condlen> bytes
+ put_bytes(fd, (uintmax_t)gap->ga_len, 2); // <prefcondcnt>
+ size_t totlen = 2 + (size_t)gap->ga_len; // <prefcondcnt> and <condlen> bytes
+ size_t x = 1; // collect return value of fwrite()
for (int i = 0; i < gap->ga_len; ++i) {
// <prefcond> : <condlen> <condstr>
- p = ((char_u **)gap->ga_data)[i];
+ char_u *p = ((char_u **)gap->ga_data)[i];
if (p != NULL) {
- len = (int)STRLEN(p);
+ size_t len = STRLEN(p);
if (fd != NULL) {
- fputc(len, fd);
- x &= fwrite(p, (size_t)len, (size_t)1, fd);
+ assert(len <= INT_MAX);
+ fputc((int)len, fd);
+ x &= fwrite(p, len, 1, fd);
}
totlen += len;
} else if (fd != NULL)
fputc(0, fd);
}
- return totlen;
+ assert(totlen <= INT_MAX);
+ return (int)totlen;
}
// Case-fold "str[len]" into "buf[buflen]". The result is NUL terminated.