Mercurial > vim
changeset 13610:e76499e85744 v8.0.1677
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
commit https://github.com/vim/vim/commit/ea39176baab52b646d1e2676e662def718ddd365
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 8 13:07:22 2018 +0200
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Problem: No compiler warning for wrong format in vim_snprintf().
Solution: Add printf attribute for gcc. Fix reported problems.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 08 Apr 2018 13:15:07 +0200 |
parents | 67cb9088e452 |
children | 60f7b362f2cf |
files | 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 |
diffstat | 10 files changed, 51 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -7105,7 +7105,7 @@ get_tv_string_buf_chk(typval_T *varp, ch { 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:
--- a/src/fileio.c +++ b/src/fileio.c @@ -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); } }
--- a/src/json.c +++ b/src/json.c @@ -217,7 +217,7 @@ json_encode_item(garray_T *gap, typval_T case VAR_NUMBER: vim_snprintf((char *)numbuf, NUMBUFLEN, "%lld", - val->vval.v_number); + (long long)val->vval.v_number); ga_concat(gap, numbuf); break;
--- a/src/mbyte.c +++ b/src/mbyte.c @@ -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
--- 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); } }
--- a/src/proto.h +++ b/src/proto.h @@ -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, # 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)
--- a/src/spellfile.c +++ b/src/spellfile.c @@ -3649,7 +3649,7 @@ spell_read_dic(spellinfo_T *spin, char_u { 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);
--- a/src/undo.c +++ b/src/undo.c @@ -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);
--- a/src/version.c +++ b/src/version.c @@ -763,6 +763,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1677, +/**/ 1676, /**/ 1675,
--- 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 */