The API for the MFlash file system library (mflash_file.h) is not const-correct, in that the filename parameters in the mflash_file_t struct and mflash_file_save() and mflash_file_mmap() functions are not declared "const char *" but instead "char *".
typedef struct
{
char *path;
uint32_t max_size;
} mflash_file_t;
status_t mflash_file_save(char *path, uint8_t *data, uint32_t size);
status_t mflash_file_mmap(char *path, uint8_t **pdata, uint32_t *psize);
This throws a warning when declaring a table of mflash_file_t structs in a C++ translation unit:
C:\NXP\workspace\[redacted]\config/kvstore_config.h:50:28: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
50 | #define KVSTORE_FILE_PATH ("/kvstore")
| ~^~~~~~~~~~~
../source/program.cpp:47:15: note: in expansion of macro 'KVSTORE_FILE_PATH'
47 | { .path = KVSTORE_FILE_PATH, .max_size = 3000 },
| ^~~~~~~~~~~~~~~~~
String literals should never be treated as writable; in some cases, this can cause excessive memory usage if strings are allocated to RAM instead of flash because they are declared writable.
Please fix the API for these functions. Also, please add missing extern "C" { } declarations for this and other header files; I have to place the #include <mflash_file.h> declaration inside an extern "C" { } declaration in order for my application to link correctly.
Dana M.