From: Sebastian Harl Date: Fri, 22 Aug 2014 06:06:04 +0000 (-0700) Subject: Added __attribute__((format(printf, ...))) where appropriate. X-Git-Tag: sysdb-0.4.0~10 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f78d30d42f9fe3b58f1c2132cafe4c8687b8bd46;p=sysdb.git Added __attribute__((format(printf, ...))) where appropriate. Also, fixed various (mostly minor) issues identified this way. --- diff --git a/src/frontend/connection.c b/src/frontend/connection.c index 6888e39..ce16a8b 100644 --- a/src/frontend/connection.c +++ b/src/frontend/connection.c @@ -302,7 +302,7 @@ command_init(sdb_conn_t *conn) return -1; /* reset */ - sdb_strbuf_sprintf(conn->errbuf, ""); + sdb_strbuf_clear(conn->errbuf); conn->cmd = connection_get_int32(conn, 0); conn->cmd_len = connection_get_int32(conn, sizeof(uint32_t)); @@ -317,7 +317,7 @@ command_init(sdb_conn_t *conn) if (errmsg) { size_t len = sdb_strbuf_len(conn->buf); - sdb_strbuf_sprintf(conn->errbuf, errmsg); + sdb_strbuf_sprintf(conn->errbuf, "%s", errmsg); sdb_connection_send(conn, CONNECTION_ERROR, (uint32_t)strlen(errmsg), errmsg); conn->skip_len += conn->cmd_len; diff --git a/src/frontend/query.c b/src/frontend/query.c index e0b7181..bbf9853 100644 --- a/src/frontend/query.c +++ b/src/frontend/query.c @@ -102,7 +102,7 @@ sdb_fe_query(sdb_conn_t *conn) char query[conn->cmd_len + 1]; strncpy(query, sdb_strbuf_string(conn->buf), conn->cmd_len); query[sizeof(query) - 1] = '\0'; - sdb_log(SDB_LOG_WARNING, "frontend: Ignoring %d command%s " + sdb_log(SDB_LOG_WARNING, "frontend: Ignoring %zu command%s " "in multi-statement query '%s'", sdb_llist_len(parsetree) - 1, sdb_llist_len(parsetree) == 2 ? "" : "s", diff --git a/src/frontend/sock.c b/src/frontend/sock.c index dd0afa9..96bc04b 100644 --- a/src/frontend/sock.c +++ b/src/frontend/sock.c @@ -543,8 +543,8 @@ sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock, sdb_fe_loop_t *loop) return -1; } - sdb_log(SDB_LOG_INFO, "frontend: Starting %d connection " - "handler thread%s managing %d listener%s", + sdb_log(SDB_LOG_INFO, "frontend: Starting %zu connection " + "handler thread%s managing %zu listener%s", loop->num_threads, loop->num_threads == 1 ? "" : "s", sock->listeners_num, sock->listeners_num == 1 ? "" : "s"); diff --git a/src/include/core/plugin.h b/src/include/core/plugin.h index 0dce877..4e5d104 100644 --- a/src/include/core/plugin.h +++ b/src/include/core/plugin.h @@ -373,9 +373,11 @@ sdb_plugin_log(int prio, const char *msg); * Log a formatted message. See sdb_plugin_log for more information. */ int -sdb_plugin_vlogf(int prio, const char *fmt, va_list ap); +sdb_plugin_vlogf(int prio, const char *fmt, va_list ap) + __attribute__((format(printf, 2, 0))); int -sdb_plugin_logf(int prio, const char *fmt, ...); +sdb_plugin_logf(int prio, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); /* * sdb_plugin_fetch_timeseries: diff --git a/src/include/core/time.h b/src/include/core/time.h index c97e121..c48a2e1 100644 --- a/src/include/core/time.h +++ b/src/include/core/time.h @@ -74,7 +74,8 @@ int sdb_sleep(sdb_time_t reg, sdb_time_t *rem); size_t -sdb_strftime(char *s, size_t len, const char *format, sdb_time_t); +sdb_strftime(char *s, size_t len, const char *format, sdb_time_t) + __attribute__((format(strftime, 3, 0))); size_t sdb_strfinterval(char *s, size_t len, sdb_time_t interval); diff --git a/src/include/utils/error.h b/src/include/utils/error.h index b9256bb..2c3df32 100644 --- a/src/include/utils/error.h +++ b/src/include/utils/error.h @@ -80,7 +80,8 @@ sdb_error_set_logger(int (*f)(int, const char *)); * on configuration, try a clean shut-down of the process. */ int -sdb_log(int prio, const char *fmt, ...); +sdb_log(int prio, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); /* * sdb_error_set, sdb_error_append: @@ -89,9 +90,11 @@ sdb_log(int prio, const char *fmt, ...); * be done. */ int -sdb_error_set(const char *fmt, ...); +sdb_error_set(const char *fmt, ...) + __attribute__((format(printf, 1, 2))); int -sdb_error_append(const char *fmt, ...); +sdb_error_append(const char *fmt, ...) + __attribute__((format(printf, 1, 2))); /* * sdb_error_chomp: diff --git a/src/include/utils/strbuf.h b/src/include/utils/strbuf.h index 20cf870..5e9913d 100644 --- a/src/include/utils/strbuf.h +++ b/src/include/utils/strbuf.h @@ -74,9 +74,11 @@ sdb_strbuf_destroy(sdb_strbuf_t *strbuf); * - a negative value on error */ ssize_t -sdb_strbuf_vappend(sdb_strbuf_t *strbuf, const char *fmt, va_list ap); +sdb_strbuf_vappend(sdb_strbuf_t *strbuf, const char *fmt, va_list ap) + __attribute__((format(printf, 2, 0))); ssize_t -sdb_strbuf_append(sdb_strbuf_t *strbuf, const char *fmt, ...); +sdb_strbuf_append(sdb_strbuf_t *strbuf, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); /* * sdb_strbuf_vsprintf, sdb_strbuf_sprintf: @@ -90,9 +92,11 @@ sdb_strbuf_append(sdb_strbuf_t *strbuf, const char *fmt, ...); * - a negative value on error */ ssize_t -sdb_strbuf_vsprintf(sdb_strbuf_t *strbuf, const char *fmt, va_list ap); +sdb_strbuf_vsprintf(sdb_strbuf_t *strbuf, const char *fmt, va_list ap) + __attribute__((format(printf, 2, 0))); ssize_t -sdb_strbuf_sprintf(sdb_strbuf_t *strbuf, const char *fmt, ...); +sdb_strbuf_sprintf(sdb_strbuf_t *strbuf, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); /* * sdb_strbuf_memcpy, sdb_strbuf_memappend: diff --git a/src/tools/sysdb/input.c b/src/tools/sysdb/input.c index 21a2e5d..55a074c 100644 --- a/src/tools/sysdb/input.c +++ b/src/tools/sysdb/input.c @@ -129,8 +129,7 @@ handle_input(char *line) return; } - sdb_strbuf_append(sysdb_input->input, line); - sdb_strbuf_append(sysdb_input->input, "\n"); + sdb_strbuf_append(sysdb_input->input, "%s\n", line); free(line); if (sysdb_input->interactive) diff --git a/t/unit/utils/strbuf_test.c b/t/unit/utils/strbuf_test.c index b0159c4..e7cb9f5 100644 --- a/t/unit/utils/strbuf_test.c +++ b/t/unit/utils/strbuf_test.c @@ -177,7 +177,7 @@ START_TEST(test_append) size_t i; for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { - n = sdb_strbuf_append(buf, golden_data[i].input); + n = sdb_strbuf_append(buf, "%s", golden_data[i].input); fail_unless((size_t)n == strlen(golden_data[i].input), "sdb_strbuf_append() appended %zi bytes; expected: %zu", n, strlen(golden_data[i].input)); @@ -198,7 +198,7 @@ START_TEST(test_append) test, golden_data[i].result); } - n = sdb_strbuf_append(buf, "%zu; %5.4f", 42, 4.2); + n = sdb_strbuf_append(buf, "%zu; %5.4f", (size_t)42, 4.2); fail_unless(n == 10, "sdb_strbuf_append() appended %zi bytes; expected: 10", n); total += n; @@ -234,7 +234,7 @@ START_TEST(test_sprintf) size_t i; for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { - n = sdb_strbuf_sprintf(buf, golden_data[i]); + n = sdb_strbuf_sprintf(buf, "%s", golden_data[i]); fail_unless((size_t)n == strlen(golden_data[i]), "sdb_strbuf_sprintf() wrote %zi bytes; expected: %zu", n, strlen(golden_data[i])); @@ -258,7 +258,7 @@ START_TEST(test_sprintf) check, n, n / 3); } - n = sdb_strbuf_sprintf(buf, "%zu; %5.4f", 42, 4.2); + n = sdb_strbuf_sprintf(buf, "%zu; %5.4f", (size_t)42, 4.2); fail_unless(n == 10, "sdb_strbuf_sprintf() wrote %zi bytes; expected: 10", n); check = sdb_strbuf_len(buf); @@ -449,7 +449,7 @@ START_TEST(test_chomp) const char *check; if (golden_data[i].input) - sdb_strbuf_sprintf(buf, golden_data[i].input); + sdb_strbuf_sprintf(buf, "%s", golden_data[i].input); /* empty buffer */ n = sdb_strbuf_chomp(buf); @@ -511,7 +511,7 @@ START_TEST(test_skip) const char *check; size_t n; - sdb_strbuf_sprintf(buf, input); + sdb_strbuf_sprintf(buf, "%s", input); sdb_strbuf_skip(buf, golden_data[i].offset, golden_data[i].n); @@ -573,7 +573,7 @@ START_TEST(test_string) const char *check; if (golden_data[i].input) - sdb_strbuf_sprintf(buf, golden_data[i].input); + sdb_strbuf_sprintf(buf, "%s", golden_data[i].input); check = sdb_strbuf_string(buf); fail_unless(!strcmp(check, golden_data[i].expected), "sdb_strbuf_string() = '%s'; expected: '%s'", @@ -599,7 +599,7 @@ START_TEST(test_len) size_t check; if (golden_data[i].input) - sdb_strbuf_sprintf(buf, golden_data[i].input); + sdb_strbuf_sprintf(buf, "%s", golden_data[i].input); check = sdb_strbuf_len(buf); fail_unless(check == golden_data[i].expected, "sdb_strbuf_len() = %zu; expected: %zu",