Skip to content

Commit a888914

Browse files
authored
Issue #1011: Add the format __attribute__ to still more functions (#1061)
Functions which don't take actual format parameters can set the third argument to 0, and then the compiler simply syntax-checks the formatting string literal (and skips checking if the parameter types match). This way, even functions that take `va_list`, or functions that produce the parameters themselves, can be annotated.
1 parent 2206bab commit a888914

File tree

7 files changed

+9
-6
lines changed

7 files changed

+9
-6
lines changed

include/qpid/dispatch/error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ ENUM_DECLARE(qd_error);
7070

7171
qd_error_t qd_error_impl(qd_error_t code, const char *file, int line, const char *fmt, ...)
7272
__attribute__((format(printf, 4, 5)));
73-
qd_error_t qd_error_vimpl(qd_error_t code, const char *file, int line, const char *fmt, va_list ap);
73+
qd_error_t qd_error_vimpl(qd_error_t code, const char *file, int line, const char *fmt, va_list ap)
74+
__attribute__((format(printf, 4, 0)));
7475

7576
/**
7677
* Clear thread-local error code and message.

include/qpid/dispatch/log.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ void qd_log_impl(qd_log_source_t *source, qd_log_level_t level, const char *file
5353
*/
5454
void qd_log_impl_v1(qd_log_source_t *source, qd_log_level_t level, const char *file, int line, const char *fmt, ...)
5555
__attribute__((format(printf, 5, 6)));
56-
void qd_vlog_impl(qd_log_source_t *source, qd_log_level_t level, bool check_level, const char *file, int line, const char *fmt, va_list ap);
56+
void qd_vlog_impl(qd_log_source_t *source, qd_log_level_t level, bool check_level, const char *file, int line, const char *fmt, va_list ap)
57+
__attribute__((format(printf, 6, 0)));
5758

5859
/** Log a message
5960
* Note: does not evaluate the format args unless the log message is enabled.

src/aprintf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
Variadic appending printf - see aprintf()
2626
*/
27-
int vaprintf(char **begin, char *end, const char *format, va_list ap_in);
27+
int vaprintf(char **begin, char *end, const char *format, va_list ap_in) __attribute__((format(printf, 3, 0)));
2828

2929
/**
3030
Appending printf.

src/message.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static void quote(char* bytes, int n, char **begin, char *end) {
135135
/**
136136
* Populates the buffer with formatted epoch_time
137137
*/
138+
__attribute__((format(strftime, 2, 0)))
138139
static void format_time(pn_timestamp_t epoch_time, char *format, char *buffer, size_t len)
139140
{
140141
struct timeval local_timeval;

tests/clogger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const uint8_t msg_header[] = {
9797
};
9898

9999

100-
void debug(const char *format, ...)
100+
__attribute__((format(printf, 1, 2))) void debug(const char *format, ...)
101101
{
102102
va_list args;
103103

tests/test-receiver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ uint64_t count = 0;
5858
uint64_t limit = 0; // if > 0 stop after limit messages arrive
5959

6060

61-
void debug(const char *format, ...)
61+
__attribute__((format(printf, 1, 2))) void debug(const char *format, ...)
6262
{
6363
va_list args;
6464

tests/test-sender.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const char big_string[] =
110110
"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
111111

112112

113-
void debug(const char *format, ...)
113+
__attribute__((format(printf, 1, 2))) void debug(const char *format, ...)
114114
{
115115
va_list args;
116116

0 commit comments

Comments
 (0)