]> git.draconx.ca Git - liblbx.git/commitdiff
"Soften" the format assertions so that they no longer abort().
authorNick Bowler <draconx@gmail.com>
Sun, 30 Dec 2007 16:43:48 +0000 (11:43 -0500)
committerNick Bowler <draconx@gmail.com>
Mon, 31 Dec 2007 01:42:48 +0000 (20:42 -0500)
src/image.c
src/misc.h

index 336cd98ebd4951cfb049d24c10db6f3eeaf55864..81f66e015e6e05e602dfca397d78901f7355d959 100644 (file)
@@ -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) {
index d7a760599b4bcf3179af2eb6e4b13a43ddced731..5e5947a3597df05bbee747271fae9d0255483454 100644 (file)
@@ -1,11 +1,26 @@
 #ifndef LBX_MISC_H_
 #define LBX_MISC_H_
 
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
 #include <stdio.h>
 
 #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,