From ea9655907d37782a2a505caee22f2458058784ee Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 30 Dec 2007 11:43:48 -0500 Subject: [PATCH] "Soften" the format assertions so that they no longer abort(). --- src/image.c | 4 ++-- src/misc.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/image.c b/src/image.c index 336cd98..81f66e0 100644 --- a/src/image.c +++ b/src/image.c @@ -51,8 +51,8 @@ struct lbx_image *lbximg_fopen(FILE *f) * If we never find any exceptions, we can replace the assertions with * assumptions. */ - assert(tmp.wtf1 == 0); - assert(tmp.offs == tmp.frames + 1); + _lbx_assert(tmp.wtf1 == 0); + _lbx_assert(tmp.offs == tmp.frames + 1); new = malloc(sizeof *new + tmp.offs * sizeof *new->offsets); if (!new) { diff --git a/src/misc.h b/src/misc.h index d7a7605..5e5947a 100644 --- a/src/misc.h +++ b/src/misc.h @@ -1,11 +1,26 @@ #ifndef LBX_MISC_H_ #define LBX_MISC_H_ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) +#ifndef NDEBUG +# define _lbx_dbgprint(str) (fprintf(stderr, str " [%s, %s:%d]", \ + __func__, __FILE__, __LINE__)) +# define _lbx_assert(expr) ((!(expr)) \ + ? (_lbx_dbgprint("format assertion failed: " #expr), 0) \ + : 1) +#else +# define _lbx_dbgprint(str) 0 +# define _lbx_assert(expr) ((expr) ? 1 : 0) +#endif + /** _lbx_fseek() * Seeks the specified file to the specified offset, given that the file is * currently positioned at *current. If the file does not support seeking, -- 2.43.2