From: Roland Dobai Date: Mon, 9 Apr 2018 10:58:35 +0000 (+0200) Subject: Resolve problems found by enabling -Wwrite-strings compilation flag X-Git-Tag: v3.1-beta1~273^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=744c2dcdd91d9ac28be1080df50e616713cd9749;p=esp-idf Resolve problems found by enabling -Wwrite-strings compilation flag --- diff --git a/components/bootloader/subproject/main/bootloader_start.c b/components/bootloader/subproject/main/bootloader_start.c index c20273cec1..37a3af9692 100644 --- a/components/bootloader/subproject/main/bootloader_start.c +++ b/components/bootloader/subproject/main/bootloader_start.c @@ -141,7 +141,7 @@ bool load_partition_table(bootloader_state_t* bs) { const esp_partition_info_t *partitions; const int ESP_PARTITION_TABLE_DATA_LEN = 0xC00; /* length of actual data (signature is appended to this) */ - char *partition_usage; + const char *partition_usage; esp_err_t err; int num_partitions; @@ -900,7 +900,7 @@ static void wdt_reset_info_dump(int cpu) { uint32_t inst = 0, pid = 0, stat = 0, data = 0, pc = 0, lsstat = 0, lsaddr = 0, lsdata = 0, dstat = 0; - char *cpu_name = cpu ? "APP" : "PRO"; + const char *cpu_name = cpu ? "APP" : "PRO"; if (cpu == 0) { stat = DPORT_REG_READ(DPORT_PRO_CPU_RECORD_STATUS_REG); diff --git a/components/bt/bluedroid/btc/core/btc_ble_storage.c b/components/bt/bluedroid/btc/core/btc_ble_storage.c index 3c26064281..e2c2b6d3f8 100644 --- a/components/bt/bluedroid/btc/core/btc_ble_storage.c +++ b/components/bt/bluedroid/btc/core/btc_ble_storage.c @@ -392,7 +392,7 @@ bool _btc_storage_compare_address_key_value(bt_bdaddr_t *remote_bd_addr, { bdstr_t bdstr; bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr)); - char *key_type_str; + const char *key_type_str; switch (key_type) { case BTM_LE_KEY_PENC: key_type_str = BTC_BLE_STORAGE_LE_KEY_PENC_STR; diff --git a/components/bt/bluedroid/btc/core/btc_config.c b/components/bt/bluedroid/btc/core/btc_config.c index 7b733ae7b9..df95701385 100644 --- a/components/bt/bluedroid/btc/core/btc_config.c +++ b/components/bt/bluedroid/btc/core/btc_config.c @@ -36,7 +36,7 @@ static void btc_key_value_to_string(uint8_t *key_value, char *value_str, int key static osi_mutex_t lock; // protects operations on |config|. static config_t *config; -bool btc_compare_address_key_value(const char *section, char *key_type, void *key_value, int key_length) +bool btc_compare_address_key_value(const char *section, const char *key_type, void *key_value, int key_length) { assert(key_value != NULL); bool status = false; diff --git a/components/bt/bluedroid/btc/include/btc_config.h b/components/bt/bluedroid/btc/include/btc_config.h index 79f6137e85..dfbdcdbadf 100644 --- a/components/bt/bluedroid/btc/include/btc_config.h +++ b/components/bt/bluedroid/btc/include/btc_config.h @@ -49,7 +49,7 @@ int btc_config_clear(void); // TODO(zachoverflow): Eww...we need to move these out. These are peer specific, not config general. bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type); -bool btc_compare_address_key_value(const char *section, char *key_type, void *key_value, int key_length); +bool btc_compare_address_key_value(const char *section, const char *key_type, void *key_value, int key_length); bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type); void btc_config_lock(void); diff --git a/components/bt/bluedroid/osi/config.c b/components/bt/bluedroid/osi/config.c index 44bdacfa00..c9b76e3502 100644 --- a/components/bt/bluedroid/osi/config.c +++ b/components/bt/bluedroid/osi/config.c @@ -134,7 +134,7 @@ bool config_has_key(const config_t *config, const char *section, const char *key return (entry_find(config, section, key) != NULL); } -bool config_has_key_in_section(config_t *config, char *key, char *key_value) +bool config_has_key_in_section(config_t *config, const char *key, char *key_value) { LOG_DEBUG("key = %s, value = %s", key, key_value); for (const list_node_t *node = list_begin(config->sections); node != list_end(config->sections); node = list_next(node)) { diff --git a/components/bt/bluedroid/osi/include/config.h b/components/bt/bluedroid/osi/include/config.h index 41f5ddb18a..c1a2f3d5d6 100644 --- a/components/bt/bluedroid/osi/include/config.h +++ b/components/bt/bluedroid/osi/include/config.h @@ -68,7 +68,7 @@ bool config_has_key(const config_t *config, const char *section, const char *key // Returns true if the config file has a key named |key| and the key_value. // Returns false otherwise. |config|, |key|, and |key_value| must not be NULL. -bool config_has_key_in_section(config_t *config, char *key, char *key_value); +bool config_has_key_in_section(config_t *config, const char *key, char *key_value); // Returns the integral value for a given |key| in |section|. If |section| // or |key| do not exist, or the value cannot be fully converted to an integer, diff --git a/components/bt/bluedroid/stack/btm/btm_sec.c b/components/bt/bluedroid/stack/btm/btm_sec.c index dda360de23..9a02c526d7 100644 --- a/components/bt/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/bluedroid/stack/btm/btm_sec.c @@ -90,7 +90,7 @@ static tBTM_STATUS btm_sec_send_hci_disconnect (tBTM_SEC_DEV_REC *p_dev_rec, UIN UINT8 btm_sec_start_role_switch (tBTM_SEC_DEV_REC *p_dev_rec); tBTM_SEC_DEV_REC *btm_sec_find_dev_by_sec_state (UINT8 state); -static BOOLEAN btm_sec_set_security_level ( CONNECTION_TYPE conn_type, char *p_name, UINT8 service_id, +static BOOLEAN btm_sec_set_security_level ( CONNECTION_TYPE conn_type, const char *p_name, UINT8 service_id, UINT16 sec_level, UINT16 psm, UINT32 mx_proto_id, UINT32 mx_chan_id); #if (SMP_INCLUDED == TRUE) @@ -459,7 +459,7 @@ void BTM_SetSecureConnectionsOnly (BOOLEAN secure_connections_only_mode) ** Returns TRUE if registered OK, else FALSE ** *******************************************************************************/ -BOOLEAN BTM_SetSecurityLevel (BOOLEAN is_originator, char *p_name, UINT8 service_id, +BOOLEAN BTM_SetSecurityLevel (BOOLEAN is_originator, const char *p_name, UINT8 service_id, UINT16 sec_level, UINT16 psm, UINT32 mx_proto_id, UINT32 mx_chan_id) { @@ -499,7 +499,7 @@ BOOLEAN BTM_SetSecurityLevel (BOOLEAN is_originator, char *p_name, UINT8 service ** Returns TRUE if registered OK, else FALSE ** *******************************************************************************/ -static BOOLEAN btm_sec_set_security_level (CONNECTION_TYPE conn_type, char *p_name, UINT8 service_id, +static BOOLEAN btm_sec_set_security_level (CONNECTION_TYPE conn_type, const char *p_name, UINT8 service_id, UINT16 sec_level, UINT16 psm, UINT32 mx_proto_id, UINT32 mx_chan_id) { diff --git a/components/bt/bluedroid/stack/include/btm_api.h b/components/bt/bluedroid/stack/include/btm_api.h index b685cdb778..113040b2fb 100644 --- a/components/bt/bluedroid/stack/include/btm_api.h +++ b/components/bt/bluedroid/stack/include/btm_api.h @@ -3354,7 +3354,7 @@ void BTM_SetSecureConnectionsOnly (BOOLEAN secure_connections_only_mode); ** *******************************************************************************/ //extern -BOOLEAN BTM_SetSecurityLevel (BOOLEAN is_originator, char *p_name, +BOOLEAN BTM_SetSecurityLevel (BOOLEAN is_originator, const char *p_name, UINT8 service_id, UINT16 sec_level, UINT16 psm, UINT32 mx_proto_id, UINT32 mx_chan_id); diff --git a/components/coap/component.mk b/components/coap/component.mk index 86993b29e9..012188d7ab 100644 --- a/components/coap/component.mk +++ b/components/coap/component.mk @@ -9,3 +9,6 @@ COMPONENT_OBJS = libcoap/src/address.o libcoap/src/async.o libcoap/src/block.o l COMPONENT_SRCDIRS := libcoap/src libcoap port COMPONENT_SUBMODULES += libcoap + +libcoap/src/debug.o: CFLAGS += -Wno-write-strings +libcoap/src/pdu.o: CFLAGS += -Wno-write-strings diff --git a/components/console/argtable3/argtable3.c b/components/console/argtable3/argtable3.c index ed577c83aa..3fdda9068d 100644 --- a/components/console/argtable3/argtable3.c +++ b/components/console/argtable3/argtable3.c @@ -4535,9 +4535,9 @@ static void arg_print_gnuswitch(FILE *fp, struct arg_hdr * *table) { int tabindex; - char *format1 = " -%c"; - char *format2 = " [-%c"; - char *suffix = ""; + const char *format1 = " -%c"; + const char *format2 = " [-%c"; + const char *suffix = ""; /* print all mandatory switches that are without argument values */ for(tabindex = 0; diff --git a/components/esp32/gdbstub.c b/components/esp32/gdbstub.c index 757725aad6..df04c91992 100644 --- a/components/esp32/gdbstub.c +++ b/components/esp32/gdbstub.c @@ -66,7 +66,7 @@ static void ATTR_GDBFN gdbPacketChar(char c) { } //Send a string as part of a packet -static void ATTR_GDBFN gdbPacketStr(char *c) { +static void ATTR_GDBFN gdbPacketStr(const char *c) { while (*c!=0) { gdbPacketChar(*c); c++; diff --git a/components/fatfs/test/test_fatfs_common.c b/components/fatfs/test/test_fatfs_common.c index 592cdfd8f2..7ab7fb2eb1 100644 --- a/components/fatfs/test/test_fatfs_common.c +++ b/components/fatfs/test/test_fatfs_common.c @@ -194,7 +194,7 @@ void test_fatfs_link_rename(const char* filename_prefix) FILE* f = fopen(name_src, "w+"); TEST_ASSERT_NOT_NULL(f); - char* str = "0123456789"; + const char* str = "0123456789"; for (int i = 0; i < 4000; ++i) { TEST_ASSERT_NOT_EQUAL(EOF, fputs(str, f)); } diff --git a/components/newlib/test/test_newlib.c b/components/newlib/test/test_newlib.c index 3627850209..2836fc3d27 100644 --- a/components/newlib/test/test_newlib.c +++ b/components/newlib/test/test_newlib.c @@ -115,7 +115,7 @@ TEST_CASE("test asctime", "[newlib]") TEST_ASSERT_EQUAL_STRING(buf, time_str); } -static bool fn_in_rom(void *fn, char *name) +static bool fn_in_rom(void *fn, const char *name) { const int fnaddr = (int)fn; return (fnaddr >= 0x40000000) && (fnaddr < 0x40070000); diff --git a/components/openssl/library/ssl_lib.c b/components/openssl/library/ssl_lib.c index 363cacdf8d..6fc863aa76 100644 --- a/components/openssl/library/ssl_lib.c +++ b/components/openssl/library/ssl_lib.c @@ -1106,9 +1106,9 @@ const char *SSL_rstate_string_long(SSL *ssl) /** * @brief get SSL statement string */ -char *SSL_state_string(const SSL *ssl) +const char *SSL_state_string(const SSL *ssl) { - char *str = "UNKWN "; + const char *str = "UNKWN "; SSL_ASSERT2(ssl); @@ -1214,9 +1214,9 @@ char *SSL_state_string(const SSL *ssl) /** * @brief get SSL statement long string */ -char *SSL_state_string_long(const SSL *ssl) +const char *SSL_state_string_long(const SSL *ssl) { - char *str = "UNKWN "; + const char *str = "UNKWN "; SSL_ASSERT2(ssl); diff --git a/components/spiffs/test/test_spiffs.c b/components/spiffs/test/test_spiffs.c index fdd3d241a6..3805848b43 100644 --- a/components/spiffs/test/test_spiffs.c +++ b/components/spiffs/test/test_spiffs.c @@ -158,7 +158,7 @@ void test_spiffs_rename(const char* filename_prefix) FILE* f = fopen(name_src, "w+"); TEST_ASSERT_NOT_NULL(f); - char* str = "0123456789"; + const char* str = "0123456789"; for (int i = 0; i < 400; ++i) { TEST_ASSERT_NOT_EQUAL(EOF, fputs(str, f)); } diff --git a/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c b/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c index 17ad81f909..5294c344da 100644 --- a/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c +++ b/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c @@ -85,9 +85,9 @@ static struct gattc_profile_inst gl_profile_tab[PROFILE_NUM] = { }, }; -static char *esp_key_type_to_str(esp_ble_key_type_t key_type) +static const char *esp_key_type_to_str(esp_ble_key_type_t key_type) { - char *key_str = NULL; + const char *key_str = NULL; switch(key_type) { case ESP_LE_KEY_NONE: key_str = "ESP_LE_KEY_NONE"; diff --git a/examples/protocols/http2_request/components/sh2lib/sh2lib.c b/examples/protocols/http2_request/components/sh2lib/sh2lib.c index 3abfc5c5c7..4026db4562 100644 --- a/examples/protocols/http2_request/components/sh2lib/sh2lib.c +++ b/examples/protocols/http2_request/components/sh2lib/sh2lib.c @@ -101,7 +101,7 @@ static ssize_t callback_recv(nghttp2_session *session, uint8_t *buf, return rv; } -char *sh2lib_frame_type_str(int type) +const char *sh2lib_frame_type_str(int type) { switch (type) { case NGHTTP2_HEADERS: diff --git a/examples/protocols/pppos_client/main/pppos_client_main.c b/examples/protocols/pppos_client/main/pppos_client_main.c index 432bd6bc0c..a1dcaf588c 100644 --- a/examples/protocols/pppos_client/main/pppos_client_main.c +++ b/examples/protocols/pppos_client/main/pppos_client_main.c @@ -54,9 +54,9 @@ struct netif ppp_netif; static const char *TAG = "example"; typedef struct { - char *cmd; + const char *cmd; uint16_t cmdSize; - char *cmdResponseOnOk; + const char *cmdResponseOnOk; uint32_t timeoutMs; } GSM_Cmd;