From 02dc60a51d0e07f43eb6c3de2b7c07992af39a65 Mon Sep 17 00:00:00 2001 From: William Smith Date: Sun, 13 Jan 2013 18:35:59 -0500 Subject: [PATCH] debug: add proper const attribute to function arguments MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add proper const attribute to function arguments. Also add format attribute to debug_fmt() function. This fixes many warnings in many files, for example: ssl_cli.c: In function ‘ssl_write_client_hello’: ssl_cli.c:55: warning: passing argument 3 of ‘debug_print_msg’ discards qualifiers from pointer target type const attribute is added to function arguments and variables in order to allow compiler checks with -Wbad-function-cast, -Wcast-qual and -Wwrite-strings warnings options. --- include/tropicssl/debug.h | 31 ++++++++++++++++++++----------- library/debug.c | 26 +++++++++++++++----------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/include/tropicssl/debug.h b/include/tropicssl/debug.h index ffe240c..6864b8c 100644 --- a/include/tropicssl/debug.h +++ b/include/tropicssl/debug.h @@ -65,27 +65,36 @@ #endif +#ifdef __GNUC__ +#define __tropicssl_debug_fmt_format__ __attribute__((format(printf, 1, 2))) +#else /* __GNUC__ */ +#define __tropicssl_debug_fmt_format__ +#endif /* __GNUC__ */ + #ifdef __cplusplus extern "C" { #endif - char *debug_fmt(const char *format, ...); + char *debug_fmt(const char *format, ...) __tropicssl_debug_fmt_format__; - void debug_print_msg(ssl_context * ssl, int level, - char *file, int line, char *text); + void debug_print_msg(const ssl_context * ssl, int level, + const char *file, int line, const char *text); - void debug_print_ret(ssl_context * ssl, int level, - char *file, int line, char *text, int ret); + void debug_print_ret(const ssl_context * ssl, int level, + const char *file, int line, + const char *text, int ret); - void debug_print_buf(ssl_context * ssl, int level, - char *file, int line, char *text, + void debug_print_buf(const ssl_context * ssl, int level, + const char *file, int line, const char *text, unsigned char *buf, int len); - void debug_print_mpi(ssl_context * ssl, int level, - char *file, int line, char *text, mpi * X); + void debug_print_mpi(const ssl_context * ssl, int level, + const char *file, int line, + const char *text, const mpi * X); - void debug_print_crt(ssl_context * ssl, int level, - char *file, int line, char *text, x509_cert * crt); + void debug_print_crt(const ssl_context * ssl, int level, + const char *file, int line, + const char *text, const x509_cert * crt); #ifdef __cplusplus } diff --git a/library/debug.c b/library/debug.c index 48fc391..74bbf37 100644 --- a/library/debug.c +++ b/library/debug.c @@ -64,8 +64,8 @@ char *debug_fmt(const char *format, ...) return (str); } -void debug_print_msg(ssl_context * ssl, int level, - char *file, int line, char *text) +void debug_print_msg(const ssl_context * ssl, int level, + const char *file, int line, const char *text) { char str[512]; int maxlen = sizeof(str) - 1; @@ -78,8 +78,9 @@ void debug_print_msg(ssl_context * ssl, int level, ssl->f_dbg(ssl->p_dbg, level, str); } -void debug_print_ret(ssl_context * ssl, int level, - char *file, int line, char *text, int ret) +void debug_print_ret(const ssl_context * ssl, int level, + const char *file, int line, + const char *text, int ret) { char str[512]; int maxlen = sizeof(str) - 1; @@ -94,8 +95,8 @@ void debug_print_ret(ssl_context * ssl, int level, ssl->f_dbg(ssl->p_dbg, level, str); } -void debug_print_buf(ssl_context * ssl, int level, - char *file, int line, char *text, +void debug_print_buf(const ssl_context * ssl, int level, + const char *file, int line, const char *text, unsigned char *buf, int len) { char str[512]; @@ -135,8 +136,9 @@ void debug_print_buf(ssl_context * ssl, int level, ssl->f_dbg(ssl->p_dbg, level, "\n"); } -void debug_print_mpi(ssl_context * ssl, int level, - char *file, int line, char *text, mpi * X) +void debug_print_mpi(const ssl_context * ssl, int level, + const char *file, int line, + const char *text, const mpi * X) { char str[512]; int i, j, k, n, maxlen = sizeof(str) - 1; @@ -149,7 +151,8 @@ void debug_print_mpi(ssl_context * ssl, int level, break; snprintf(str, maxlen, "%s(%04d): value of '%s' (%lu bits) is:\n", - file, line, text, ((n + 1) * sizeof(t_int)) << 3); + file, line, text, + (unsigned long)((n + 1) * sizeof(t_int)) << 3); str[maxlen] = '\0'; ssl->f_dbg(ssl->p_dbg, level, str); @@ -177,8 +180,9 @@ void debug_print_mpi(ssl_context * ssl, int level, ssl->f_dbg(ssl->p_dbg, level, "\n"); } -void debug_print_crt(ssl_context * ssl, int level, - char *file, int line, char *text, x509_cert * crt) +void debug_print_crt(const ssl_context * ssl, int level, + const char *file, int line, + const char *text, const x509_cert * crt) { char str[512], prefix[64], *p; int i = 0, maxlen = sizeof(prefix) - 1; -- 2.11.4.GIT