Make CANT_HAPPEN() more obvious for static analysis

Local analysis can now easily find out what's up.  Before,
whole-program analysis was required.  The Clang Static Analyzer
complained about code that is actually fine.
This commit is contained in:
Markus Armbruster 2010-01-15 20:02:11 +01:00
parent ad80846283
commit 9061ae7b9d
2 changed files with 5 additions and 8 deletions

View file

@ -70,15 +70,15 @@
* Return EXPR != 0. * Return EXPR != 0.
* Usage: if (CANT_HAPPEN(...)) <recovery code>; * Usage: if (CANT_HAPPEN(...)) <recovery code>;
*/ */
#define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0) #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__), 1 : 0)
/* /*
* Report internal error. * Report internal error.
* Usage: CANT_REACH(); <recovery code>; * Usage: CANT_REACH(); <recovery code>;
*/ */
#define CANT_REACH() (void)oops(NULL, __FILE__, __LINE__) #define CANT_REACH() oops(NULL, __FILE__, __LINE__)
extern int oops(char *, char *, int); extern void oops(char *, char *, int);
extern void (*oops_handler)(void); extern void (*oops_handler)(void);
void exit_nomem(void) ATTRIBUTE((noreturn)); void exit_nomem(void) ATTRIBUTE((noreturn));

View file

@ -126,16 +126,13 @@ logerror(char *format, ...)
} }
/* /*
* Log internal error MSG occured in FILE:LINE. * Log internal error MSG occured in FILE:LINE, call oops handler.
* Call oops handler, and if it returns, return 1.
* Oops handler defaults to abort().
*/ */
int void
oops(char *msg, char *file, int line) oops(char *msg, char *file, int line)
{ {
logerror("Oops: %s in %s:%d", msg ? msg : "bug", file, line); logerror("Oops: %s in %s:%d", msg ? msg : "bug", file, line);
oops_handler(); oops_handler();
return 1;
} }
/* /*