aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAyrton Munoz <ayrton@google.com>2022-10-20 12:32:24 -0400
committerAyrton Munoz <ayrton@google.com>2022-10-20 21:23:05 +0000
commit1bcf7281725e9b48b9271400643ac65f227ca9ac (patch)
tree9a467337b12d2bc44fbf57187c90429c8b969b74 /lib
parent334c9ec7a0c1688fa6726b29b3222d140857ad65 (diff)
downloadcommon-1bcf7281725e9b48b9271400643ac65f227ca9ac.tar.gz
lib/libc: Make DEBUG_ASSERT use asserted expression in all cases
When LK_DEBUGLEVEL is less than 2 the variable asserted in DEBUG_ASSERT must be used afterwards to avoid a `variable set but not used` error. This change allows defining variables which only need to be asserted. It also fixes a few cases in miniheap that did not compile because of conditionally defined struct fields/variables. This fixes the generic-arm* targets when switching to musl. Bug: 230134581 Change-Id: I9753d238470caabaaebd5fb02558fc37ebce94ba
Diffstat (limited to 'lib')
-rw-r--r--lib/heap/miniheap/miniheap.c4
-rw-r--r--lib/libc/include_common/assert.h2
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/heap/miniheap/miniheap.c b/lib/heap/miniheap/miniheap.c
index 51f9412c..dad20f79 100644
--- a/lib/heap/miniheap/miniheap.c
+++ b/lib/heap/miniheap/miniheap.c
@@ -124,7 +124,9 @@ static struct free_heap_chunk *heap_insert_free_chunk(struct free_heap_chunk *ch
// walk through the list, finding the node to insert before
list_for_every_entry(&theheap.free_list, next_chunk, struct free_heap_chunk, node) {
if (chunk < next_chunk) {
+#if LK_DEBUGLEVEL > INFO
DEBUG_ASSERT(chunk_end <= (vaddr_t)next_chunk);
+#endif
list_add_before(&next_chunk->node, &chunk->node);
@@ -354,7 +356,9 @@ void miniheap_free(void *ptr)
struct alloc_struct_begin *as = (struct alloc_struct_begin *)ptr;
as--;
+#if LK_DEBUGLEVEL > 1
DEBUG_ASSERT(as->magic == HEAP_MAGIC);
+#endif
#if DEBUG_HEAP
{
diff --git a/lib/libc/include_common/assert.h b/lib/libc/include_common/assert.h
index 21d109a5..7caf9a16 100644
--- a/lib/libc/include_common/assert.h
+++ b/lib/libc/include_common/assert.h
@@ -34,7 +34,7 @@
do { if (unlikely(!(x))) { panic("DEBUG ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
#else
#define DEBUG_ASSERT(x) \
- do { } while(0)
+ do { (void)(x); } while(0)
#endif
#define assert(e) DEBUG_ASSERT(e)