Fix accepted chars issue on big endian systems #5479
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
lv_conf_template.h
run lv_conf_internal_gen.py and update Kconfig.scripts/code-format.py
(astyle needs to be installed) and follow the Code Conventions