From 2f68fa390a61676a01cd82bc00e4a44867041299 Mon Sep 17 00:00:00 2001 From: Martin Nagy Date: Thu, 2 Jul 2009 18:19:07 +0200 Subject: Add annotations to printf-like functions The ISC_FORMAT_PRINTF() macro will make sure that gcc checks if these functions are used correctly. Also fix bugs that were found along the way. --- src/krb5_helper.c | 2 +- src/ldap_helper.c | 2 +- src/log.c | 2 ++ src/log.h | 4 ++-- src/str.h | 3 ++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/krb5_helper.c b/src/krb5_helper.c index c69a947..a52b412 100644 --- a/src/krb5_helper.c +++ b/src/krb5_helper.c @@ -137,7 +137,7 @@ get_krb5_tgt(isc_mem_t *mctx, const char *principal, const char *keyfile) krberr = krb5_cc_resolve(context, str_buf(ccname), &ccache); CHECK_KRB5(context, krberr, - "Failed to resolve ccache name %s", ccname); + "Failed to resolve ccache name %s", str_buf(ccname)); /* get krb5_principal from string */ krberr = krb5_parse_name(context, principal, &kprincpw); diff --git a/src/ldap_helper.c b/src/ldap_helper.c index aa5af2d..432efcd 100644 --- a/src/ldap_helper.c +++ b/src/ldap_helper.c @@ -1524,7 +1524,7 @@ ldap_sasl_interact(LDAP *ld, unsigned flags, void *defaults, void *sin) in->len = 0; ret = LDAP_OTHER; } - log_error("result: %s", in->result?in->result:""); + log_error("result: %s", (char *)(in->result?in->result:"")); } return ret; diff --git a/src/log.c b/src/log.c index 3bcd767..bdf2745 100644 --- a/src/log.c +++ b/src/log.c @@ -19,6 +19,8 @@ #include +#include + #include #include "log.h" diff --git a/src/log.h b/src/log.h index 00f772d..5446b04 100644 --- a/src/log.h +++ b/src/log.h @@ -42,7 +42,7 @@ log_func_va("exiting with %s", isc_result_totext(res)) /* Basic logging functions */ -void log_debug(int level, const char *format, ...); -void log_error(const char *format, ...); +void log_debug(int level, const char *format, ...) ISC_FORMAT_PRINTF(2, 3); +void log_error(const char *format, ...) ISC_FORMAT_PRINTF(1, 2); #endif /* !_LD_LOG_H_ */ diff --git a/src/str.h b/src/str.h index 4fdf177..7746a25 100644 --- a/src/str.h +++ b/src/str.h @@ -20,6 +20,7 @@ #ifndef _LD_STR_H_ #define _LD_STR_H_ +#include #include #define LD_MAX_SPLITS 256 @@ -55,7 +56,7 @@ isc_result_t str_cat_char_len(ld_string_t *dest, const char *src, size_t len); isc_result_t str_cat_isc_region(ld_string_t *dest, const isc_region_t *region); isc_result_t str_cat_isc_buffer(ld_string_t *dest, const isc_buffer_t *buffer); isc_result_t str_cat(ld_string_t *dest, const ld_string_t *src); -isc_result_t str_sprintf(ld_string_t *dest, const char *format, ...); +isc_result_t str_sprintf(ld_string_t *dest, const char *format, ...) ISC_FORMAT_PRINTF(2, 3); isc_result_t str_vsprintf(ld_string_t *dest, const char *format, va_list ap); void str_toupper(ld_string_t *str); -- cgit