From e9ef70e24ba796b6d69a18a949e0fbfeb6fb2d35 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Fri, 17 Feb 2023 12:00:29 +0200 Subject: [PATCH] sched/assert: Call abort() instead of exit() in assert POSIX dictates that assert() terminates via abort(), even though in NuttX abort() just calls exit(EXIT_FAILURE) it is better to use the correct API here, if at some point a proper implementation for abort() is made. Also, as the kernel must not use abort() which is a userspace API, direct the exit to PANIC() if for some reason _assert() returns (it should not but trap it here just in case). --- libs/libc/assert/lib_assert.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/libc/assert/lib_assert.c b/libs/libc/assert/lib_assert.c index 5ff55c86a30..97bb7517b5e 100644 --- a/libs/libc/assert/lib_assert.c +++ b/libs/libc/assert/lib_assert.c @@ -27,6 +27,16 @@ #include #include +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* If assert() is called from kernel, must not call user API abort */ + +#ifdef __KERNEL__ +# define abort PANIC +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -34,5 +44,5 @@ void __assert(FAR const char *filename, int linenum, FAR const char *msg) { _assert(filename, linenum, msg); - exit(EXIT_FAILURE); + abort(); }