Main: include/kernaux/assert.h: Macro "KERNAUX_PANIC" receives string

This commit is contained in:
Alex Kotov 2022-06-02 13:25:52 +03:00
parent 5bf174eb65
commit c2dddb9448
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
5 changed files with 12 additions and 8 deletions

View File

@ -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

View File

@ -61,7 +61,7 @@ int main()
assert(count == 1);
assert(strcmp(last_file, __FILE__) == 0);
assert(last_line == 28);
assert(strcmp(last_str, "\"foo\"") == 0);
assert(strcmp(last_str, "foo") == 0);
assert(noreturn_count == 2);
assert(!test_panic_retval(true));
@ -69,6 +69,6 @@ int main()
assert(count == 2);
assert(strcmp(last_file, __FILE__) == 0);
assert(last_line == 34);
assert(strcmp(last_str, "\"bar\"") == 0);
assert(strcmp(last_str, "bar") == 0);
assert(noreturn_count == 2);
}

View File

@ -36,12 +36,12 @@ int main()
assert(count == 1);
assert(strcmp(last_file, __FILE__) == 0);
assert(last_line == __LINE__ - 4);
assert(strcmp(last_str, "\"bar\"") == 0);
assert(strcmp(last_str, "bar") == 0);
KERNAUX_PANIC("car");
assert(count == 2);
assert(strcmp(last_file, __FILE__) == 0);
assert(last_line == __LINE__ - 4);
assert(strcmp(last_str, "\"car\"") == 0);
assert(strcmp(last_str, "car") == 0);
}

View File

@ -5,8 +5,8 @@
extern "C" {
#endif
#define KERNAUX_PANIC(msg) (kernaux_assert_do(__FILE__, __LINE__, #msg))
#define KERNAUX_ASSERT(cond) ((cond) ? (void)0 : KERNAUX_PANIC(cond))
#define KERNAUX_PANIC(msg) (kernaux_assert_do(__FILE__, __LINE__, msg))
#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_RETVAL(msg, val) do { KERNAUX_PANIC(msg); return (val); } while (0)

View File

@ -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) {
// Protect caller from invalid state
*buffer = '\0';
KERNAUX_PANIC_RETVAL(prefix is too long, NULL);
KERNAUX_PANIC_RETVAL("prefix is too long", NULL);
}
*(buffer++) = *(prefix++);
}