Prechádzať zdrojové kódy

Merge branch 'bugfix/storage_wformat' into 'master'

storage: fix and re-enable -Wformat warnings

See merge request espressif/esp-idf!20486
Ivan Grokhotkov 3 rokov pred
rodič
commit
11ec9d392d

+ 0 - 2
components/fatfs/CMakeLists.txt

@@ -14,5 +14,3 @@ idf_component_register(SRCS ${srcs}
                        REQUIRES wear_levelling sdmmc
                        PRIV_REQUIRES vfs
                       )
-
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 2 - 2
components/fatfs/vfs/vfs_fat.c

@@ -577,9 +577,9 @@ static off_t vfs_fat_lseek(void* ctx, int fd, off_t offset, int mode)
     }
 
 #if FF_FS_EXFAT
-    ESP_LOGD(TAG, "%s: offset=%ld, filesize:=%lld", __func__, new_pos, f_size(file));
+    ESP_LOGD(TAG, "%s: offset=%ld, filesize:=%" PRIu64, __func__, new_pos, f_size(file));
 #else
-    ESP_LOGD(TAG, "%s: offset=%ld, filesize:=%d", __func__, new_pos, f_size(file));
+    ESP_LOGD(TAG, "%s: offset=%ld, filesize:=%" PRIu32, __func__, new_pos, f_size(file));
 #endif
     FRESULT res = f_lseek(file, new_pos);
     if (res != FR_OK) {

+ 0 - 2
components/spiffs/CMakeLists.txt

@@ -21,5 +21,3 @@ idf_component_register(SRCS ${srcs}
 if(CMAKE_C_COMPILER_ID MATCHES "GNU")
     set_source_files_properties(spiffs/src/spiffs_nucleus.c PROPERTIES COMPILE_FLAGS -Wno-stringop-truncation)
 endif()
-
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 6 - 6
components/spiffs/esp_spiffs.c

@@ -148,7 +148,7 @@ static esp_err_t esp_spiffs_init(const esp_vfs_spiffs_conf_t* conf)
     uint32_t flash_page_size = g_rom_flashchip.page_size;
     uint32_t log_page_size = CONFIG_SPIFFS_PAGE_SIZE;
     if (log_page_size % flash_page_size != 0) {
-        ESP_LOGE(TAG, "SPIFFS_PAGE_SIZE is not multiple of flash chip page size (%d)",
+        ESP_LOGE(TAG, "SPIFFS_PAGE_SIZE is not multiple of flash chip page size (%" PRIu32 ")",
                 flash_page_size);
         return ESP_ERR_INVALID_ARG;
     }
@@ -268,11 +268,11 @@ static esp_err_t esp_spiffs_init(const esp_vfs_spiffs_conf_t* conf)
                             efs->cache, efs->cache_sz, spiffs_api_check);
 
     if (conf->format_if_mount_failed && res != SPIFFS_OK) {
-        ESP_LOGW(TAG, "mount failed, %i. formatting...", SPIFFS_errno(efs->fs));
+        ESP_LOGW(TAG, "mount failed, %" PRId32 ". formatting...", SPIFFS_errno(efs->fs));
         SPIFFS_clearerr(efs->fs);
         res = SPIFFS_format(efs->fs);
         if (res != SPIFFS_OK) {
-            ESP_LOGE(TAG, "format failed, %i", SPIFFS_errno(efs->fs));
+            ESP_LOGE(TAG, "format failed, %" PRId32, SPIFFS_errno(efs->fs));
             SPIFFS_clearerr(efs->fs);
             esp_spiffs_free(&efs);
             return ESP_FAIL;
@@ -281,7 +281,7 @@ static esp_err_t esp_spiffs_init(const esp_vfs_spiffs_conf_t* conf)
                             efs->cache, efs->cache_sz, spiffs_api_check);
     }
     if (res != SPIFFS_OK) {
-        ESP_LOGE(TAG, "mount failed, %i", SPIFFS_errno(efs->fs));
+        ESP_LOGE(TAG, "mount failed, %" PRId32, SPIFFS_errno(efs->fs));
         SPIFFS_clearerr(efs->fs);
         esp_spiffs_free(&efs);
         return ESP_FAIL;
@@ -354,7 +354,7 @@ esp_err_t esp_spiffs_format(const char* partition_label)
 
     s32_t res = SPIFFS_format(_efs[index]->fs);
     if (res != SPIFFS_OK) {
-        ESP_LOGE(TAG, "format failed, %i", SPIFFS_errno(_efs[index]->fs));
+        ESP_LOGE(TAG, "format failed, %" PRId32, SPIFFS_errno(_efs[index]->fs));
         SPIFFS_clearerr(_efs[index]->fs);
         /* If the partition was previously mounted, but format failed, don't
          * try to mount the partition back (it will probably fail). On the
@@ -371,7 +371,7 @@ esp_err_t esp_spiffs_format(const char* partition_label)
                             _efs[index]->fds, _efs[index]->fds_sz, _efs[index]->cache,
                             _efs[index]->cache_sz, spiffs_api_check);
         if (res != SPIFFS_OK) {
-            ESP_LOGE(TAG, "mount failed, %i", SPIFFS_errno(_efs[index]->fs));
+            ESP_LOGE(TAG, "mount failed, %" PRId32, SPIFFS_errno(_efs[index]->fs));
             SPIFFS_clearerr(_efs[index]->fs);
             return ESP_FAIL;
         }

+ 5 - 5
components/spiffs/spiffs_api.c

@@ -27,7 +27,7 @@ s32_t spiffs_api_read(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *dst)
     esp_err_t err = esp_partition_read(((esp_spiffs_t *)(fs->user_data))->partition,
                                         addr, dst, size);
     if (unlikely(err)) {
-        ESP_LOGE(TAG, "failed to read addr %08x, size %08x, err %d", addr, size, err);
+        ESP_LOGE(TAG, "failed to read addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err);
         return -1;
     }
     return 0;
@@ -38,7 +38,7 @@ s32_t spiffs_api_write(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *src)
     esp_err_t err = esp_partition_write(((esp_spiffs_t *)(fs->user_data))->partition,
                                         addr, src, size);
     if (unlikely(err)) {
-        ESP_LOGE(TAG, "failed to write addr %08x, size %08x, err %d", addr, size, err);
+        ESP_LOGE(TAG, "failed to write addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err);
         return -1;
     }
     return 0;
@@ -49,7 +49,7 @@ s32_t spiffs_api_erase(spiffs *fs, uint32_t addr, uint32_t size)
     esp_err_t err = esp_partition_erase_range(((esp_spiffs_t *)(fs->user_data))->partition,
                                         addr, size);
     if (err) {
-        ESP_LOGE(TAG, "failed to erase addr %08x, size %08x, err %d", addr, size, err);
+        ESP_LOGE(TAG, "failed to erase addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err);
         return -1;
     }
     return 0;
@@ -75,10 +75,10 @@ void spiffs_api_check(spiffs *fs, spiffs_check_type type,
     };
 
     if (report != SPIFFS_CHECK_PROGRESS) {
-        ESP_LOGE(TAG, "CHECK: type:%s, report:%s, %x:%x", spiffs_check_type_str[type],
+        ESP_LOGE(TAG, "CHECK: type:%s, report:%s, %" PRIx32 ":%" PRIx32, spiffs_check_type_str[type],
                               spiffs_check_report_str[report], arg1, arg2);
     } else {
-        ESP_LOGV(TAG, "CHECK PROGRESS: report:%s, %x:%x",
+        ESP_LOGV(TAG, "CHECK PROGRESS: report:%s, %" PRIx32 ":%" PRIx32,
                               spiffs_check_report_str[report], arg1, arg2);
     }
 }

+ 0 - 2
components/vfs/CMakeLists.txt

@@ -23,5 +23,3 @@ endif()
 # Some newlib syscalls are implemented in vfs.c, make sure these are always
 # seen by the linker
 target_link_libraries(${COMPONENT_LIB} INTERFACE "-u vfs_include_syscalls_impl")
-
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 0 - 1
components/vfs/test/CMakeLists.txt

@@ -1,4 +1,3 @@
 idf_component_register(SRC_DIRS "."
                        PRIV_INCLUDE_DIRS .
                        PRIV_REQUIRES cmock test_utils vfs fatfs spiffs)
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 1 - 1
components/vfs/vfs.c

@@ -1047,7 +1047,7 @@ int esp_vfs_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds
              * 1 tick before triggering a timeout. Thus, we need to pass 2 ticks as a timeout
              * to `xSemaphoreTake`. */
             ticks_to_wait = ((timeout_ms + portTICK_PERIOD_MS - 1) / portTICK_PERIOD_MS) + 1;
-            ESP_LOGD(TAG, "timeout is %dms", timeout_ms);
+            ESP_LOGD(TAG, "timeout is %" PRIu32 "ms", timeout_ms);
         }
         ESP_LOGD(TAG, "waiting without calling socket_select");
         xSemaphoreTake(sel_sem.sem, ticks_to_wait);

+ 1 - 1
components/vfs/vfs_semihost.c

@@ -195,7 +195,7 @@ static int vfs_semihost_mkdir(void* ctx, const char* path, mode_t mode)
         return -1;
     }
 
-    ESP_LOGV(TAG, "%s: '%s 0x%x'", __func__, path, mode);
+    ESP_LOGV(TAG, "%s: '%s 0x%x'", __func__, path, (unsigned) mode);
     return semihosting_mkdir(path, mode);
 }
 

+ 0 - 1
examples/storage/ext_flash_fatfs/main/CMakeLists.txt

@@ -1,2 +1 @@
 idf_component_register(SRCS "ext_flash_fatfs_example_main.c")
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 5 - 5
examples/storage/ext_flash_fatfs/main/ext_flash_fatfs_example_main.c

@@ -83,7 +83,7 @@ void app_main(void)
     // Print FAT FS size information
     uint64_t bytes_total, bytes_free;
     esp_vfs_fat_info(base_path, &bytes_total, &bytes_free);
-    ESP_LOGI(TAG, "FAT FS: %lld kB total, %lld kB free", bytes_total / 1024, bytes_free / 1024);
+    ESP_LOGI(TAG, "FAT FS: %" PRIu64 " kB total, %" PRIu64 " kB free", bytes_total / 1024, bytes_free / 1024);
 
     // Create a file in FAT FS
     ESP_LOGI(TAG, "Opening file");
@@ -157,20 +157,20 @@ static esp_flash_t* example_init_ext_flash(void)
     // Print out the ID and size
     uint32_t id;
     ESP_ERROR_CHECK(esp_flash_read_id(ext_flash, &id));
-    ESP_LOGI(TAG, "Initialized external Flash, size=%d KB, ID=0x%x", ext_flash->size / 1024, id);
+    ESP_LOGI(TAG, "Initialized external Flash, size=%" PRIu32 " KB, ID=0x%" PRIx32, ext_flash->size / 1024, id);
 
     return ext_flash;
 }
 
 static const esp_partition_t* example_add_partition(esp_flash_t* ext_flash, const char* partition_label)
 {
-    ESP_LOGI(TAG, "Adding external Flash as a partition, label=\"%s\", size=%d KB", partition_label, ext_flash->size / 1024);
+    ESP_LOGI(TAG, "Adding external Flash as a partition, label=\"%s\", size=%" PRIu32 " KB", partition_label, ext_flash->size / 1024);
     const esp_partition_t* fat_partition;
     const size_t offset = 0;
     ESP_ERROR_CHECK(esp_partition_register_external(ext_flash, offset, ext_flash->size, partition_label, ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, &fat_partition));
 
     // Erase space of partition on the external flash chip
-    ESP_LOGI(TAG, "Erasing partition range, offset=%d size=%d KB", offset, ext_flash->size / 1024);
+    ESP_LOGI(TAG, "Erasing partition range, offset=%u size=%" PRIu32 " KB", offset, ext_flash->size / 1024);
     ESP_ERROR_CHECK(esp_partition_erase_range(fat_partition, offset, ext_flash->size));
     return fat_partition;
 }
@@ -182,7 +182,7 @@ static void example_list_data_partitions(void)
 
     for (; it != NULL; it = esp_partition_next(it)) {
         const esp_partition_t *part = esp_partition_get(it);
-        ESP_LOGI(TAG, "- partition '%s', subtype %d, offset 0x%x, size %d kB",
+        ESP_LOGI(TAG, "- partition '%s', subtype %d, offset 0x%" PRIx32 ", size %" PRIu32 " kB",
         part->label, part->subtype, part->address, part->size / 1024);
     }
 

+ 0 - 1
examples/storage/nvs_rw_blob/main/CMakeLists.txt

@@ -1,3 +1,2 @@
 idf_component_register(SRCS "nvs_blob_example_main.c"
                     INCLUDE_DIRS ".")
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 3 - 2
examples/storage/nvs_rw_blob/main/nvs_blob_example_main.c

@@ -10,6 +10,7 @@
    CONDITIONS OF ANY KIND, either express or implied.
 */
 #include <stdio.h>
+#include <inttypes.h>
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "esp_system.h"
@@ -127,7 +128,7 @@ esp_err_t print_what_saved(void)
     int32_t restart_counter = 0; // value will default to 0, if not set yet in NVS
     err = nvs_get_i32(my_handle, "restart_conter", &restart_counter);
     if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) return err;
-    printf("Restart counter = %d\n", restart_counter);
+    printf("Restart counter = %" PRIu32 "\n", restart_counter);
 
     // Read run time blob
     size_t required_size = 0;  // value will default to 0, if not set yet in NVS
@@ -145,7 +146,7 @@ esp_err_t print_what_saved(void)
             return err;
         }
         for (int i = 0; i < required_size / sizeof(uint32_t); i++) {
-            printf("%d: %d\n", i + 1, run_time[i]);
+            printf("%d: %" PRIu32 "\n", i + 1, run_time[i]);
         }
         free(run_time);
     }

+ 0 - 1
examples/storage/nvs_rw_value/main/CMakeLists.txt

@@ -1,3 +1,2 @@
 idf_component_register(SRCS "nvs_value_example_main.c"
                     INCLUDE_DIRS ".")
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 2 - 1
examples/storage/nvs_rw_value/main/nvs_value_example_main.c

@@ -10,6 +10,7 @@
    CONDITIONS OF ANY KIND, either express or implied.
 */
 #include <stdio.h>
+#include <inttypes.h>
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "esp_system.h"
@@ -45,7 +46,7 @@ void app_main(void)
         switch (err) {
             case ESP_OK:
                 printf("Done\n");
-                printf("Restart counter = %d\n", restart_counter);
+                printf("Restart counter = %" PRIu32 "\n", restart_counter);
                 break;
             case ESP_ERR_NVS_NOT_FOUND:
                 printf("The value is not initialized yet!\n");

+ 0 - 1
examples/storage/nvs_rw_value_cxx/main/CMakeLists.txt

@@ -1,3 +1,2 @@
 idf_component_register(SRCS "nvs_value_example_main.cpp"
                     INCLUDE_DIRS ".")
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 2 - 1
examples/storage/nvs_rw_value_cxx/main/nvs_value_example_main.cpp

@@ -10,6 +10,7 @@
    CONDITIONS OF ANY KIND, either express or implied.
 */
 #include <stdio.h>
+#include <inttypes.h>
 #include "nvs_flash.h"
 #include "nvs.h"
 #include "nvs_handle.hpp"
@@ -47,7 +48,7 @@ extern "C" void app_main(void)
         switch (err) {
             case ESP_OK:
                 printf("Done\n");
-                printf("Restart counter = %d\n", restart_counter);
+                printf("Restart counter = %" PRIu32 "\n", restart_counter);
                 break;
             case ESP_ERR_NVS_NOT_FOUND:
                 printf("The value is not initialized yet!\n");

+ 0 - 1
examples/storage/partition_api/partition_find/main/CMakeLists.txt

@@ -1,4 +1,3 @@
 idf_component_register(SRCS "main.c"
                     INCLUDE_DIRS "."
                     EMBED_TXTFILES ../partitions_example.csv)
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 3 - 3
examples/storage/partition_api/partition_find/main/main.c

@@ -51,7 +51,7 @@ static void find_partition(esp_partition_type_t type, esp_partition_subtype_t su
     const esp_partition_t * part  = esp_partition_find_first(type, subtype, name);
 
     if (part != NULL) {
-        ESP_LOGI(TAG, "\tfound partition '%s' at offset 0x%x with size 0x%x", part->label, part->address, part->size);
+        ESP_LOGI(TAG, "\tfound partition '%s' at offset 0x%" PRIx32 " with size 0x%" PRIx32, part->label, part->address, part->size);
     } else {
         ESP_LOGE(TAG, "\tpartition not found!");
     }
@@ -103,7 +103,7 @@ void app_main(void)
     // label is found. Verify if its the same instance as the one found before.
     for (; it != NULL; it = esp_partition_next(it)) {
         const esp_partition_t *part = esp_partition_get(it);
-        ESP_LOGI(TAG, "\tfound partition '%s' at offset 0x%x with size 0x%x", part->label, part->address, part->size);
+        ESP_LOGI(TAG, "\tfound partition '%s' at offset 0x%" PRIx32 " with size 0x%" PRIx32, part->label, part->address, part->size);
     }
     // Release the partition iterator to release memory allocated for it
     esp_partition_iterator_release(it);
@@ -115,7 +115,7 @@ void app_main(void)
     // label is found. Verify if its the same instance as the one found before.
     for (; it != NULL; it = esp_partition_next(it)) {
         const esp_partition_t *part = esp_partition_get(it);
-        ESP_LOGI(TAG, "\tfound partition '%s' at offset 0x%x with size 0x%x", part->label, part->address, part->size);
+        ESP_LOGI(TAG, "\tfound partition '%s' at offset 0x%" PRIx32 " with size 0x%" PRIx32, part->label, part->address, part->size);
     }
 
     // Release the partition iterator to release memory allocated for it