From 4a4407126c3f4ed67eea72c924e72e2fdc1f3cd4 Mon Sep 17 00:00:00 2001 From: Michael Graeb Date: Thu, 2 Feb 2023 09:33:17 -0800 Subject: [PATCH] Assert that each error-info-list starts with correct value (#978) --- source/error.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/error.c b/source/error.c index bcc73e9cc..ad3cec869 100644 --- a/source/error.c +++ b/source/error.c @@ -145,8 +145,20 @@ void aws_register_error_info(const struct aws_error_info_list *error_info) { } #if DEBUG_BUILD + /* Assert that first error has the right value */ + const int expected_first_code = slot_index << AWS_ERROR_ENUM_STRIDE_BITS; + if (error_info->error_list[0].error_code != expected_first_code) { + fprintf( + stderr, + "Missing info: First error in list should be %d, not %d (%s)\n", + expected_first_code, + error_info->error_list[0].error_code, + error_info->error_list[0].literal_name); + AWS_FATAL_ASSERT(0); + } + /* Assert that error info entries are in the right order. */ - for (int i = 1; i < error_info->count; ++i) { + for (int i = 0; i < error_info->count; ++i) { const int expected_code = min_range + i; const struct aws_error_info *info = &error_info->error_list[i]; if (info->error_code != expected_code) {