From 3a568075688fe9984b9ae1cf521c3aab747f8450 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Wed, 21 Dec 2022 11:30:50 +0530 Subject: [PATCH 1/4] protocomm: remove "Wno-format" cflag and fix formatting errors --- components/protocomm/CMakeLists.txt | 2 -- components/protocomm/src/common/protocomm.c | 5 +++-- components/protocomm/src/security/security1.c | 7 ++++--- components/protocomm/src/security/security2.c | 9 +++++---- .../protocomm/src/simple_ble/simple_ble.c | 9 +++++---- .../protocomm/src/transports/protocomm_httpd.c | 17 +++++++++-------- .../protocomm/src/transports/protocomm_nimble.c | 7 ++++--- 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/components/protocomm/CMakeLists.txt b/components/protocomm/CMakeLists.txt index 4c35f55eb5..d98541d8f1 100644 --- a/components/protocomm/CMakeLists.txt +++ b/components/protocomm/CMakeLists.txt @@ -48,5 +48,3 @@ idf_component_register(SRCS "${srcs}" PRIV_INCLUDE_DIRS "${priv_include_dirs}" PRIV_REQUIRES protobuf-c mbedtls console esp_http_server driver REQUIRES bt) - -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/protocomm/src/common/protocomm.c b/components/protocomm/src/common/protocomm.c index 8a6433170e..c8e0012db5 100644 --- a/components/protocomm/src/common/protocomm.c +++ b/components/protocomm/src/common/protocomm.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -149,7 +150,7 @@ esp_err_t protocomm_open_session(protocomm_t *pc, uint32_t session_id) if (pc->sec && pc->sec->new_transport_session) { esp_err_t ret = pc->sec->new_transport_session(pc->sec_inst, session_id); if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to launch new session with ID: %d", session_id); + ESP_LOGE(TAG, "Failed to launch new session with ID: %" PRId32, session_id); return ret; } } @@ -165,7 +166,7 @@ esp_err_t protocomm_close_session(protocomm_t *pc, uint32_t session_id) if (pc->sec && pc->sec->close_transport_session) { esp_err_t ret = pc->sec->close_transport_session(pc->sec_inst, session_id); if (ret != ESP_OK) { - ESP_LOGE(TAG, "Error while closing session with ID: %d", session_id); + ESP_LOGE(TAG, "Error while closing session with ID: %" PRId32, session_id); return ret; } } diff --git a/components/protocomm/src/security/security1.c b/components/protocomm/src/security/security1.c index f530055fab..dbc62383fc 100644 --- a/components/protocomm/src/security/security1.c +++ b/components/protocomm/src/security/security1.c @@ -9,6 +9,7 @@ #include #include #include +#include /* TODO: Currently MBEDTLS_ECDH_LEGACY_CONTEXT is enabled by default * when MBEDTLS_ECP_RESTARTABLE is enabled. @@ -459,7 +460,7 @@ static esp_err_t sec1_new_session(protocomm_security_handle_t handle, uint32_t s if (cur_session->id != -1) { /* Only one session is allowed at a time */ - ESP_LOGE(TAG, "Closing old session with id %u", cur_session->id); + ESP_LOGE(TAG, "Closing old session with id %" PRIu32, cur_session->id); sec1_close_session(cur_session, session_id); } @@ -503,7 +504,7 @@ static esp_err_t sec1_decrypt(protocomm_security_handle_t handle, } if (!cur_session || cur_session->id != session_id) { - ESP_LOGE(TAG, "Session with ID %d not found", session_id); + ESP_LOGE(TAG, "Session with ID %" PRId32 "not found", session_id); return ESP_ERR_INVALID_STATE; } @@ -542,7 +543,7 @@ static esp_err_t sec1_req_handler(protocomm_security_handle_t handle, } if (session_id != cur_session->id) { - ESP_LOGE(TAG, "Invalid session ID : %d (expected %d)", session_id, cur_session->id); + ESP_LOGE(TAG, "Invalid session ID:%" PRId32 "(expected %" PRId32 ")", session_id, cur_session->id); return ESP_ERR_INVALID_STATE; } diff --git a/components/protocomm/src/security/security2.c b/components/protocomm/src/security/security2.c index 19e33f8ee2..fe1250019a 100644 --- a/components/protocomm/src/security/security2.c +++ b/components/protocomm/src/security/security2.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -367,7 +368,7 @@ static esp_err_t sec2_new_session(protocomm_security_handle_t handle, uint32_t s if (cur_session->id != -1) { /* Only one session is allowed at a time */ - ESP_LOGE(TAG, "Closing old session with id %u", cur_session->id); + ESP_LOGE(TAG, "Closing old session with id %" PRIu32, cur_session->id); sec2_close_session(cur_session, session_id); } @@ -411,7 +412,7 @@ static esp_err_t sec2_encrypt(protocomm_security_handle_t handle, } if (!cur_session || cur_session->id != session_id) { - ESP_LOGE(TAG, "Session with ID %d not found", session_id); + ESP_LOGE(TAG, "Session with ID %" PRId32 "not found", session_id); return ESP_ERR_INVALID_STATE; } @@ -451,7 +452,7 @@ static esp_err_t sec2_decrypt(protocomm_security_handle_t handle, } if (!cur_session || cur_session->id != session_id) { - ESP_LOGE(TAG, "Session with ID %d not found", session_id); + ESP_LOGE(TAG, "Session with ID %" PRId32 "not found", session_id); return ESP_ERR_INVALID_STATE; } @@ -490,7 +491,7 @@ static esp_err_t sec2_req_handler(protocomm_security_handle_t handle, } if (session_id != cur_session->id) { - ESP_LOGE(TAG, "Invalid session ID : %d (expected %d)", session_id, cur_session->id); + ESP_LOGE(TAG, "Invalid session ID:%" PRId32 "(expected %" PRId32 ")", session_id, cur_session->id); return ESP_ERR_INVALID_STATE; } diff --git a/components/protocomm/src/simple_ble/simple_ble.c b/components/protocomm/src/simple_ble/simple_ble.c index e59f05ec18..ec210408d2 100644 --- a/components/protocomm/src/simple_ble/simple_ble.c +++ b/components/protocomm/src/simple_ble/simple_ble.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include #include @@ -209,7 +210,7 @@ esp_err_t simple_ble_deinit(void) esp_err_t simple_ble_start(simple_ble_cfg_t *cfg) { g_ble_cfg_p = cfg; - ESP_LOGD(TAG, "Free mem at start of simple_ble_init %d", esp_get_free_heap_size()); + ESP_LOGD(TAG, "Free mem at start of simple_ble_init %" PRIu32, esp_get_free_heap_size()); esp_err_t ret; esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); @@ -267,7 +268,7 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg) if (local_mtu_ret) { ESP_LOGE(TAG, "set local MTU failed, error code = 0x%x", local_mtu_ret); } - ESP_LOGD(TAG, "Free mem at end of simple_ble_init %d", esp_get_free_heap_size()); + ESP_LOGD(TAG, "Free mem at end of simple_ble_init %" PRIu32, esp_get_free_heap_size()); /* set the security iocap & auth_req & key size & init key response key parameters to the stack*/ esp_ble_auth_req_t auth_req= ESP_LE_AUTH_REQ_MITM; @@ -294,7 +295,7 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg) esp_err_t simple_ble_stop(void) { esp_err_t err; - ESP_LOGD(TAG, "Free mem at start of simple_ble_stop %d", esp_get_free_heap_size()); + ESP_LOGD(TAG, "Free mem at start of simple_ble_stop %" PRIu32, esp_get_free_heap_size()); err = esp_bluedroid_disable(); if (err != ESP_OK) { return ESP_FAIL; @@ -320,7 +321,7 @@ esp_err_t simple_ble_stop(void) } ESP_LOGD(TAG, "esp_bt_controller_deinit called successfully"); - ESP_LOGD(TAG, "Free mem at end of simple_ble_stop %d", esp_get_free_heap_size()); + ESP_LOGD(TAG, "Free mem at end of simple_ble_stop %" PRIu32, esp_get_free_heap_size()); return ESP_OK; } diff --git a/components/protocomm/src/transports/protocomm_httpd.c b/components/protocomm/src/transports/protocomm_httpd.c index 33a4337141..eaa0019577 100644 --- a/components/protocomm/src/transports/protocomm_httpd.c +++ b/components/protocomm/src/transports/protocomm_httpd.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "esp_random.h" #include @@ -34,7 +35,7 @@ static void protocomm_httpd_session_close(void *ctx) * request is for the same session. */ if (sock_session_id != PROTOCOMM_NO_SESSION_ID) { - ESP_LOGW(TAG, "Resetting socket session id as socket %d was closed", sock_session_id); + ESP_LOGW(TAG, "Resetting socket session id as socket %" PRId32 "was closed", sock_session_id); sock_session_id = PROTOCOMM_NO_SESSION_ID; } } @@ -56,12 +57,12 @@ static esp_err_t common_post_handler(httpd_req_t *req) if (httpd_req_get_hdr_value_str(req, "Cookie", cookie_buf, sizeof(cookie_buf)) == ESP_OK) { ESP_LOGD(TAG, "Received cookie %s", cookie_buf); char session_cookie[20] = {0}; - snprintf(session_cookie, sizeof(session_cookie), "session=%u", cookie_session_id); + snprintf(session_cookie, sizeof(session_cookie), "session=%" PRIu32, cookie_session_id); /* If a cookie is found, check it against the session id. If it matches, * it means that this is a continuation of the same session. */ if (strcmp(session_cookie, cookie_buf) == 0) { - ESP_LOGD(TAG, "Continuing Session %u", cookie_session_id); + ESP_LOGD(TAG, "Continuing Session %" PRIu32, cookie_session_id); /* If we reach here, it means that the client supports cookies and so the * socket session id would no more be required for checking. */ @@ -70,7 +71,7 @@ static esp_err_t common_post_handler(httpd_req_t *req) } } else if (cur_sock_session_id == sock_session_id) { /* If the socket number matches, we assume it to be the same session */ - ESP_LOGD(TAG, "Continuing Socket Session %u", sock_session_id); + ESP_LOGD(TAG, "Continuing Socket Session %" PRIu32, sock_session_id); same_session = true; } if (!same_session) { @@ -78,11 +79,11 @@ static esp_err_t common_post_handler(httpd_req_t *req) * first close any existing sessions as applicable. */ if (cookie_session_id != PROTOCOMM_NO_SESSION_ID) { - ESP_LOGW(TAG, "Closing session with ID: %u", cookie_session_id); + ESP_LOGW(TAG, "Closing session with ID: %" PRIu32, cookie_session_id); if (pc_httpd->sec && pc_httpd->sec->close_transport_session) { ret = pc_httpd->sec->close_transport_session(pc_httpd->sec_inst, cookie_session_id); if (ret != ESP_OK) { - ESP_LOGW(TAG, "Error closing session with ID: %u", cookie_session_id); + ESP_LOGW(TAG, "Error closing session with ID: %" PRIu32, cookie_session_id); } } cookie_session_id = PROTOCOMM_NO_SESSION_ID; @@ -104,7 +105,7 @@ static esp_err_t common_post_handler(httpd_req_t *req) } cookie_session_id = cur_cookie_session_id; sock_session_id = cur_sock_session_id; - ESP_LOGD(TAG, "New socket session ID: %d", sock_session_id); + ESP_LOGD(TAG, "New socket session ID: %" PRId32, sock_session_id); } if (req->content_len <= 0) { @@ -147,7 +148,7 @@ static esp_err_t common_post_handler(httpd_req_t *req) } /* If this is a new session, send the session id in a cookie */ if (!same_session) { - snprintf(cookie_buf, sizeof(cookie_buf), "session=%u", cookie_session_id); + snprintf(cookie_buf, sizeof(cookie_buf), "session=%" PRIu32, cookie_session_id); ESP_LOGD(TAG, "Setting cookie %s", cookie_buf); httpd_resp_set_hdr(req, "Set-Cookie", cookie_buf); } diff --git a/components/protocomm/src/transports/protocomm_nimble.c b/components/protocomm/src/transports/protocomm_nimble.c index f3b894f3de..d8f9e2f91c 100644 --- a/components/protocomm/src/transports/protocomm_nimble.c +++ b/components/protocomm/src/transports/protocomm_nimble.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -208,7 +209,7 @@ simple_ble_advertise(void) return; } /* Take note of free heap space */ - ESP_LOGD(TAG, "Minimum free heap size = %d, free Heap size = %d", + ESP_LOGD(TAG, "Minimum free heap size = %" PRIu32 ", free Heap size = %" PRIu32, esp_get_minimum_free_heap_size(), esp_get_free_heap_size()); } @@ -488,7 +489,7 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg) { ble_cfg_p = (void *)cfg; int rc; - ESP_LOGD(TAG, "Free memory at start of simple_ble_init %d", esp_get_free_heap_size()); + ESP_LOGD(TAG, "Free memory at start of simple_ble_init %" PRIu32, esp_get_free_heap_size()); nimble_port_init(); @@ -948,7 +949,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con } esp_err_t err = simple_ble_start(ble_config); - ESP_LOGD(TAG, "Free Heap size after simple_ble_start= %d", esp_get_free_heap_size()); + ESP_LOGD(TAG, "Free Heap size after simple_ble_start= %" PRIu32, esp_get_free_heap_size()); if (err != ESP_OK) { ESP_LOGE(TAG, "simple_ble_start failed w/ error code 0x%x", err); From bbc5914e63275138526b00cdc5fa38ac09de9726 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Wed, 21 Dec 2022 11:33:04 +0530 Subject: [PATCH 2/4] esp_http_client: remove "Wno-format" cflag and fix formatting errors --- components/esp_http_client/CMakeLists.txt | 2 -- components/esp_http_client/esp_http_client.c | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/esp_http_client/CMakeLists.txt b/components/esp_http_client/CMakeLists.txt index 3a2dcef3e6..cc1f844cff 100644 --- a/components/esp_http_client/CMakeLists.txt +++ b/components/esp_http_client/CMakeLists.txt @@ -7,5 +7,3 @@ idf_component_register(SRCS "esp_http_client.c" # lwip is a public requirement because esp_http_client.h includes sys/socket.h REQUIRES lwip PRIV_REQUIRES tcp_transport http_parser) - -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index ca8fe9eccb..681bfef2ed 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -6,6 +6,7 @@ #include +#include #include "esp_system.h" #include "esp_log.h" @@ -253,7 +254,7 @@ static int http_on_headers_complete(http_parser *parser) client->response->data_offset = parser->nread; client->response->content_length = parser->content_length; client->response->data_process = 0; - ESP_LOGD(TAG, "http_on_headers_complete, status=%d, offset=%d, nread=%d", parser->status_code, client->response->data_offset, parser->nread); + ESP_LOGD(TAG, "http_on_headers_complete, status=%d, offset=%d, nread=%" PRId32, parser->status_code, client->response->data_offset, parser->nread); client->state = HTTP_STATE_RES_COMPLETE_HEADER; if (client->connection_info.method == HTTP_METHOD_HEAD) { /* In a HTTP_RESPONSE parser returning '1' from on_headers_complete will tell the From 035c2e579941620f667b93429637aa2c904ee6a4 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Wed, 21 Dec 2022 11:33:38 +0530 Subject: [PATCH 3/4] esp_http(s)_server: remove "Wno-format" cflag and fix formatting errors --- components/esp_http_server/CMakeLists.txt | 2 -- components/esp_http_server/src/httpd_parse.c | 3 ++- components/esp_https_ota/CMakeLists.txt | 2 -- components/esp_https_ota/src/esp_https_ota.c | 3 ++- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/components/esp_http_server/CMakeLists.txt b/components/esp_http_server/CMakeLists.txt index d098ec067d..c660da3aa5 100644 --- a/components/esp_http_server/CMakeLists.txt +++ b/components/esp_http_server/CMakeLists.txt @@ -9,5 +9,3 @@ idf_component_register(SRCS "src/httpd_main.c" PRIV_INCLUDE_DIRS "src/port/esp32" "src/util" REQUIRES esp_event http_parser # for http_parser.h PRIV_REQUIRES lwip mbedtls esp_timer) - -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/esp_http_server/src/httpd_parse.c b/components/esp_http_server/src/httpd_parse.c index 5ff8aafa0e..9c27c297a5 100644 --- a/components/esp_http_server/src/httpd_parse.c +++ b/components/esp_http_server/src/httpd_parse.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "esp_httpd_priv.h" @@ -364,7 +365,7 @@ static esp_err_t cb_headers_complete(http_parser *parser) r->content_len = ((int)parser->content_length != -1 ? parser->content_length : 0); - ESP_LOGD(TAG, LOG_FMT("bytes read = %d"), parser->nread); + ESP_LOGD(TAG, LOG_FMT("bytes read = %" PRId32 ""), parser->nread); ESP_LOGD(TAG, LOG_FMT("content length = %zu"), r->content_len); /* Handle upgrade requests - only WebSocket is supported for now */ diff --git a/components/esp_https_ota/CMakeLists.txt b/components/esp_https_ota/CMakeLists.txt index b4d88d02a5..6dfe5f9ac4 100644 --- a/components/esp_https_ota/CMakeLists.txt +++ b/components/esp_https_ota/CMakeLists.txt @@ -2,5 +2,3 @@ idf_component_register(SRCS "src/esp_https_ota.c" INCLUDE_DIRS "include" REQUIRES esp_http_client bootloader_support esp_app_format esp_event PRIV_REQUIRES log app_update) - -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index 9302830d92..9541093f4d 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -12,6 +12,7 @@ #include #include #include +#include ESP_EVENT_DEFINE_BASE(ESP_HTTPS_OTA_EVENT); @@ -342,7 +343,7 @@ esp_err_t esp_https_ota_begin(const esp_https_ota_config_t *ota_config, esp_http err = ESP_FAIL; goto http_cleanup; } - ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x", + ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%" PRIx32, https_ota_handle->update_partition->subtype, https_ota_handle->update_partition->address); const int alloc_size = MAX(ota_config->http_config->buffer_size, DEFAULT_OTA_BUF_SIZE); From b709c84e1ca4e14143085967b7dcd83bead3a143 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Wed, 21 Dec 2022 11:34:13 +0530 Subject: [PATCH 4/4] esp_local_ctrl: remove "Wno-format" cflag and fix formatting errors --- components/esp_local_ctrl/CMakeLists.txt | 2 -- components/esp_local_ctrl/src/esp_local_ctrl.c | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/components/esp_local_ctrl/CMakeLists.txt b/components/esp_local_ctrl/CMakeLists.txt index ef9024913a..d71ac890df 100644 --- a/components/esp_local_ctrl/CMakeLists.txt +++ b/components/esp_local_ctrl/CMakeLists.txt @@ -24,5 +24,3 @@ idf_component_register(SRCS "${srcs}" PRIV_REQUIRES protobuf-c) idf_component_optional_requires(PRIVATE espressif__mdns mdns) - -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/esp_local_ctrl/src/esp_local_ctrl.c b/components/esp_local_ctrl/src/esp_local_ctrl.c index c1fef0ee23..51de3df35b 100644 --- a/components/esp_local_ctrl/src/esp_local_ctrl.c +++ b/components/esp_local_ctrl/src/esp_local_ctrl.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -355,7 +356,7 @@ esp_err_t esp_local_ctrl_get_prop_values(size_t total_indices, uint32_t *indices /* Convert indices to names */ for (size_t i = 0; i < total_indices; i++) { if (indices[i] >= local_ctrl_inst_ctx->props_count) { - ESP_LOGE(TAG, "Invalid property index %d", indices[i]); + ESP_LOGE(TAG, "Invalid property index %" PRId32, indices[i]); return ESP_ERR_INVALID_ARG; } props[i].name = local_ctrl_inst_ctx->props[indices[i]]->name; @@ -396,7 +397,7 @@ esp_err_t esp_local_ctrl_set_prop_values(size_t total_indices, uint32_t *indices } for (size_t i = 0; i < total_indices; i++) { if (indices[i] >= local_ctrl_inst_ctx->props_count) { - ESP_LOGE(TAG, "Invalid property index %d", indices[i]); + ESP_LOGE(TAG, "Invalid property index %" PRId32, indices[i]); free(props); return ESP_ERR_INVALID_ARG; }