Permalink
Browse files

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.
  • Loading branch information...
brammool committed Apr 8, 2018
1 parent 4ac2e8d commit ea39176baab52b646d1e2676e662def718ddd365
Showing with 51 additions and 31 deletions.
  1. +1 −1 src/eval.c
  2. +2 −2 src/fileio.c
  3. +1 −1 src/json.c
  4. +2 −2 src/mbyte.c
  5. +23 −14 src/ops.c
  6. +18 −2 src/proto.h
  7. +1 −1 src/spellfile.c
  8. +1 −1 src/undo.c
  9. +2 −0 src/version.c
  10. +0 −7 src/vim.h
@@ -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:
@@ -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);
}
}
@@ -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;
@@ -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
@@ -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);
}
}
@@ -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)
@@ -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);
@@ -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);
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1677,
/**/
1676,
/**/
@@ -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 */

0 comments on commit ea39176

Please sign in to comment.