Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Superfluous #ifdef LV_FS_WIN32_PATH in lv_fs_win32.c? #7603

Open
vwheeler63 opened this issue Jan 14, 2025 · 1 comment · May be fixed by #7608
Open

Superfluous #ifdef LV_FS_WIN32_PATH in lv_fs_win32.c? #7603

vwheeler63 opened this issue Jan 14, 2025 · 1 comment · May be fixed by #7608

Comments

@vwheeler63
Copy link
Contributor

vwheeler63 commented Jan 14, 2025

Introduce the problem

In having a look at issue #7601 a few minutes ago, I (once again) looked into how the LV_FS_WIN32_PATH macro is used, and I noticed an inconsistency in how it is used in lv_fs_win32.c. On line 363 in the fs_dir_open() function:

#ifdef LV_FS_WIN32_PATH
    lv_snprintf(buf, sizeof(buf), LV_FS_WIN32_PATH "%s\\*", path);
#else
    lv_snprintf(buf, sizeof(buf), "%s\\*", path);
#endif

but on line 226 in fs_open():

    lv_snprintf(buf, sizeof(buf), LV_FS_WIN32_PATH "%s", path);

and there is no protective #ifdef.

At first, I thought the fault was on line 226, and to prove it, I undefined LV_FS_WIN32_PATH in lv_conf.h and tried to compile lv_fs_win32.c. To my surprise, it compiled without errors. And then I realized: lv_conf_internal.h supplies it with a valid default value of an empty string "". That it is not possible for an end user (programmer) to accidentally not define LV_FS_WIN32_PATH.

So it now appears to me that the first use of it on line 363 is in fact "the inconsistency" -- that no alternate compilation directive should be used. Reason this is important: because it can mis-direct developers using LVGL to thinking that LV_FS_WIN32_PATH can somehow not be defined when that code is compiled. (Note that the entire file is protected with #if LV_USE_FS_WIN32 != '\0'.)

As a side note (different topic): #if LV_USE_FS_WIN32 != '\0' should probably be #if LV_USE_FS_WIN32 != 0. While I am aware that \0 also resolved to 0, there is no reason it should be represented as a char data type.

Proposal

Line 363 be changed to:

    lv_snprintf(buf, sizeof(buf), LV_FS_WIN32_PATH "%s\\*", path);
@kisvegabor
Copy link
Member

I agree with both!

#if LV_USE_FS_WIN32 != '\0'

Probably is was confuse with LV_FS_WIN32_LETTER where we use \0 to indicate that the value is a char.

vwheeler63 added a commit to vwheeler63/lvgl that referenced this issue Jan 15, 2025
...and clean up `#if LV_USE_...` expression in 2 files in the `fsdrv`
directory.

Resolves lvgl#7603
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants