Skip to content

Commit 4ac2e8d

Browse files
committed
patch 8.0.1676: no compiler warning for wrong printf format
Problem: No compiler warning for wrong printf format. Solution: Add a printf attribute for gcc. Fix reported problems. (Dominique Pelle, closes #2789)
1 parent 8200829 commit 4ac2e8d

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/channel.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ ch_log_lead(const char *what, channel_T *ch)
158158

159159
static int did_log_msg = TRUE;
160160

161+
#ifndef PROTO /* prototype is in vim.h */
161162
void
162163
ch_log(channel_T *ch, const char *fmt, ...)
163164
{
@@ -174,6 +175,14 @@ ch_log(channel_T *ch, const char *fmt, ...)
174175
did_log_msg = TRUE;
175176
}
176177
}
178+
#endif
179+
180+
static void
181+
ch_error(channel_T *ch, const char *fmt, ...)
182+
#ifdef __GNUC__
183+
__attribute__((format(printf, 2, 3)))
184+
#endif
185+
;
177186

178187
static void
179188
ch_error(channel_T *ch, const char *fmt, ...)
@@ -1442,8 +1451,8 @@ channel_write_in(channel_T *channel)
14421451
ch_close_part(channel, PART_IN);
14431452
}
14441453
else
1445-
ch_log(channel, "Still %d more lines to write",
1446-
buf->b_ml.ml_line_count - lnum + 1);
1454+
ch_log(channel, "Still %ld more lines to write",
1455+
(long)(buf->b_ml.ml_line_count - lnum + 1));
14471456
}
14481457

14491458
/*
@@ -1536,8 +1545,8 @@ channel_write_new_lines(buf_T *buf)
15361545
else if (written > 1)
15371546
ch_log(channel, "written %d lines to channel", written);
15381547
if (lnum < buf->b_ml.ml_line_count)
1539-
ch_log(channel, "Still %d more lines to write",
1540-
buf->b_ml.ml_line_count - lnum);
1548+
ch_log(channel, "Still %ld more lines to write",
1549+
(long)(buf->b_ml.ml_line_count - lnum));
15411550

15421551
in_part->ch_buf_bot = lnum;
15431552
}
@@ -2081,7 +2090,8 @@ channel_get_json(
20812090
{
20822091
*rettv = item->jq_value;
20832092
if (tv->v_type == VAR_NUMBER)
2084-
ch_log(channel, "Getting JSON message %d", tv->vval.v_number);
2093+
ch_log(channel, "Getting JSON message %ld",
2094+
(long)tv->vval.v_number);
20852095
remove_json_node(head, item);
20862096
return OK;
20872097
}

src/proto/channel.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* channel.c */
22
void ch_logfile(char_u *fname, char_u *opt);
33
int ch_log_active(void);
4-
void ch_log(channel_T *ch, const char *fmt, ...);
54
channel_T *add_channel(void);
65
int has_any_channel(void);
76
int channel_unref(channel_T *channel);

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+
1676,
765767
/**/
766768
1675,
767769
/**/

src/vim.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,4 +2549,11 @@ 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+
25522559
#endif /* VIM__H */

0 commit comments

Comments
 (0)