mirror of https://github.com/tailix/libkernaux.git
Main: include/kernaux/assert.h: Macro "KERNAUX_PANIC" receives string
This commit is contained in:
parent
5bf174eb65
commit
c2dddb9448
|
@ -1,4 +1,8 @@
|
||||||
2022-06-31 Alex Kotov <kotovalexarian@gmail.com>
|
2022-06-02 Alex Kotov <kotovalexarian@gmail.com>
|
||||||
|
|
||||||
|
* include/kernaux/assert.h: Macro "KERNAUX_PANIC" receives string
|
||||||
|
|
||||||
|
2022-06-01 Alex Kotov <kotovalexarian@gmail.com>
|
||||||
|
|
||||||
* include/kernaux/ntoa.h: Protect from too long prefix
|
* include/kernaux/ntoa.h: Protect from too long prefix
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ int main()
|
||||||
assert(count == 1);
|
assert(count == 1);
|
||||||
assert(strcmp(last_file, __FILE__) == 0);
|
assert(strcmp(last_file, __FILE__) == 0);
|
||||||
assert(last_line == 28);
|
assert(last_line == 28);
|
||||||
assert(strcmp(last_str, "\"foo\"") == 0);
|
assert(strcmp(last_str, "foo") == 0);
|
||||||
assert(noreturn_count == 2);
|
assert(noreturn_count == 2);
|
||||||
|
|
||||||
assert(!test_panic_retval(true));
|
assert(!test_panic_retval(true));
|
||||||
|
@ -69,6 +69,6 @@ int main()
|
||||||
assert(count == 2);
|
assert(count == 2);
|
||||||
assert(strcmp(last_file, __FILE__) == 0);
|
assert(strcmp(last_file, __FILE__) == 0);
|
||||||
assert(last_line == 34);
|
assert(last_line == 34);
|
||||||
assert(strcmp(last_str, "\"bar\"") == 0);
|
assert(strcmp(last_str, "bar") == 0);
|
||||||
assert(noreturn_count == 2);
|
assert(noreturn_count == 2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,12 +36,12 @@ int main()
|
||||||
assert(count == 1);
|
assert(count == 1);
|
||||||
assert(strcmp(last_file, __FILE__) == 0);
|
assert(strcmp(last_file, __FILE__) == 0);
|
||||||
assert(last_line == __LINE__ - 4);
|
assert(last_line == __LINE__ - 4);
|
||||||
assert(strcmp(last_str, "\"bar\"") == 0);
|
assert(strcmp(last_str, "bar") == 0);
|
||||||
|
|
||||||
KERNAUX_PANIC("car");
|
KERNAUX_PANIC("car");
|
||||||
|
|
||||||
assert(count == 2);
|
assert(count == 2);
|
||||||
assert(strcmp(last_file, __FILE__) == 0);
|
assert(strcmp(last_file, __FILE__) == 0);
|
||||||
assert(last_line == __LINE__ - 4);
|
assert(last_line == __LINE__ - 4);
|
||||||
assert(strcmp(last_str, "\"car\"") == 0);
|
assert(strcmp(last_str, "car") == 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define KERNAUX_PANIC(msg) (kernaux_assert_do(__FILE__, __LINE__, #msg))
|
#define KERNAUX_PANIC(msg) (kernaux_assert_do(__FILE__, __LINE__, msg))
|
||||||
#define KERNAUX_ASSERT(cond) ((cond) ? (void)0 : KERNAUX_PANIC(cond))
|
#define KERNAUX_ASSERT(cond) ((cond) ? (void)0 : KERNAUX_PANIC(#cond))
|
||||||
|
|
||||||
#define KERNAUX_PANIC_RETURN(msg) do { KERNAUX_PANIC(msg); return; } while (0)
|
#define KERNAUX_PANIC_RETURN(msg) do { KERNAUX_PANIC(msg); return; } while (0)
|
||||||
#define KERNAUX_PANIC_RETVAL(msg, val) do { KERNAUX_PANIC(msg); return (val); } while (0)
|
#define KERNAUX_PANIC_RETVAL(msg, val) do { KERNAUX_PANIC(msg); return (val); } while (0)
|
||||||
|
|
|
@ -37,7 +37,7 @@ char *kernaux_utoa(uint64_t value, char *buffer, int base, const char *prefix)
|
||||||
if (prefix_len > KERNAUX_NTOA_MAX_PREFIX_LEN) {
|
if (prefix_len > KERNAUX_NTOA_MAX_PREFIX_LEN) {
|
||||||
// Protect caller from invalid state
|
// Protect caller from invalid state
|
||||||
*buffer = '\0';
|
*buffer = '\0';
|
||||||
KERNAUX_PANIC_RETVAL(prefix is too long, NULL);
|
KERNAUX_PANIC_RETVAL("prefix is too long", NULL);
|
||||||
}
|
}
|
||||||
*(buffer++) = *(prefix++);
|
*(buffer++) = *(prefix++);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue