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 TLSF returning the wrong pointer when the requested size is too large #3325

Merged
merged 2 commits into from May 14, 2022

Conversation

embeddedt
Copy link
Member

Description of the feature or fix

Checkpoints

  • Follow the styling guide
  • Run code-format.py from the scripts folder. astyle needs to be installed.
  • Update the documentation

@embeddedt
Copy link
Member Author

I have realized that the assert statements are an issue in general, because I actually want the test to pass if an assertion happens, and fail otherwise (the opposite of the default logic). The cleanest solution would be if the testing framework had a feature built-in to invert the pass/fail logic, but Unity does not appear to have that. I'll need to think of an alternate solution if we want a CI test for #3324.

@kisvegabor
Copy link
Member

I believe the same should be tested with lv_mem_alloc/free/realloc where we can see the returned value and decide to fail or pass.

  void * buf = lv_mem_alloc(20);
  printf("%p\n", buf);
  buf = lv_mem_realloc(buf, LV_MEM_SIZE + 16384);
  printf("%p\n", buf);

Results in

0x56222ce78510
0x56222ce78510

Anyway we can fix this issue by updating lv_tlsf.c. That's we have a copy of these files and not submodules.

@embeddedt embeddedt marked this pull request as ready for review May 13, 2022 01:47
@embeddedt embeddedt changed the title Test improvements Fix TLSF returning the wrong pointer when the requested size is too large May 13, 2022
@embeddedt
Copy link
Member Author

embeddedt commented May 13, 2022

I found the issue. adjust_request_size in TLSF returns 0 if the provided size is larger than the maximum block size, and that causes lv_tlsf_realloc to think the allocation doesn't need resizing just below here.

What do you think of my fix?

EDIT: It seems that the issue was mentioned upstream but never addressed. mattconte/tlsf#22

@kisvegabor
Copy link
Member

LGTM!

It seems that the issue was mentioned upstream but never addressed. mattconte/tlsf#22

I wanted to suggest reporting it in the upstream.

@kisvegabor kisvegabor merged commit 2148ed9 into master May 14, 2022
@kisvegabor kisvegabor deleted the test/3324 branch May 14, 2022 20:04
somebodyLi pushed a commit to somebodyLi/lvgl that referenced this pull request Nov 8, 2022
…e is too large (lvgl#3325)

* test(mem) add test for lvgl#3324

* fix(tlsf) don't return the same pointer if the requested size is too large
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.

None yet

2 participants