Rizin
unix-like reverse engineering framework and cli tools
rz_assert.h File Reference
#include "rz_log.h"

Go to the source code of this file.

Macros

#define RZ_STATIC_ASSERT(x)
 
#define RZ_FUNCTION   ((const char *)("???"))
 
#define rz_warn_if_reached()
 
#define rz_warn_if_fail(expr)
 
#define RZ_CHECKS_LEVEL   2
 
#define H_LOG_(loglevel, fmt, ...)   rz_assert_log(loglevel, fmt, __VA_ARGS__)
 
#define rz_return_if_fail(expr)
 
#define rz_return_val_if_fail(expr, val)
 
#define rz_return_if_reached()
 
#define rz_return_val_if_reached(val)
 
#define rz_goto_if_reached(where)
 

Functions

RZ_API void rz_assert_log (RzLogLevel level, const char *fmt,...) RZ_PRINTF_CHECK(2
 

Macro Definition Documentation

◆ H_LOG_

#define H_LOG_ (   loglevel,
  fmt,
  ... 
)    rz_assert_log(loglevel, fmt, __VA_ARGS__)

Definition at line 79 of file rz_assert.h.

◆ RZ_CHECKS_LEVEL

#define RZ_CHECKS_LEVEL   2

Definition at line 52 of file rz_assert.h.

◆ RZ_FUNCTION

#define RZ_FUNCTION   ((const char *)("???"))

Definition at line 26 of file rz_assert.h.

◆ rz_goto_if_reached

#define rz_goto_if_reached (   where)
Value:
do { \
H_LOG_(RZ_LOGLVL_ERROR, "file %s: line %d (%s): should not be reached; jumping to %s\n", __FILE__, __LINE__, RZ_FUNCTION, #where); \
goto where; \
} while (0)
#define RZ_FUNCTION
Definition: rz_assert.h:26
@ RZ_LOGLVL_ERROR
Definition: rz_log.h:22

Definition at line 128 of file rz_assert.h.

◆ rz_return_if_fail

#define rz_return_if_fail (   expr)
Value:
do { \
if (!(expr)) { \
H_LOG_(RZ_LOGLVL_WARN, "%s: assertion '%s' failed (line %d)\n", RZ_FUNCTION, #expr, __LINE__); \
return; \
} \
} while (0)
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
Definition: calc.c:167
@ RZ_LOGLVL_WARN
Definition: rz_log.h:21

rz_return_if_fail: @expr: the expression to check

Verifies that the expression @expr, usually representing a precondition, evaluates to true. If the function returns a value, use rz_return_val_if_fail() instead.

If @expr evaluates to FALSE, the current function should be considered to have undefined behaviour (a programmer error). The only correct solution to such an error is to change the module that is calling the current function, so that it avoids this incorrect call.

To make this undefined behaviour visible, if @expr evaluates to FALSE, the result is usually that a critical message is logged and the current function returns.

Definition at line 100 of file rz_assert.h.

◆ rz_return_if_reached

#define rz_return_if_reached ( )
Value:
do { \
H_LOG_(RZ_LOGLVL_ERROR, "file %s: line %d (%s): should not be reached\n", __FILE__, __LINE__, RZ_FUNCTION); \
return; \
} while (0)

Definition at line 116 of file rz_assert.h.

◆ rz_return_val_if_fail

#define rz_return_val_if_fail (   expr,
  val 
)
Value:
do { \
if (!(expr)) { \
H_LOG_(RZ_LOGLVL_WARN, "%s: assertion '%s' failed (line %d)\n", RZ_FUNCTION, #expr, __LINE__); \
return (val); \
} \
} while (0)
ut16 val
Definition: armass64_const.h:6

Definition at line 108 of file rz_assert.h.

◆ rz_return_val_if_reached

#define rz_return_val_if_reached (   val)
Value:
do { \
H_LOG_(RZ_LOGLVL_ERROR, "file %s: line %d (%s): should not be reached\n", __FILE__, __LINE__, RZ_FUNCTION); \
return (val); \
} while (0)

Definition at line 122 of file rz_assert.h.

◆ RZ_STATIC_ASSERT

#define RZ_STATIC_ASSERT (   x)
Value:
switch (0) { \
case 0: \
case (x):; \
}
int x
Definition: mipsasm.c:20

Definition at line 10 of file rz_assert.h.

◆ rz_warn_if_fail

#define rz_warn_if_fail (   expr)
Value:
do { \
if (!(expr)) { \
rz_assert_log(RZ_LOGLVL_WARN, "(%s:%d):%s%s runtime check failed: (%s)\n", \
__FILE__, __LINE__, RZ_FUNCTION, RZ_FUNCTION[0] ? ":" : "", #expr); \
} \
} while (0)

Definition at line 35 of file rz_assert.h.

◆ rz_warn_if_reached

#define rz_warn_if_reached ( )
Value:
do { \
rz_assert_log(RZ_LOGLVL_WARN, "(%s:%d):%s%s code should not be reached\n", \
__FILE__, __LINE__, RZ_FUNCTION, RZ_FUNCTION[0] ? ":" : ""); \
} while (0)

Definition at line 29 of file rz_assert.h.

Function Documentation

◆ rz_assert_log()

RZ_API void rz_assert_log ( RzLogLevel  level,
const char *  fmt,
  ... 
)