Skip to content

Commit ea39176

Browse files
committed
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.
1 parent 4ac2e8d commit ea39176

File tree

10 files changed

+51
-31
lines changed

10 files changed

+51
-31
lines changed

src/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7105,7 +7105,7 @@ get_tv_string_buf_chk(typval_T *varp, char_u *buf)
71057105
{
71067106
case VAR_NUMBER:
71077107
vim_snprintf((char *)buf, NUMBUFLEN, "%lld",
7108-
(varnumber_T)varp->vval.v_number);
7108+
(long long)varp->vval.v_number);
71097109
return buf;
71107110
case VAR_FUNC:
71117111
case VAR_PARTIAL:

src/fileio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5315,7 +5315,7 @@ msg_add_lines(
53155315
*p++ = ' ';
53165316
if (shortmess(SHM_LINES))
53175317
vim_snprintf((char *)p, IOSIZE - (p - IObuff),
5318-
"%ldL, %lldC", lnum, (varnumber_T)nchars);
5318+
"%ldL, %lldC", lnum, (long long)nchars);
53195319
else
53205320
{
53215321
if (lnum == 1)
@@ -5327,7 +5327,7 @@ msg_add_lines(
53275327
STRCPY(p, _("1 character"));
53285328
else
53295329
vim_snprintf((char *)p, IOSIZE - (p - IObuff),
5330-
_("%lld characters"), (varnumber_T)nchars);
5330+
_("%lld characters"), (long long)nchars);
53315331
}
53325332
}
53335333

src/json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ json_encode_item(garray_T *gap, typval_T *val, int copyID, int options)
217217

218218
case VAR_NUMBER:
219219
vim_snprintf((char *)numbuf, NUMBUFLEN, "%lld",
220-
val->vval.v_number);
220+
(long long)val->vval.v_number);
221221
ga_concat(gap, numbuf);
222222
break;
223223

src/mbyte.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5040,11 +5040,11 @@ im_preedit_window_open()
50405040
#else
50415041
gtk_widget_modify_font(preedit_label, gui.norm_font);
50425042

5043-
vim_snprintf(buf, sizeof(buf), "#%06X", gui.norm_pixel);
5043+
vim_snprintf(buf, sizeof(buf), "#%06X", (unsigned)gui.norm_pixel);
50445044
gdk_color_parse(buf, &color);
50455045
gtk_widget_modify_fg(preedit_label, GTK_STATE_NORMAL, &color);
50465046

5047-
vim_snprintf(buf, sizeof(buf), "#%06X", gui.back_pixel);
5047+
vim_snprintf(buf, sizeof(buf), "#%06X", (unsigned)gui.back_pixel);
50485048
gdk_color_parse(buf, &color);
50495049
gtk_widget_modify_bg(preedit_window, GTK_STATE_NORMAL, &color);
50505050
#endif

src/ops.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5976,13 +5976,17 @@ do_addsub(
59765976
buf2[i] = '\0';
59775977
}
59785978
else if (pre == 0)
5979-
vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", n);
5979+
vim_snprintf((char *)buf2, NUMBUFLEN, "%llu",
5980+
(long long unsigned)n);
59805981
else if (pre == '0')
5981-
vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", n);
5982+
vim_snprintf((char *)buf2, NUMBUFLEN, "%llo",
5983+
(long long unsigned)n);
59825984
else if (pre && hexupper)
5983-
vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", n);
5985+
vim_snprintf((char *)buf2, NUMBUFLEN, "%llX",
5986+
(long long unsigned)n);
59845987
else
5985-
vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", n);
5988+
vim_snprintf((char *)buf2, NUMBUFLEN, "%llx",
5989+
(long long unsigned)n);
59865990
length -= (int)STRLEN(buf2);
59875991

59885992
/*
@@ -7501,16 +7505,21 @@ cursor_pos_info(dict_T *dict)
75017505
_("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Bytes"),
75027506
buf1, line_count_selected,
75037507
(long)curbuf->b_ml.ml_line_count,
7504-
word_count_cursor, word_count,
7505-
byte_count_cursor, byte_count);
7508+
(long long)word_count_cursor,
7509+
(long long)word_count,
7510+
(long long)byte_count_cursor,
7511+
(long long)byte_count);
75067512
else
75077513
vim_snprintf((char *)IObuff, IOSIZE,
75087514
_("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Chars; %lld of %lld Bytes"),
75097515
buf1, line_count_selected,
75107516
(long)curbuf->b_ml.ml_line_count,
7511-
word_count_cursor, word_count,
7512-
char_count_cursor, char_count,
7513-
byte_count_cursor, byte_count);
7517+
(long long)word_count_cursor,
7518+
(long long)word_count,
7519+
(long long)char_count_cursor,
7520+
(long long)char_count,
7521+
(long long)byte_count_cursor,
7522+
(long long)byte_count);
75147523
}
75157524
else
75167525
{
@@ -7528,17 +7537,17 @@ cursor_pos_info(dict_T *dict)
75287537
(char *)buf1, (char *)buf2,
75297538
(long)curwin->w_cursor.lnum,
75307539
(long)curbuf->b_ml.ml_line_count,
7531-
word_count_cursor, word_count,
7532-
byte_count_cursor, byte_count);
7540+
(long long)word_count_cursor, (long long)word_count,
7541+
(long long)byte_count_cursor, (long long)byte_count);
75337542
else
75347543
vim_snprintf((char *)IObuff, IOSIZE,
75357544
_("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Char %lld of %lld; Byte %lld of %lld"),
75367545
(char *)buf1, (char *)buf2,
75377546
(long)curwin->w_cursor.lnum,
75387547
(long)curbuf->b_ml.ml_line_count,
7539-
word_count_cursor, word_count,
7540-
char_count_cursor, char_count,
7541-
byte_count_cursor, byte_count);
7548+
(long long)word_count_cursor, (long long)word_count,
7549+
(long long)char_count_cursor, (long long)char_count,
7550+
(long long)byte_count_cursor, (long long)byte_count);
75427551
}
75437552
}
75447553

src/proto.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,21 @@ int
119119
# ifdef __BORLANDC__
120120
_RTLENTRYF
121121
# endif
122-
vim_snprintf_add(char *, size_t, char *, ...);
122+
vim_snprintf_add(char *, size_t, char *, ...)
123+
#ifdef __GNUC__
124+
__attribute__((format(printf, 3, 4)))
125+
#endif
126+
;
123127

124128
int
125129
# ifdef __BORLANDC__
126130
_RTLENTRYF
127131
# endif
128-
vim_snprintf(char *, size_t, char *, ...);
132+
vim_snprintf(char *, size_t, char *, ...)
133+
#ifdef __GNUC__
134+
__attribute__((format(printf, 3, 4)))
135+
#endif
136+
;
129137

130138
int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap);
131139
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
212220
# endif
213221
# ifdef FEAT_JOB_CHANNEL
214222
# include "channel.pro"
223+
224+
/* Not generated automatically, to add extra attribute. */
225+
void ch_log(channel_T *ch, const char *fmt, ...)
226+
#ifdef __GNUC__
227+
__attribute__((format(printf, 2, 3)))
228+
#endif
229+
;
230+
215231
# endif
216232

217233
# if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL)

src/spellfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3649,7 +3649,7 @@ spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile)
36493649
{
36503650
spin->si_msg_count = 0;
36513651
vim_snprintf((char *)message, sizeof(message),
3652-
_("line %6d, word %6d - %s"),
3652+
_("line %6d, word %6ld - %s"),
36533653
lnum, spin->si_foldwcount + spin->si_keepwcount, w);
36543654
msg_start();
36553655
msg_puts_long_attr(message, 0);

src/undo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3029,7 +3029,7 @@ ex_undolist(exarg_T *eap UNUSED)
30293029
{
30303030
if (ga_grow(&ga, 1) == FAIL)
30313031
break;
3032-
vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7ld ",
3032+
vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7d ",
30333033
uhp->uh_seq, changes);
30343034
u_add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff),
30353035
uhp->uh_time);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static char *(features[]) =
762762

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1677,
765767
/**/
766768
1676,
767769
/**/

src/vim.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,11 +2549,4 @@ typedef enum {
25492549
#define TERM_START_FORCEIT 2
25502550
#define TERM_START_SYSTEM 4
25512551

2552-
/* Not generated automatically, to add extra attribute. */
2553-
void ch_log(channel_T *ch, const char *fmt, ...)
2554-
#ifdef __GNUC__
2555-
__attribute__((format(printf, 2, 3)))
2556-
#endif
2557-
;
2558-
25592552
#endif /* VIM__H */

0 commit comments

Comments
 (0)