]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf() v8.0.1677
authorBram Moolenaar <Bram@vim.org>
Sun, 8 Apr 2018 11:07:22 +0000 (13:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 8 Apr 2018 11:07:22 +0000 (13:07 +0200)
Problem:    No compiler warning for wrong format in vim_snprintf().
Solution:   Add printf attribute for gcc.  Fix reported problems.

src/eval.c
src/fileio.c
src/json.c
src/mbyte.c
src/ops.c
src/proto.h
src/spellfile.c
src/undo.c
src/version.c
src/vim.h

index c965d64f2d479b4e4233508c1ef10701e1ab792c..cfeba2edaa7172270bb9de90a73b6df2277dbff4 100644 (file)
@@ -7105,7 +7105,7 @@ get_tv_string_buf_chk(typval_T *varp, char_u *buf)
     {
        case VAR_NUMBER:
            vim_snprintf((char *)buf, NUMBUFLEN, "%lld",
-                                           (varnumber_T)varp->vval.v_number);
+                                           (long long)varp->vval.v_number);
            return buf;
        case VAR_FUNC:
        case VAR_PARTIAL:
index e2fa3e22b6ad45a5902881d3010afbd9d5a4f708..4f35cb9659e648e271a3e18097e2868cbd3c9d5c 100644 (file)
@@ -5315,7 +5315,7 @@ msg_add_lines(
        *p++ = ' ';
     if (shortmess(SHM_LINES))
        vim_snprintf((char *)p, IOSIZE - (p - IObuff),
-               "%ldL, %lldC", lnum, (varnumber_T)nchars);
+               "%ldL, %lldC", lnum, (long long)nchars);
     else
     {
        if (lnum == 1)
@@ -5327,7 +5327,7 @@ msg_add_lines(
            STRCPY(p, _("1 character"));
        else
            vim_snprintf((char *)p, IOSIZE - (p - IObuff),
-                   _("%lld characters"), (varnumber_T)nchars);
+                   _("%lld characters"), (long long)nchars);
     }
 }
 
index e1f40bf652db868ec1d5b616852a0e6455816412..cc756488d8f6f845f46c52bafd08b7be64117f92 100644 (file)
@@ -217,7 +217,7 @@ json_encode_item(garray_T *gap, typval_T *val, int copyID, int options)
 
        case VAR_NUMBER:
            vim_snprintf((char *)numbuf, NUMBUFLEN, "%lld",
-                                                   val->vval.v_number);
+                                               (long long)val->vval.v_number);
            ga_concat(gap, numbuf);
            break;
 
index cb2d2d93ed3bbf2c200d8505f9b999e93c6b4811..6d21f113e94f295a779dfffada78a84f3694290d 100644 (file)
@@ -5040,11 +5040,11 @@ im_preedit_window_open()
 #else
     gtk_widget_modify_font(preedit_label, gui.norm_font);
 
-    vim_snprintf(buf, sizeof(buf), "#%06X", gui.norm_pixel);
+    vim_snprintf(buf, sizeof(buf), "#%06X", (unsigned)gui.norm_pixel);
     gdk_color_parse(buf, &color);
     gtk_widget_modify_fg(preedit_label, GTK_STATE_NORMAL, &color);
 
-    vim_snprintf(buf, sizeof(buf), "#%06X", gui.back_pixel);
+    vim_snprintf(buf, sizeof(buf), "#%06X", (unsigned)gui.back_pixel);
     gdk_color_parse(buf, &color);
     gtk_widget_modify_bg(preedit_window, GTK_STATE_NORMAL, &color);
 #endif
index cb019cfd0871095c4243c821c42aadedd1272519..8b895d86371ec05ee675a7b756665842c4ccb41e 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -5976,13 +5976,17 @@ do_addsub(
            buf2[i] = '\0';
        }
        else if (pre == 0)
-           vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", n);
+           vim_snprintf((char *)buf2, NUMBUFLEN, "%llu",
+                                                       (long long unsigned)n);
        else if (pre == '0')
-           vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", n);
+           vim_snprintf((char *)buf2, NUMBUFLEN, "%llo",
+                                                       (long long unsigned)n);
        else if (pre && hexupper)
-           vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", n);
+           vim_snprintf((char *)buf2, NUMBUFLEN, "%llX",
+                                                       (long long unsigned)n);
        else
-           vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", n);
+           vim_snprintf((char *)buf2, NUMBUFLEN, "%llx",
+                                                       (long long unsigned)n);
        length -= (int)STRLEN(buf2);
 
        /*
@@ -7501,16 +7505,21 @@ cursor_pos_info(dict_T *dict)
                            _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Bytes"),
                            buf1, line_count_selected,
                            (long)curbuf->b_ml.ml_line_count,
-                           word_count_cursor, word_count,
-                           byte_count_cursor, byte_count);
+                           (long long)word_count_cursor,
+                           (long long)word_count,
+                           (long long)byte_count_cursor,
+                           (long long)byte_count);
                else
                    vim_snprintf((char *)IObuff, IOSIZE,
                            _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Chars; %lld of %lld Bytes"),
                            buf1, line_count_selected,
                            (long)curbuf->b_ml.ml_line_count,
-                           word_count_cursor, word_count,
-                           char_count_cursor, char_count,
-                           byte_count_cursor, byte_count);
+                           (long long)word_count_cursor,
+                           (long long)word_count,
+                           (long long)char_count_cursor,
+                           (long long)char_count,
+                           (long long)byte_count_cursor,
+                           (long long)byte_count);
            }
            else
            {
@@ -7528,17 +7537,17 @@ cursor_pos_info(dict_T *dict)
                        (char *)buf1, (char *)buf2,
                        (long)curwin->w_cursor.lnum,
                        (long)curbuf->b_ml.ml_line_count,
-                       word_count_cursor, word_count,
-                       byte_count_cursor, byte_count);
+                       (long long)word_count_cursor, (long long)word_count,
+                       (long long)byte_count_cursor, (long long)byte_count);
                else
                    vim_snprintf((char *)IObuff, IOSIZE,
                        _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Char %lld of %lld; Byte %lld of %lld"),
                        (char *)buf1, (char *)buf2,
                        (long)curwin->w_cursor.lnum,
                        (long)curbuf->b_ml.ml_line_count,
-                       word_count_cursor, word_count,
-                       char_count_cursor, char_count,
-                       byte_count_cursor, byte_count);
+                       (long long)word_count_cursor, (long long)word_count,
+                       (long long)char_count_cursor, (long long)char_count,
+                       (long long)byte_count_cursor, (long long)byte_count);
            }
        }
 
index 5513746dd9615af2015419a4e125c96e0b8c9afb..231c53f3bf55f2b220fb287daf0f9db11f45d247 100644 (file)
@@ -119,13 +119,21 @@ int
 #  ifdef __BORLANDC__
 _RTLENTRYF
 #  endif
-vim_snprintf_add(char *, size_t, char *, ...);
+vim_snprintf_add(char *, size_t, char *, ...)
+#ifdef __GNUC__
+    __attribute__((format(printf, 3, 4)))
+#endif
+    ;
 
 int
 #  ifdef __BORLANDC__
 _RTLENTRYF
 #  endif
-vim_snprintf(char *, size_t, char *, ...);
+vim_snprintf(char *, size_t, char *, ...)
+#ifdef __GNUC__
+    __attribute__((format(printf, 3, 4)))
+#endif
+    ;
 
 int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap);
 int vim_vsnprintf_typval(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs);
@@ -212,6 +220,14 @@ void qsort(void *base, size_t elm_count, size_t elm_size, int (*cmp)(const void
 # endif
 # ifdef FEAT_JOB_CHANNEL
 #  include "channel.pro"
+
+/* Not generated automatically, to add extra attribute. */
+void ch_log(channel_T *ch, const char *fmt, ...)
+#ifdef __GNUC__
+    __attribute__((format(printf, 2, 3)))
+#endif
+    ;
+
 # endif
 
 # if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL)
index e9eacbecb69898a8fb5e414adc2ac06edd66b466..496e07f8f6912c67a61fd6010210d056f6ff41f7 100644 (file)
@@ -3649,7 +3649,7 @@ spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile)
        {
            spin->si_msg_count = 0;
            vim_snprintf((char *)message, sizeof(message),
-                   _("line %6d, word %6d - %s"),
+                   _("line %6d, word %6ld - %s"),
                       lnum, spin->si_foldwcount + spin->si_keepwcount, w);
            msg_start();
            msg_puts_long_attr(message, 0);
index 09bcc91bef77dae3bd2f040d5b9e0cee51133d4c..6e3381f8cd50c4a9febace6e9214c60300c79a9f 100644 (file)
@@ -3029,7 +3029,7 @@ ex_undolist(exarg_T *eap UNUSED)
        {
            if (ga_grow(&ga, 1) == FAIL)
                break;
-           vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7ld  ",
+           vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7d  ",
                                                        uhp->uh_seq, changes);
            u_add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff),
                                                                uhp->uh_time);
index 4ee3c25769f5e8b08533a614cddbe9fca545ce7d..1b2a1fa0f047cdec17ff38fbae1fc2866e084808 100644 (file)
@@ -762,6 +762,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1677,
 /**/
     1676,
 /**/
index 78dede0cd7f935e646ae562d30e61b65d5e08525..626c0ad12015eb58d9730472584f44dbfe74624f 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2549,11 +2549,4 @@ typedef enum {
 #define TERM_START_FORCEIT     2
 #define TERM_START_SYSTEM      4
 
-/* Not generated automatically, to add extra attribute. */
-void ch_log(channel_T *ch, const char *fmt, ...)
-#ifdef __GNUC__
-__attribute__((format(printf, 2, 3)))
-#endif
-;
-
 #endif /* VIM__H */