From 0e960d940a3b52406bb72af2750b6b6d29e39067 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Tue, 20 Apr 2010 01:11:35 +0000 Subject: [PATCH] common/ 2010-04-20 Marcus Brinkmann * logging.c (do_log_ignore_arg): New helper function. (log_string): Use it to remove ugly volatile hack that causes gcc warning. (log_flush): Likewise. * sysutils.c (gnupg_unsetenv) [!HAVE_W32CE_SYSTEM]: Return something. (gnupg_setenv) [!HAVE_W32CE_SYSTEM]: Likewise. * pka.c (get_pka_info): Solve strict aliasing rule violation. * t-exechelp.c (test_close_all_fds): Use dummy variables to silence gcc warning. kbx/ 2010-04-20 Marcus Brinkmann * keybox-update.c [!HAVE_DOSISH_SYSTEM]: Include ../common/sysutils.h even then to silence gcc warning about missing declaration of gnupg_remove. tools/ 2010-04-20 Marcus Brinkmann * gpgconf-comp.c (option_check_validity): Use dummy variables to silence gcc warning. --- common/ChangeLog | 12 ++++++++++++ common/logging.c | 24 +++++++++++++++--------- common/pka.c | 20 +++++++++++++------- common/signal.c | 16 +++++++++------- common/sysutils.c | 6 +++--- common/t-exechelp.c | 11 ++++++----- kbx/ChangeLog | 6 ++++++ kbx/keybox-update.c | 2 -- tools/ChangeLog | 5 +++++ tools/gpgconf-comp.c | 10 ++++++++-- 10 files changed, 77 insertions(+), 35 deletions(-) diff --git a/common/ChangeLog b/common/ChangeLog index 7a6c33743..dce7cb3f6 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,15 @@ +2010-04-20 Marcus Brinkmann + + * logging.c (do_log_ignore_arg): New helper function. + (log_string): Use it to remove ugly volatile hack that causes gcc + warning. + (log_flush): Likewise. + * sysutils.c (gnupg_unsetenv) [!HAVE_W32CE_SYSTEM]: Return something. + (gnupg_setenv) [!HAVE_W32CE_SYSTEM]: Likewise. + * pka.c (get_pka_info): Solve strict aliasing rule violation. + * t-exechelp.c (test_close_all_fds): Use dummy variables to + silence gcc warning. + 2010-04-14 Werner Koch * Makefile.am (noinst_LIBRARIES) [W32CE]: Exclude libsimple-pwquery. diff --git a/common/logging.c b/common/logging.c index 5641b71e7..f014d9fca 100644 --- a/common/logging.c +++ b/common/logging.c @@ -515,16 +515,23 @@ log_logv (int level, const char *fmt, va_list arg_ptr) } +static void +do_log_ignore_arg (int level, const char *str, ...) +{ + va_list arg_ptr; + va_start (arg_ptr, str); + do_logv (level, 1, str, arg_ptr); + va_end (arg_ptr); +} + + void log_string (int level, const char *string) { - /* We need to provide a dummy arg_ptr. volatile is needed to - suppress compiler warnings. The static is required for gcc 4.4 - because it seems that it detects that a volatile automatic - variable is not any good if not initialized. */ - static volatile va_list dummy_arg_ptr; - - do_logv (level, 1, string, dummy_arg_ptr); + /* We need a dummy arg_ptr, but there is no portable way to create + one. So we call the do_logv function through a variadic wrapper. + MB: Why not just use "%s"? */ + do_log_ignore_arg (level, string); } @@ -604,8 +611,7 @@ log_printf (const char *fmt, ...) void log_flush (void) { - static volatile va_list dummy_arg_ptr; - do_logv (JNLIB_LOG_CONT, 1, NULL, dummy_arg_ptr); + do_log_ignore_arg (JNLIB_LOG_CONT, NULL); } diff --git a/common/pka.c b/common/pka.c index 751ccf7c2..5cdc323e6 100644 --- a/common/pka.c +++ b/common/pka.c @@ -180,7 +180,7 @@ get_pka_info (const char *address, unsigned char *fpr) unsigned char *p, *pend; const char *domain; char *name; - + HEADER header; domain = strrchr (address, '@'); if (!domain || domain == address || !domain[1]) @@ -196,18 +196,24 @@ get_pka_info (const char *address, unsigned char *fpr) xfree (name); if (anslen < sizeof(HEADER)) return NULL; /* DNS resolver returned a too short answer. */ - if ( (rc=((HEADER*)answer)->rcode) != NOERROR ) + + /* Don't despair: A good compiler should optimize this away, as + header is just 32 byte and constant at compile time. It's + one way to comply with strict aliasing rules. */ + memcpy (&header, answer, sizeof (header)); + + if ( (rc=header.rcode) != NOERROR ) return NULL; /* DNS resolver returned an error. */ /* We assume that PACKETSZ is large enough and don't do dynmically expansion of the buffer. */ if (anslen > PACKETSZ) return NULL; /* DNS resolver returned a too long answer */ - - qdcount = ntohs (((HEADER*)answer)->qdcount); - ancount = ntohs (((HEADER*)answer)->ancount); - nscount = ntohs (((HEADER*)answer)->nscount); - arcount = ntohs (((HEADER*)answer)->arcount); + + qdcount = ntohs (header.qdcount); + ancount = ntohs (header.ancount); + nscount = ntohs (header.nscount); + arcount = ntohs (header.arcount); if (!ancount) return NULL; /* Got no answer. */ diff --git a/common/signal.c b/common/signal.c index 422f6af3a..ee55f1917 100644 --- a/common/signal.c +++ b/common/signal.c @@ -89,6 +89,8 @@ get_signal_name( int signum ) static RETSIGTYPE got_fatal_signal (int sig) { + /* Dummy result variable to suppress gcc warning. */ + int res; const char *s; if (caught_fatal_sig) @@ -98,14 +100,14 @@ got_fatal_signal (int sig) if (cleanup_fnc) cleanup_fnc (); /* Better don't translate these messages. */ - write (2, "\n", 1 ); + res = write (2, "\n", 1 ); s = log_get_prefix (NULL); if (s) - write(2, s, strlen (s)); - write (2, ": signal ", 9 ); + res = write(2, s, strlen (s)); + res = write (2, ": signal ", 9 ); s = get_signal_name(sig); if (s) - write (2, s, strlen(s) ); + res = write (2, s, strlen(s) ); else { /* We are in a signal handler so we can't use any kind of printf @@ -115,7 +117,7 @@ got_fatal_signal (int sig) things are messed up because we modify its value. Although this is a bug in that system, we will protect against it. */ if (sig < 0 || sig >= 100000) - write (2, "?", 1); + res = write (2, "?", 1); else { int i, value, any=0; @@ -124,7 +126,7 @@ got_fatal_signal (int sig) { if (value >= i || ((any || i==1) && !(value/i))) { - write (2, "0123456789"+(value/i), 1); + res = write (2, "0123456789"+(value/i), 1); if ((value/i)) any = 1; value %= i; @@ -132,7 +134,7 @@ got_fatal_signal (int sig) } } } - write (2, " caught ... exiting\n", 20); + res = write (2, " caught ... exiting\n", 20); /* Reset action to default action and raise signal again */ init_one_signal (sig, SIG_DFL, 0); diff --git a/common/sysutils.c b/common/sysutils.c index 9e5717649..c6c9bda8e 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -604,7 +604,7 @@ gnupg_setenv (const char *name, const char *value, int overwrite) (void)overwrite; return 0; #else - setenv (name, value, overwrite); + return setenv (name, value, overwrite); #endif } @@ -616,9 +616,9 @@ gnupg_unsetenv (const char *name) return 0; #else # ifdef HAVE_UNSETENV - unsetenv (name); + return unsetenv (name); # else - putenv (name); + return putenv (name); # endif #endif } diff --git a/common/t-exechelp.c b/common/t-exechelp.c index 600379b69..5c5c5d311 100644 --- a/common/t-exechelp.c +++ b/common/t-exechelp.c @@ -76,6 +76,7 @@ test_close_all_fds (void) int max_fd = get_max_fds (); int *array; int fd; + int dummy_fd; int initial_count, count, n; #if 0 char buffer[100]; @@ -92,10 +93,10 @@ test_close_all_fds (void) free (array); /* Some dups to get more file descriptors and close one. */ - dup (1); - dup (1); + dummy_fd = dup (1); + dummy_fd = dup (1); fd = dup (1); - dup (1); + dummy_fd = dup (1); close (fd); array = xget_all_open_fds (); @@ -136,14 +137,14 @@ test_close_all_fds (void) int except[] = { 20, 23, 24, -1 }; for (n=initial_count; n < 31; n++) - dup (1); + dummy_fd = dup (1); array = xget_all_open_fds (); if (verbose) print_open_fds (array); free (array); for (n=0; n < 5; n++) { - dup (1); + dummy_fd = dup (1); array = xget_all_open_fds (); if (verbose) print_open_fds (array); diff --git a/kbx/ChangeLog b/kbx/ChangeLog index 95c6477a4..c64da6cd6 100644 --- a/kbx/ChangeLog +++ b/kbx/ChangeLog @@ -1,3 +1,9 @@ +2010-04-20 Marcus Brinkmann + + * keybox-update.c [!HAVE_DOSISH_SYSTEM]: Include + ../common/sysutils.h even then to silence gcc warning about + missing declaration of gnupg_remove. + 2010-03-23 Werner Koch * Makefile.am (extra_libs): New. diff --git a/kbx/keybox-update.c b/kbx/keybox-update.c index c3aa5dc8d..f5cf4483b 100644 --- a/kbx/keybox-update.c +++ b/kbx/keybox-update.c @@ -26,9 +26,7 @@ #include #include "keybox-defs.h" -#ifdef HAVE_DOSISH_SYSTEM #include "../common/sysutils.h" -#endif #define EXTSEP_S "." diff --git a/tools/ChangeLog b/tools/ChangeLog index b3e846a53..76b42763a 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,3 +1,8 @@ +2010-04-20 Marcus Brinkmann + + * gpgconf-comp.c (option_check_validity): Use dummy variables to + silence gcc warning. + 2010-04-14 Werner Koch * Makefile.am (bin_PROGRAMS) [W32CE]: Exclude gpgkey2ssh. diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index 4fe84cf27..8f9278d28 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -2241,8 +2241,11 @@ option_check_validity (gc_option_t *option, unsigned long flags, } else if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_INT32) { + long res; + gpg_err_set_errno (0); - (void) strtol (arg, &arg, 0); + res = strtol (arg, &arg, 0); + (void) res; if (errno) gc_error (1, errno, "invalid argument for option %s", @@ -2254,8 +2257,11 @@ option_check_validity (gc_option_t *option, unsigned long flags, } else if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_INT32) { + unsigned long res; + gpg_err_set_errno (0); - (void) strtoul (arg, &arg, 0); + res = strtoul (arg, &arg, 0); + (void) res; if (errno) gc_error (1, errno, "invalid argument for option %s",