Skip to content

Commit b5443cc

Browse files
committed
patch 8.1.0753: printf format not checked for semsg()
Problem: printf format not checked for semsg(). Solution: Add GNUC attribute and fix reported problems. (Dominique Pelle, closes #3805)
1 parent 8e481e8 commit b5443cc

File tree

16 files changed

+55
-31
lines changed

16 files changed

+55
-31
lines changed

src/buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ do_buffer(
14071407
else
14081408
#endif
14091409
{
1410-
semsg(_("E89: No write since last change for buffer %ld (add ! to override)"),
1410+
semsg(_("E89: No write since last change for buffer %d (add ! to override)"),
14111411
buf->b_fnum);
14121412
return FAIL;
14131413
}
@@ -2283,7 +2283,7 @@ buflist_getfile(
22832283
if ((options & GETF_ALT) && n == 0)
22842284
emsg(_(e_noalt));
22852285
else
2286-
semsg(_("E92: Buffer %ld not found"), n);
2286+
semsg(_("E92: Buffer %d not found"), n);
22872287
return FAIL;
22882288
}
22892289

src/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ diff_buf_add(buf_T *buf)
173173
return;
174174
}
175175

176-
semsg(_("E96: Cannot diff more than %ld buffers"), DB_COUNT);
176+
semsg(_("E96: Cannot diff more than %d buffers"), DB_COUNT);
177177
}
178178

179179
/*

src/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ compare_func_name(const void *s1, const void *s2)
268268

269269
/*
270270
* Sort the function table by function name.
271-
* The sorting of the table above is ASCII dependant.
271+
* The sorting of the table above is ASCII dependent.
272272
* On machines using EBCDIC we have to sort it.
273273
*/
274274
static void

src/evalfunc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8256,7 +8256,7 @@ f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
82568256
return;
82578257
if (id >= 1 && id <= 3)
82588258
{
8259-
semsg(_("E798: ID is reserved for \":match\": %ld"), id);
8259+
semsg(_("E798: ID is reserved for \":match\": %d"), id);
82608260
return;
82618261
}
82628262

@@ -8314,7 +8314,7 @@ f_matchaddpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
83148314
/* id == 3 is ok because matchaddpos() is supposed to substitute :3match */
83158315
if (id == 1 || id == 2)
83168316
{
8317-
semsg(_("E798: ID is reserved for \":match\": %ld"), id);
8317+
semsg(_("E798: ID is reserved for \":match\": %d"), id);
83188318
return;
83198319
}
83208320

src/ex_docmd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ do_cmdline(
13471347
}
13481348
else if (p != NULL)
13491349
{
1350-
semsg(p);
1350+
emsg(p);
13511351
vim_free(p);
13521352
}
13531353
vim_free(sourcing_name);
@@ -5788,8 +5788,8 @@ check_more(
57885788
return FAIL;
57895789
}
57905790
#endif
5791-
semsg(NGETTEXT("E173: %ld more file to edit",
5792-
"E173: %ld more files to edit", n), n);
5791+
semsg(NGETTEXT("E173: %d more file to edit",
5792+
"E173: %d more files to edit", n), n);
57935793
quitmore = 2; /* next try to quit is allowed */
57945794
}
57955795
return FAIL;
@@ -6958,7 +6958,7 @@ do_ucmd(exarg_T *eap)
69586958
}
69596959
}
69606960

6961-
/* break if there no <item> is found */
6961+
/* break if no <item> is found */
69626962
if (start == NULL || end == NULL)
69636963
break;
69646964

@@ -8022,7 +8022,7 @@ handle_drop_internal(void)
80228022
/*
80238023
* Handle a file drop. The code is here because a drop is *nearly* like an
80248024
* :args command, but not quite (we have a list of exact filenames, so we
8025-
* don't want to (a) parse a command line, or (b) expand wildcards. So the
8025+
* don't want to (a) parse a command line, or (b) expand wildcards). So the
80268026
* code is very similar to :args and hence needs access to a lot of the static
80278027
* functions in this file.
80288028
*

src/gui_x11.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,9 +2210,10 @@ check_fontset_sanity(XFontSet fs)
22102210
semsg(_("E253: Fontset name: %s"), base_name);
22112211
semsg(_("Font0: %s"), font_name[min_font_idx]);
22122212
semsg(_("Font1: %s"), font_name[i]);
2213-
semsg(_("Font%ld width is not twice that of font0"), i);
2214-
semsg(_("Font0 width: %ld"), xfs[min_font_idx]->max_bounds.width);
2215-
semsg(_("Font1 width: %ld"), xfs[i]->max_bounds.width);
2213+
semsg(_("Font%d width is not twice that of font0"), i);
2214+
semsg(_("Font0 width: %d"),
2215+
(int)xfs[min_font_idx]->max_bounds.width);
2216+
semsg(_("Font%d width: %d"), i, (int)xfs[i]->max_bounds.width);
22162217
return FAIL;
22172218
}
22182219
}

src/if_cscope.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ cs_cnt_connections(void)
651651
cs_reading_emsg(
652652
int idx) /* connection index */
653653
{
654-
semsg(_("E262: error reading cscope connection %ld"), idx);
654+
semsg(_("E262: error reading cscope connection %d"), idx);
655655
}
656656

657657
#define CSREAD_BUFSIZE 2048

src/netbeans.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ nb_do_cmd(
15411541
if (!buf->bufp->b_netbeans_file)
15421542
{
15431543
nbdebug(("E658: NetBeans connection lost for buffer %ld\n", buf->bufp->b_fnum));
1544-
semsg(_("E658: NetBeans connection lost for buffer %ld"),
1544+
semsg(_("E658: NetBeans connection lost for buffer %d"),
15451545
buf->bufp->b_fnum);
15461546
}
15471547
else

src/proto.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,31 @@ int
108108
# ifdef __BORLANDC__
109109
_RTLENTRYF
110110
# endif
111-
smsg(const char *, ...);
111+
smsg(const char *, ...)
112+
#ifdef USE_PRINTF_FORMAT_ATTRIBUTE
113+
__attribute__((format(printf, 1, 0)))
114+
#endif
115+
;
112116

113117
int
114118
# ifdef __BORLANDC__
115119
_RTLENTRYF
116120
# endif
117-
smsg_attr(int, const char *, ...);
121+
smsg_attr(int, const char *, ...)
122+
#ifdef USE_PRINTF_FORMAT_ATTRIBUTE
123+
__attribute__((format(printf, 2, 3)))
124+
#endif
125+
;
118126

119127
int
120128
# ifdef __BORLANDC__
121129
_RTLENTRYF
122130
# endif
123-
smsg_attr_keep(int, const char *, ...);
131+
smsg_attr_keep(int, const char *, ...)
132+
#ifdef USE_PRINTF_FORMAT_ATTRIBUTE
133+
__attribute__((format(printf, 2, 3)))
134+
#endif
135+
;
124136

125137
int
126138
# ifdef __BORLANDC__

src/proto/message.pro

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ int emsg_not_now(void);
1111
void ignore_error_for_testing(char_u *error);
1212
void do_perror(char *msg);
1313
int emsg(char *s);
14-
int semsg(const char *s, ...);
14+
15+
int semsg(const char *s, ...)
16+
#ifdef USE_PRINTF_FORMAT_ATTRIBUTE
17+
__attribute__((format(printf, 1, 2)))
18+
#endif
19+
;
1520
void iemsg(char *s);
16-
void siemsg(const char *s, ...);
21+
void siemsg(const char *s, ...)
22+
#ifdef USE_PRINTF_FORMAT_ATTRIBUTE
23+
__attribute__((format(printf, 1, 2)))
24+
#endif
25+
;
1726
void internal_error(char *where);
1827
void emsg_invreg(int name);
1928
char_u *msg_trunc_attr(char_u *s, int force, int attr);

0 commit comments

Comments
 (0)