From f9affb9fb8a10ae2c7ddba68da52037630e49b7b Mon Sep 17 00:00:00 2001 From: Konstantin Kondrashov Date: Fri, 22 Jun 2018 15:17:55 +0500 Subject: [PATCH] assert: Fix. Move useful functions from wrapped assert functions Moved useful functions from wrapped assert functions, because option `CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED=y` will remove this functions. Closes https://github.com/espressif/esp-idf/issues/2068 --- components/bootloader_support/src/bootloader_sha.c | 11 ++++++++--- components/heap/multi_heap_poisoning.c | 3 ++- examples/peripherals/adc2/main/adc2_example_main.c | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/components/bootloader_support/src/bootloader_sha.c b/components/bootloader_support/src/bootloader_sha.c index be23f7f26..a8d537e04 100644 --- a/components/bootloader_support/src/bootloader_sha.c +++ b/components/bootloader_support/src/bootloader_sha.c @@ -28,7 +28,10 @@ bootloader_sha256_handle_t bootloader_sha256_start() return NULL; } mbedtls_sha256_init(ctx); - assert(mbedtls_sha256_starts_ret(ctx, false) == 0); + int ret = mbedtls_sha256_starts_ret(ctx, false); + if (ret != 0) { + return NULL; + } return ctx; } @@ -36,7 +39,8 @@ void bootloader_sha256_data(bootloader_sha256_handle_t handle, const void *data, { assert(handle != NULL); mbedtls_sha256_context *ctx = (mbedtls_sha256_context *)handle; - assert(mbedtls_sha256_update_ret(ctx, data, data_len) == 0); + int ret = mbedtls_sha256_update_ret(ctx, data, data_len); + assert(ret == 0); } void bootloader_sha256_finish(bootloader_sha256_handle_t handle, uint8_t *digest) @@ -44,7 +48,8 @@ void bootloader_sha256_finish(bootloader_sha256_handle_t handle, uint8_t *digest assert(handle != NULL); mbedtls_sha256_context *ctx = (mbedtls_sha256_context *)handle; if (digest != NULL) { - assert(mbedtls_sha256_finish_ret(ctx, digest) == 0); + int ret = mbedtls_sha256_finish_ret(ctx, digest); + assert(ret == 0); } mbedtls_sha256_free(ctx); free(handle); diff --git a/components/heap/multi_heap_poisoning.c b/components/heap/multi_heap_poisoning.c index 1fdf586aa..aa50bc59e 100644 --- a/components/heap/multi_heap_poisoning.c +++ b/components/heap/multi_heap_poisoning.c @@ -182,7 +182,8 @@ void *multi_heap_malloc(multi_heap_handle_t heap, size_t size) data = poison_allocated_region(head, size); #ifdef SLOW /* check everything we got back is FREE_FILL_PATTERN & swap for MALLOC_FILL_PATTERN */ - assert( verify_fill_pattern(data, size, true, true, true) ); + bool ret = verify_fill_pattern(data, size, true, true, true); + assert( ret ); #endif } diff --git a/examples/peripherals/adc2/main/adc2_example_main.c b/examples/peripherals/adc2/main/adc2_example_main.c index 309053ad1..3542dad8d 100644 --- a/examples/peripherals/adc2/main/adc2_example_main.c +++ b/examples/peripherals/adc2/main/adc2_example_main.c @@ -28,8 +28,10 @@ void app_main(void) gpio_num_t adc_gpio_num, dac_gpio_num; - assert( adc2_pad_get_io_num( ADC2_EXAMPLE_CHANNEL, &adc_gpio_num ) == ESP_OK ); - assert( dac_pad_get_io_num( DAC_EXAMPLE_CHANNEL, &dac_gpio_num ) == ESP_OK ); + r = adc2_pad_get_io_num( ADC2_EXAMPLE_CHANNEL, &adc_gpio_num ); + assert( r == ESP_OK ); + r = dac_pad_get_io_num( DAC_EXAMPLE_CHANNEL, &dac_gpio_num ); + assert( r == ESP_OK ); printf("ADC channel %d @ GPIO %d, DAC channel %d @ GPIO %d.\n", ADC2_EXAMPLE_CHANNEL, adc_gpio_num, DAC_EXAMPLE_CHANNEL, dac_gpio_num );