summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2008-08-20 17:59:42 +0000
committerWerner Koch <wk@gnupg.org>2008-08-20 17:59:42 +0000
commit2f818ed3f919a9f8f565b67007b194fa953e7d9b (patch)
tree72827351385a8fb1e13998f9df6864287bec2dcf
parentee4d4642216dd04c84a360a5dd59c090e095114c (diff)
downloadlibgcrypt-2f818ed3f919a9f8f565b67007b194fa953e7d9b.tar.gz
Replace assert calls by a new gcry_assert at most places.
-rw-r--r--cipher/ac.c9
-rw-r--r--cipher/dsa.c3
-rw-r--r--cipher/ecc.c1
-rw-r--r--cipher/md.c7
-rw-r--r--cipher/primegen.c5
-rw-r--r--cipher/pubkey.c23
-rw-r--r--cipher/rijndael.c5
-rw-r--r--cipher/whirlpool.c3
-rw-r--r--mpi/ec.c1
-rw-r--r--mpi/mpi-bit.c1
-rw-r--r--mpi/mpi-mod.c1
-rw-r--r--mpi/mpi-mpow.c12
-rw-r--r--mpi/mpi-pow.c6
-rw-r--r--mpi/mpicoder.c7
-rw-r--r--mpi/mpiutil.c3
-rw-r--r--random/random-csprng.c19
-rw-r--r--random/random.c1
-rw-r--r--random/rndhw.c1
-rw-r--r--random/rndw32.c5
-rw-r--r--src/ChangeLog7
-rw-r--r--src/ath.c2
-rw-r--r--src/fips.c9
-rw-r--r--src/g10lib.h30
-rw-r--r--src/global.c1
-rw-r--r--src/misc.c20
25 files changed, 99 insertions, 83 deletions
diff --git a/cipher/ac.c b/cipher/ac.c
index 04a3b282..ee9498b2 100644
--- a/cipher/ac.c
+++ b/cipher/ac.c
@@ -24,7 +24,6 @@
#include <string.h>
#include <stdio.h>
#include <stddef.h>
-#include <assert.h>
#include "g10lib.h"
#include "cipher.h"
@@ -886,8 +885,8 @@ _gcry_ac_io_init_va (gcry_ac_io_t *ac_io,
if (fips_mode ())
return;
- assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE));
- assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING));
+ gcry_assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE));
+ gcry_assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING));
ac_io->mode = mode;
ac_io->type = type;
@@ -947,7 +946,7 @@ _gcry_ac_io_write (gcry_ac_io_t *ac_io, unsigned char *buffer, size_t buffer_n)
{
gcry_error_t err;
- assert (ac_io->mode == GCRY_AC_IO_WRITABLE);
+ gcry_assert (ac_io->mode == GCRY_AC_IO_WRITABLE);
err = 0;
switch (ac_io->type)
@@ -1007,7 +1006,7 @@ _gcry_ac_io_read (gcry_ac_io_t *ac_io,
{
gcry_error_t err;
- assert (ac_io->mode == GCRY_AC_IO_READABLE);
+ gcry_assert (ac_io->mode == GCRY_AC_IO_READABLE);
err = 0;
switch (ac_io->type)
diff --git a/cipher/dsa.c b/cipher/dsa.c
index ccfd6860..daafdde3 100644
--- a/cipher/dsa.c
+++ b/cipher/dsa.c
@@ -23,7 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include "g10lib.h"
#include "mpi.h"
@@ -237,7 +236,7 @@ generate (DSA_secret_key *sk, unsigned int nbits, unsigned int qbits,
* is the secret part. */
if( DBG_CIPHER )
log_debug("choosing a random x ");
- assert( qbits >= 160 );
+ gcry_assert( qbits >= 160 );
x = mpi_alloc_secure( mpi_get_nlimbs(q) );
mpi_sub_ui( h, q, 1 ); /* put q-1 into h */
rndbuf = NULL;
diff --git a/cipher/ecc.c b/cipher/ecc.c
index d1da75ac..c75fd4ef 100644
--- a/cipher/ecc.c
+++ b/cipher/ecc.c
@@ -54,7 +54,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include "g10lib.h"
#include "mpi.h"
diff --git a/cipher/md.c b/cipher/md.c
index 2cc25b77..7ca4a214 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -23,7 +23,6 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <assert.h>
#include "g10lib.h"
#include "cipher.h"
@@ -627,10 +626,10 @@ md_copy (gcry_md_hd_t ahd, gcry_md_hd_t *b_hd)
{
bhd->ctx = b = (struct gcry_md_context *) ((char *) bhd + n);
/* No need to copy the buffer due to the write above. */
- assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1));
+ gcry_assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1));
bhd->bufsize = ahd->bufsize;
bhd->bufpos = 0;
- assert (! ahd->bufpos);
+ gcry_assert (! ahd->bufpos);
memcpy (b, a, sizeof *a);
b->list = NULL;
b->debug = NULL;
@@ -843,7 +842,7 @@ prepare_macpads( gcry_md_hd_t hd, const byte *key, size_t keylen)
gcry_md_hash_buffer ( algo, helpkey, key, keylen );
key = helpkey;
keylen = md_digest_length( algo );
- assert ( keylen <= 64 );
+ gcry_assert ( keylen <= 64 );
}
memset ( hd->ctx->macpads, 0, 2*(hd->ctx->macpads_Bsize) );
diff --git a/cipher/primegen.c b/cipher/primegen.c
index 11da16a0..ef2d11d7 100644
--- a/cipher/primegen.c
+++ b/cipher/primegen.c
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include <errno.h>
#include "g10lib.h"
@@ -208,7 +207,7 @@ get_pool_prime (unsigned int nbits, gcry_random_level_t randomlevel)
{
gcry_mpi_t prime = item->prime;
item->prime = NULL;
- assert (nbits == mpi_get_nbits (prime));
+ gcry_assert (nbits == mpi_get_nbits (prime));
return prime;
}
return NULL;
@@ -950,7 +949,7 @@ is_prime (gcry_mpi_t n, int steps, unsigned int *count)
mpi_set_highbit( x, nbits-2 );
mpi_clear_bit( x, nbits-2 );
}
- assert ( mpi_cmp( x, nminus1 ) < 0 && mpi_cmp_ui( x, 1 ) > 0 );
+ gcry_assert (mpi_cmp (x, nminus1) < 0 && mpi_cmp_ui (x, 1) > 0);
}
gcry_mpi_powm ( y, x, q, n);
if ( mpi_cmp_ui(y, 1) && mpi_cmp( y, nminus1 ) )
diff --git a/cipher/pubkey.c b/cipher/pubkey.c
index ad5f89b7..cf8a17c8 100644
--- a/cipher/pubkey.c
+++ b/cipher/pubkey.c
@@ -23,7 +23,6 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <assert.h>
#include "g10lib.h"
#include "mpi.h"
@@ -860,7 +859,7 @@ sexp_elements_extract_ecc (gcry_sexp_t key_sexp, const char *element_names,
/* Clear the array for easir error cleanup. */
for (name = element_names, idx = 0; *name; name++, idx++)
elements[idx] = NULL;
- assert (idx >= 6); /* We know that ECC has at least 6 elements. */
+ gcry_assert (idx >= 6); /* We know that ECC has at least 6 elements. */
/* Init the array with the available curve parameters. */
for (name = element_names, idx = 0; *name && !err; name++, idx++)
@@ -1391,7 +1390,7 @@ sexp_data_to_mpi (gcry_sexp_t input, unsigned int nbits, gcry_mpi_t *ret_mpi,
frame[n++] = 0;
frame[n++] = 2; /* block type */
i = nframe - 3 - valuelen;
- assert (i > 0);
+ gcry_assert (i > 0);
p = gcry_random_bytes_secure (i, GCRY_STRONG_RANDOM);
/* Replace zero bytes by new values. */
for (;;)
@@ -1426,7 +1425,7 @@ sexp_data_to_mpi (gcry_sexp_t input, unsigned int nbits, gcry_mpi_t *ret_mpi,
frame[n++] = 0;
memcpy (frame+n, value, valuelen);
n += valuelen;
- assert (n == nframe);
+ gcry_assert (n == nframe);
/* FIXME, error checking? */
gcry_mpi_scan (ret_mpi, GCRYMPI_FMT_USG, frame, n, &nframe);
@@ -1527,7 +1526,7 @@ sexp_data_to_mpi (gcry_sexp_t input, unsigned int nbits, gcry_mpi_t *ret_mpi,
frame[n++] = 0;
frame[n++] = 1; /* block type */
i = nframe - valuelen - asnlen - 3 ;
- assert (i > 1);
+ gcry_assert (i > 1);
memset (frame+n, 0xff, i );
n += i;
frame[n++] = 0;
@@ -1535,7 +1534,7 @@ sexp_data_to_mpi (gcry_sexp_t input, unsigned int nbits, gcry_mpi_t *ret_mpi,
n += asnlen;
memcpy (frame+n, value, valuelen );
n += valuelen;
- assert (n == nframe);
+ gcry_assert (n == nframe);
/* Convert it into an MPI. FIXME: error checking? */
gcry_mpi_scan (ret_mpi, GCRYMPI_FMT_USG, frame, n, &nframe);
@@ -1599,7 +1598,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey)
if (rc)
goto leave;
- assert (module);
+ gcry_assert (module);
pubkey = (gcry_pk_spec_t *) module->spec;
/* If aliases for the algorithm name exists, take the first one
@@ -1838,7 +1837,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey)
if (rc)
goto leave;
- assert (module);
+ gcry_assert (module);
pubkey = (gcry_pk_spec_t *) module->spec;
algo_name = pubkey->aliases? *pubkey->aliases : NULL;
if (!algo_name || !*algo_name)
@@ -2291,7 +2290,7 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
p = stpcpy (p, "))");
}
strcpy (p, ")");
- assert (p - string < needed);
+ gcry_assert (p - string < needed);
while (nelem < DIM (mpis))
mpis[nelem++] = NULL;
@@ -2315,9 +2314,9 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
free (arg_list);
if (rc)
BUG ();
- assert (DIM (mpis) == 30); /* Reminder to make sure that the
- array gets increased if new
- parameters are added. */
+ gcry_assert (DIM (mpis) == 30); /* Reminder to make sure that
+ the array gets increased if
+ new parameters are added. */
}
gcry_free (string);
}
diff --git a/cipher/rijndael.c b/cipher/rijndael.c
index b54e069d..18158cb0 100644
--- a/cipher/rijndael.c
+++ b/cipher/rijndael.c
@@ -41,7 +41,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* for memcmp() */
-#include <assert.h>
#include "types.h" /* for byte and u32 typedefs */
#include "g10lib.h"
@@ -995,8 +994,8 @@ selftest_fips_128_38a (int requested_mode)
return a; \
} while (0)
- assert (sizeof tv[0].data[0].input == sizeof scratch);
- assert (sizeof tv[0].data[0].output == sizeof scratch);
+ gcry_assert (sizeof tv[0].data[0].input == sizeof scratch);
+ gcry_assert (sizeof tv[0].data[0].output == sizeof scratch);
for (tvi=0; tvi < DIM (tv); tvi++)
if (tv[tvi].mode == requested_mode)
diff --git a/cipher/whirlpool.c b/cipher/whirlpool.c
index 91bac244..9b029ee3 100644
--- a/cipher/whirlpool.c
+++ b/cipher/whirlpool.c
@@ -33,7 +33,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include "types.h"
#include "g10lib.h"
@@ -1350,7 +1349,7 @@ whirlpool_add (whirlpool_context_t *context,
buffer_size >>= 8;
carry >>= 8;
}
- assert (! (buffer_size || carry));
+ gcry_assert (! (buffer_size || carry));
}
static void
diff --git a/mpi/ec.c b/mpi/ec.c
index b76dd520..4a3a5f8c 100644
--- a/mpi/ec.c
+++ b/mpi/ec.c
@@ -22,7 +22,6 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include "mpi-internal.h"
#include "longlong.h"
diff --git a/mpi/mpi-bit.c b/mpi/mpi-bit.c
index 326e9522..32c820c2 100644
--- a/mpi/mpi-bit.c
+++ b/mpi/mpi-bit.c
@@ -21,7 +21,6 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include "mpi-internal.h"
#include "longlong.h"
diff --git a/mpi/mpi-mod.c b/mpi/mpi-mod.c
index 9f38a0a9..948bf231 100644
--- a/mpi/mpi-mod.c
+++ b/mpi/mpi-mod.c
@@ -23,7 +23,6 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include "mpi-internal.h"
#include "longlong.h"
diff --git a/mpi/mpi-mpow.c b/mpi/mpi-mpow.c
index f37c6f9e..131c5b67 100644
--- a/mpi/mpi-mpow.c
+++ b/mpi/mpi-mpow.c
@@ -21,10 +21,10 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
+
#include "mpi-internal.h"
#include "longlong.h"
#include "g10lib.h"
-#include <assert.h>
/* Barrett is slower than the classical way. It can be tweaked by
@@ -77,7 +77,7 @@ _gcry_mpi_mulpowm( gcry_mpi_t res, gcry_mpi_t *basearray, gcry_mpi_t *exparray,
for(k=0; basearray[k]; k++ )
;
- assert(k);
+ gcry_assert(k);
for(t=0, i=0; (tmp=exparray[i]); i++ ) {
/*log_mpidump("exp: ", tmp );*/
j = mpi_get_nbits(tmp);
@@ -85,9 +85,9 @@ _gcry_mpi_mulpowm( gcry_mpi_t res, gcry_mpi_t *basearray, gcry_mpi_t *exparray,
t = j;
}
/*log_mpidump("mod: ", m );*/
- assert(i==k);
- assert(t);
- assert( k < 10 );
+ gcry_assert (i==k);
+ gcry_assert (t);
+ gcry_assert (k < 10);
G = gcry_xcalloc( (1<<k) , sizeof *G );
#ifdef USE_BARRETT
@@ -100,7 +100,7 @@ _gcry_mpi_mulpowm( gcry_mpi_t res, gcry_mpi_t *basearray, gcry_mpi_t *exparray,
barrett_mulm(tmp, res, res, m, barrett_y, barrett_k,
barrett_r1, barrett_r2 );
idx = build_index( exparray, k, i, t );
- assert( idx >= 0 && idx < (1<<k) );
+ gcry_assert (idx >= 0 && idx < (1<<k));
if( !G[idx] ) {
if( !idx )
G[0] = mpi_alloc_set_ui( 1 );
diff --git a/mpi/mpi-pow.c b/mpi/mpi-pow.c
index 4f3d73e4..975e4aa3 100644
--- a/mpi/mpi-pow.c
+++ b/mpi/mpi-pow.c
@@ -28,9 +28,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
#include "mpi-internal.h"
#include "longlong.h"
-#include <assert.h>
/****************
@@ -133,7 +133,7 @@ gcry_mpi_powm( gcry_mpi_t res, gcry_mpi_t base, gcry_mpi_t expo, gcry_mpi_t mod)
else { /* Make BASE, EXPO and MOD not overlap with RES. */
if( rp == bp ) {
/* RES and BASE are identical. Allocate temp. space for BASE. */
- assert( !bp_marker );
+ gcry_assert (!bp_marker);
bp_nlimbs = bsec? bsize:0;
bp = bp_marker = mpi_alloc_limb_space( bsize, bsec );
MPN_COPY(bp, rp, bsize);
@@ -146,7 +146,7 @@ gcry_mpi_powm( gcry_mpi_t res, gcry_mpi_t base, gcry_mpi_t expo, gcry_mpi_t mod)
}
if( rp == mp ) {
/* RES and MOD are identical. Allocate temporary space for MOD.*/
- assert( !mp_marker );
+ gcry_assert (!mp_marker);
mp_nlimbs = msec?msize:0;
mp = mp_marker = mpi_alloc_limb_space( msize, msec );
MPN_COPY(mp, rp, msize);
diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c
index a0ae8f89..0c19941b 100644
--- a/mpi/mpicoder.c
+++ b/mpi/mpicoder.c
@@ -23,7 +23,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <assert.h>
#include "mpi-internal.h"
#include "g10lib.h"
@@ -123,9 +122,9 @@ mpi_fromstr(gcry_mpi_t val, const char *str)
}
else
c1 = *str++;
- assert(c1);
+ gcry_assert (c1);
c2 = *str++;
- assert(c2);
+ gcry_assert (c2);
if( c1 >= '0' && c1 <= '9' )
c = c1 - '0';
else if( c1 >= 'a' && c1 <= 'f' )
@@ -328,7 +327,7 @@ _gcry_mpi_set_buffer ( gcry_mpi_t a, const void *buffer_arg,
a->d[i++] = alimb;
}
a->nlimbs = i;
- assert( i == nlimbs );
+ gcry_assert (i == nlimbs);
}
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index bafc5de1..4dc52113 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include "g10lib.h"
#include "mpi-internal.h"
@@ -196,7 +195,7 @@ mpi_set_secure( gcry_mpi_t a )
ap = a->d;
if (!a->nlimbs)
{
- assert(!ap);
+ gcry_assert (!ap);
return;
}
bp = mpi_alloc_limb_space (a->nlimbs, 1);
diff --git a/random/random-csprng.c b/random/random-csprng.c
index ef168056..eda34f76 100644
--- a/random/random-csprng.c
+++ b/random/random-csprng.c
@@ -29,7 +29,6 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
@@ -278,9 +277,9 @@ initialize_basics(void)
/* Make sure that we are still using the values we have
traditionally used for the random levels. */
- assert ( GCRY_WEAK_RANDOM == 0
- && GCRY_STRONG_RANDOM == 1
- && GCRY_VERY_STRONG_RANDOM == 2);
+ gcry_assert (GCRY_WEAK_RANDOM == 0
+ && GCRY_STRONG_RANDOM == 1
+ && GCRY_VERY_STRONG_RANDOM == 2);
}
}
@@ -603,7 +602,7 @@ mix_pool(unsigned char *pool)
#error must have a digest length of 20 for ripe-md-160
#endif
- assert (pool_is_locked);
+ gcry_assert (pool_is_locked);
_gcry_rmd160_init( &md );
/* Loop over the pool. */
@@ -728,7 +727,7 @@ read_seed_file (void)
unsigned char buffer[POOLSIZE];
int n;
- assert (pool_is_locked);
+ gcry_assert (pool_is_locked);
if (!seed_file_name)
return 0;
@@ -919,7 +918,7 @@ read_pool (byte *buffer, size_t length, int level)
static volatile pid_t my_pid = (pid_t)(-1);
volatile pid_t my_pid2;
- assert (pool_is_locked);
+ gcry_assert (pool_is_locked);
retry:
/* Get our own pid, so that we can detect a fork. */
@@ -938,7 +937,7 @@ read_pool (byte *buffer, size_t length, int level)
just_mixed = 0; /* Make sure it will get mixed. */
}
- assert (pool_is_locked);
+ gcry_assert (pool_is_locked);
/* Our code does not allow to extract more than POOLSIZE. Better
check it here. */
@@ -1059,7 +1058,7 @@ add_randomness (const void *buffer, size_t length, enum random_origins origin)
const unsigned char *p = buffer;
size_t count = 0;
- assert (pool_is_locked);
+ gcry_assert (pool_is_locked);
rndstats.addbytes += length;
rndstats.naddbytes++;
@@ -1157,7 +1156,7 @@ getfnc_fast_random_poll (void))( void (*)(const void*, size_t,
static void
do_fast_random_poll (void)
{
- assert (pool_is_locked);
+ gcry_assert (pool_is_locked);
rndstats.fastpolls++;
diff --git a/random/random.c b/random/random.c
index 020c6518..4402f44a 100644
--- a/random/random.c
+++ b/random/random.c
@@ -25,7 +25,6 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include <errno.h>
#include "g10lib.h"
diff --git a/random/rndhw.c b/random/rndhw.c
index 577bd155..2c78b47c 100644
--- a/random/rndhw.c
+++ b/random/rndhw.c
@@ -20,7 +20,6 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include "types.h"
#include "g10lib.h"
diff --git a/random/rndw32.c b/random/rndw32.c
index 74007e31..1952979d 100644
--- a/random/rndw32.c
+++ b/random/rndw32.c
@@ -71,7 +71,6 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include <errno.h>
#include <string.h>
#ifdef __GNUC__
@@ -735,7 +734,7 @@ slow_gatherer ( void (*add)(const void*, size_t, enum random_origins),
(*add) (buffer, powerInfo[i].size, requester);
no_results++;
}
- assert (i < 100);
+ gcry_assert (i < 100);
}
gcry_free (buffer);
@@ -833,7 +832,7 @@ _gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t,
ADD ( GetQueueStatus (QS_ALLEVENTS));
ADD ( GetTickCount ());
- assert ( bufptr-buffer < sizeof (buffer) );
+ gcry_assert ( bufptr-buffer < sizeof (buffer) );
(*add) ( buffer, bufptr-buffer, origin );
#undef ADD
}
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.
diff --git a/src/ath.c b/src/ath.c
index edfaada6..0c274cde 100644
--- a/src/ath.c
+++ b/src/ath.c
@@ -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>
diff --git a/src/fips.c b/src/fips.c
index 0083177e..c02f064a 100644
--- a/src/fips.c
+++ b/src/fips.c
@@ -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"
diff --git a/src/misc.c b/src/misc.c
index 71c60037..cbb59e1d 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -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