diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/ChangeLog | 12 | ||||
-rw-r--r-- | common/logging.c | 24 | ||||
-rw-r--r-- | common/pka.c | 20 | ||||
-rw-r--r-- | common/signal.c | 16 | ||||
-rw-r--r-- | common/sysutils.c | 6 | ||||
-rw-r--r-- | common/t-exechelp.c | 11 |
6 files changed, 58 insertions, 31 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 <marcus@g10code.de> + + * 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 <wk@g10code.com> * 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); |