]> granicus.if.org Git - vim/commitdiff
patch 8.2.1564: a few remaining errors from ubsan v8.2.1564
authorBram Moolenaar <Bram@vim.org>
Wed, 2 Sep 2020 08:25:45 +0000 (10:25 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 2 Sep 2020 08:25:45 +0000 (10:25 +0200)
Problem:    A few remaining errors from ubsan.
Solution:   Avoid the warnings. (Dominique PellĂ©, closes #6837)

src/spellfile.c
src/spellsuggest.c
src/version.c
src/viminfo.c

index d5ec3feaddc2ed7390f62dd2f82e9fd316313263..12dedd6c573a445e8467b7706d54e5350d736e5f 100644 (file)
@@ -816,11 +816,15 @@ read_cnt_string(FILE *fd, int cnt_bytes, int *cntp)
 
     // read the length bytes, MSB first
     for (i = 0; i < cnt_bytes; ++i)
-       cnt = (cnt << 8) + (unsigned)getc(fd);
-    if (cnt < 0)
     {
-       *cntp = SP_TRUNCERROR;
-       return NULL;
+       int c = getc(fd);
+
+       if (c == EOF)
+       {
+           *cntp = SP_TRUNCERROR;
+           return NULL;
+       }
+       cnt = (cnt << 8) + (unsigned)c;
     }
     *cntp = cnt;
     if (cnt == 0)
index 96e7bb634cfc223cfa31b96a122612da4f4a4883..e2423cd98ab6783d85d8aad70946626d88ca0c94 100644 (file)
@@ -3731,9 +3731,6 @@ cleanup_suggestions(
     int                maxscore,
     int                keep)           // nr of suggestions to keep
 {
-    suggest_T   *stp = &SUG(*gap, 0);
-    int                i;
-
     if (gap->ga_len > 0)
     {
        // Sort the list.
@@ -3744,6 +3741,9 @@ cleanup_suggestions(
        // displayed.
        if (gap->ga_len > keep)
        {
+           int         i;
+           suggest_T   *stp = &SUG(*gap, 0);
+
            for (i = keep; i < gap->ga_len; ++i)
                vim_free(stp[i].st_word);
            gap->ga_len = keep;
index d606f1ec92dbd0de46d33bd6c0bbdb6ae7cf00a1..03612aa0678e0d71373e2f8f0c085cbe66a887b3 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1564,
 /**/
     1563,
 /**/
index 74780c3d072a869bf8cd1e55f4fdda3c09937ca7..0ec9a131938aace5827cb1aa21c7d48e5cb615bf 100644 (file)
@@ -2183,7 +2183,8 @@ write_viminfo_filemarks(FILE *fp)
        xfmark_T        *vi_fm;
 
        fm = idx >= 0 ? &curwin->w_jumplist[idx] : NULL;
-       vi_fm = vi_idx < vi_jumplist_len ? &vi_jumplist[vi_idx] : NULL;
+       vi_fm = (vi_jumplist != NULL && vi_idx < vi_jumplist_len)
+                                       ? &vi_jumplist[vi_idx] : NULL;
        if (fm == NULL && vi_fm == NULL)
            break;
        if (fm == NULL || (vi_fm != NULL && fm->time_set < vi_fm->time_set))