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

Fix accepted chars issue on big endian systems #5479

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

jimbom
Copy link
Contributor

@jimbom jimbom commented Jan 25, 2024

Fixes: #5454

Description of the feature or fix

When adding accepted chars to a textarea, no characters are accepted on big-endian systems.

In the function lv_textarea_add_char, the character to add is taken as a uint32_t parameter, called c. When encoded, this is casted to a char pointer. On big endian systems this pointer will point to the wrong byte in the uint32_t, and the wrong encoded character, c_uni, will be used when checking for valid characters.

The root of the issue is the following line:
uint32_t c_uni = _lv_txt_encoded_next((const char *)&c, NULL);

The reference to uint32_t c should not be casted to a char pointer. To change this, I believe require pretty big changes to the code, since _lv_txt_encoded_next requires a const char *.

The solution/workaround made here is to swap the byte order of, c in case of big-endian system. But if lv_textarea_add_char is called from lv_textarea_add_text, the byte order of c is already correct, so then the bytes order shall not be swapped. Here we assume that the byte order shall be swapped if the most significant byte of c is zero. This worked in my case but will not give the correct value of c_uni if c is a 4 byte code. However, since I believe accepted characters will always be a char, I think this will never be an issue.

Notes

@jimbom jimbom force-pushed the feature/accepted-chars-issue branch 3 times, most recently from f7f0579 to 3390ecf Compare January 25, 2024 07:50
@jimbom jimbom force-pushed the feature/accepted-chars-issue branch from 3390ecf to eb3fa3f Compare January 25, 2024 07:52
Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! it's great that v9 is tested on a Big endian machine too.

src/widgets/textarea/lv_textarea.c Outdated Show resolved Hide resolved
jimbom and others added 2 commits January 25, 2024 10:16
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
@kisvegabor
Copy link
Member

Thank you! 👏

@kisvegabor kisvegabor merged commit 65af3d7 into lvgl:master Jan 25, 2024
16 checks passed
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 this pull request may close these issues.

Text area accepted chars not working on big endian system
2 participants