diff options
author | Werner Koch <wk@gnupg.org> | 2008-08-20 17:59:42 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2008-08-20 17:59:42 +0000 |
commit | 2f818ed3f919a9f8f565b67007b194fa953e7d9b (patch) | |
tree | 72827351385a8fb1e13998f9df6864287bec2dcf /src | |
parent | ee4d4642216dd04c84a360a5dd59c090e095114c (diff) | |
download | libgcrypt-2f818ed3f919a9f8f565b67007b194fa953e7d9b.tar.gz |
Replace assert calls by a new gcry_assert at most places.
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 7 | ||||
-rw-r--r-- | src/ath.c | 2 | ||||
-rw-r--r-- | src/fips.c | 9 | ||||
-rw-r--r-- | src/g10lib.h | 30 | ||||
-rw-r--r-- | src/global.c | 1 | ||||
-rw-r--r-- | src/misc.c | 20 |
6 files changed, 51 insertions, 18 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index f7cdcca1..85076b10 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2008-08-20 Werner Koch <wk@g10code.com> + + * g10lib.h (gcry_assert): New. use this at almost all places + where we used a plain assert. + * misc.c (_gcry_assert_failed): New. + (_gcry_bug): Also use func variant for ISO-C99. + 2008-08-19 Werner Koch <wk@g10code.com> * visibility.c, visibility.h (gcry_mpi_lshift): New. @@ -22,7 +22,7 @@ #include <config.h> #endif -#include <assert.h> +#include <assert.h> /* Right: We need to use assert and not gcry_assert. */ #include <unistd.h> #ifdef HAVE_SYS_SELECT_H # include <sys/select.h> @@ -20,7 +20,6 @@ #include <config.h> #include <stdio.h> #include <stdlib.h> -#include <assert.h> #include <errno.h> #include <unistd.h> @@ -85,14 +84,14 @@ _gcry_initialize_fips_mode (int force) fips_noreturn (); } /* If not in fips mode an assert is sufficient. */ - assert (!done); + gcry_assert (!done); } done = 1; /* If the calling applicatione explicitly requested fipsmode, do so. */ if (force) { - assert (!no_fips_mode_required); + gcry_assert (!no_fips_mode_required); goto leave; } @@ -106,7 +105,7 @@ _gcry_initialize_fips_mode (int force) allowed. */ if ( !access ("/etc/gcrypt/fips140.force", F_OK) ) { - assert (!no_fips_mode_required); + gcry_assert (!no_fips_mode_required); goto leave; } @@ -124,7 +123,7 @@ _gcry_initialize_fips_mode (int force) { /* System is in fips mode. */ fclose (fp); - assert (!no_fips_mode_required); + gcry_assert (!no_fips_mode_required); goto leave; } fclose (fp); diff --git a/src/g10lib.h b/src/g10lib.h index 701656f5..ed25a514 100644 --- a/src/g10lib.h +++ b/src/g10lib.h @@ -63,6 +63,14 @@ #define _(a) _gcry_gettext(a) #define N_(a) (a) +/* Some handy macros */ +#ifndef STR +#define STR(v) #v +#endif +#define STR2(v) STR(v) +#define DIM(v) (sizeof(v)/sizeof((v)[0])) +#define DIMof(type,member) DIM(((type *)0)->member) + /*-- src/global.c -*/ @@ -73,11 +81,14 @@ int _gcry_get_debug_flag (unsigned int mask); /*-- src/misc.c --*/ -#ifdef JNLIB_GCC_M_FUNCTION +#if defined(JNLIB_GCC_M_FUNCTION) || __STDC_VERSION__ >= 199901L void _gcry_bug (const char *file, int line, const char *func) GCC_ATTR_NORETURN; +void _gcry_assert_failed (const char *expr, const char *file, int line, + const char *func) GCC_ATTR_NORETURN; #else void _gcry_bug (const char *file, int line); +void _gcry_assert_failed (const char *expr, const char *file, int line); #endif const char *_gcry_gettext (const char *key); @@ -97,10 +108,19 @@ int _gcry_log_verbosity( int level ); #ifdef JNLIB_GCC_M_FUNCTION #define BUG() _gcry_bug( __FILE__ , __LINE__, __FUNCTION__ ) +#define gcry_assert(expr) ((expr)? (void)0 \ + : _gcry_assert_failed (STR(expr), __FILE__, __LINE__, __FUNCTION__)) +#elif __STDC_VERSION__ >= 199901L +#define BUG() _gcry_bug( __FILE__ , __LINE__, __func__ ) +#define gcry_assert(expr) ((expr)? (void)0 \ + : _gcry_assert_failed (STR(expr), __FILE__, __LINE__, __func__)) #else #define BUG() _gcry_bug( __FILE__ , __LINE__ ) +#define gcry_assert(expr) ((expr)? (void)0 \ + : _gcry_assert_failed (STR(expr), __FILE__, __LINE__)) #endif + #define log_hexdump _gcry_log_hexdump #define log_bug _gcry_log_bug #define log_fatal _gcry_log_fatal @@ -169,14 +189,6 @@ int strcasecmp (const char *a, const char *b) _GCRY_GCC_ATTR_PURE; #endif -/* some handy macros */ -#ifndef STR -#define STR(v) #v -#endif -#define STR2(v) STR(v) -#define DIM(v) (sizeof(v)/sizeof((v)[0])) -#define DIMof(type,member) DIM(((type *)0)->member) - /* Stack burning. */ void _gcry_burn_stack (int bytes); diff --git a/src/global.c b/src/global.c index de562b38..ed4e4807 100644 --- a/src/global.c +++ b/src/global.c @@ -28,7 +28,6 @@ #include <limits.h> #include <errno.h> #include <unistd.h> -#include <assert.h> #include "g10lib.h" #include "cipher.h" @@ -1,5 +1,6 @@ /* misc.c - * Copyright (C) 1999, 2001, 2002, 2003, 2007 Free Software Foundation, Inc. + * Copyright (C) 1999, 2001, 2002, 2003, 2007, + * 2008 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * @@ -151,7 +152,7 @@ _gcry_log( int level, const char *fmt, ... ) } -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) +#if defined(JNLIB_GCC_M_FUNCTION) || __STDC_VERSION__ >= 199901L void _gcry_bug( const char *file, int line, const char *func ) { @@ -159,6 +160,14 @@ _gcry_bug( const char *file, int line, const char *func ) ("... this is a bug (%s:%d:%s)\n"), file, line, func ); abort(); /* never called, but it makes the compiler happy */ } +void +_gcry_assert_failed (const char *expr, const char *file, int line, + const char *func) +{ + _gcry_log (GCRY_LOG_BUG, + ("Assertion `%s' failed (%s:%d:%s)\n"), expr, file, line, func ); + abort(); /* Never called, but it makes the compiler happy. */ +} #else void _gcry_bug( const char *file, int line ) @@ -167,6 +176,13 @@ _gcry_bug( const char *file, int line ) _("you found a bug ... (%s:%d)\n"), file, line); abort(); /* never called, but it makes the compiler happy */ } +void +_gcry_assert_failed (const char *expr, const char *file, int line) +{ + _gcry_log (GCRY_LOG_BUG, + ("Assertion `%s' failed (%s:%d)\n"), expr, file, line); + abort(); /* Never called, but it makes the compiler happy. */ +} #endif void |