RW612 SDK - MFlash file library not const-correct

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

RW612 SDK - MFlash file library not const-correct

跳至解决方案
3,264 次查看
dmarks_ls
Senior Contributor II

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.

标记 (2)
0 项奖励
回复
1 解答
3,162 次查看
Christine_Li
NXP TechSupport
NXP TechSupport

Hi, @dmarks_ls 

Happy new year!

I have reported this issue to our internal expert team.

And our internal expert team will check and decide whether and how to correct it in our future release.

Thanks for pointing out our non-rigorous.

If there is no other concerns on this case, it will be closed automatically because of no any feedback from you.

Best regards,

Christine.

在原帖中查看解决方案

7 回复数
3,234 次查看
Christine_Li
NXP TechSupport
NXP TechSupport

Hi, @dmarks_ls 

To quick locate the code you mentioned, would you mind let me know your SDK version and which example project are you referring to?

So that I can download the same SDK version and import same example project to locate the issue you mentioned.

 

Best regards,

Christine.

0 项奖励
回复
3,215 次查看
dmarks_ls
Senior Contributor II

For some reason, my attachments did not show up.  Trying again.

Dana M.

0 项奖励
回复
3,220 次查看
dmarks_ls
Senior Contributor II

I'm using the latest SDK (v2.16.1), and use any example that includes the MFlash driver (e.g. "wifi_mqtt").  I've attached my "fixed" version, which simply involves replacing all instances of "char *" with "const char *".

Dana M.

0 项奖励
回复
3,189 次查看
Christine_Li
NXP TechSupport
NXP TechSupport

Hi, @dmarks_ls 

Thanks for your feedback!

I checked the code you mentioned and I found that here it mentioned the struct mflash_file_t should be const, so I agree with your point.

/*! @brief Initializes mflash filesystem and driver. Creates new filesystem unless already in place. */

status_t mflash_init(const mflash_file_t *dir_template, bool init_drv);

I will report this to our internal team and they will decide whether revise the code because as you know this is just a warning.

And also it depends on the compiler, for some strict compiler, it will report this warning.

 

Thanks for pointing out our non-rigorous.

 

Best regards,

Christine.

0 项奖励
回复
3,163 次查看
Christine_Li
NXP TechSupport
NXP TechSupport

Hi, @dmarks_ls 

Happy new year!

I have reported this issue to our internal expert team.

And our internal expert team will check and decide whether and how to correct it in our future release.

Thanks for pointing out our non-rigorous.

If there is no other concerns on this case, it will be closed automatically because of no any feedback from you.

Best regards,

Christine.

2,822 次查看
Christine_Li
NXP TechSupport
NXP TechSupport

Hi, @dmarks_ls 

For your information, our driver owner will add the const specifier for the next release and this will be release 25.03.

 

Best regards,

Christine.

3,237 次查看
Christine_Li
NXP TechSupport
NXP TechSupport

Hi, @dmarks_ls 

I will check this issue and reply to you once have any updates.

 

Best regards,

Christine.

0 项奖励
回复