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

Memory corruption or problem with multiline strings in SPI Memory Manager #180

Open
nuschpl opened this issue Mar 10, 2024 · 2 comments
Open
Labels
app:spi_mem_mgr bug Something isn't working

Comments

@nuschpl
Copy link

nuschpl commented Mar 10, 2024

Probably picture will be worth more than hundred words so I'm attaching:
obraz
The issue I'm reporting here is not SPI itself related only the GUI part which gets broken in this specific case.
Namely the string Vendor id: 0x20 which should got split into two lines:

  • Vendor id:
  • 0x20
    Actually get splits into 3 lines:
  • Vendor
  • i-
  • d: 0x20

So I'm betting it somehow related to multiline splitting or just memory corruption.
The code printing it is:

 furi_string_printf(str, "Vendor\nid: 0x%02X", spi_mem_chip_get_vendor_id(app->chip_info));
    widget_add_string_multiline_element(
        app->widget, 16, 44, AlignCenter, AlignBottom, FontSecondary, furi_string_get_cstr(str));
    furi_string_printf(str, "Type\nid: 0x%02X", spi_mem_chip_get_type_id(app->chip_info));
    widget_add_string_multiline_element(
        app->widget, 64, 44, AlignCenter, AlignBottom, FontSecondary, furi_string_get_cstr(str));
    furi_string_printf(str, "Capacity\nid: 0x%02X", spi_mem_chip_get_capacity_id(app->chip_info));
    widget_add_string_multiline_element(
        app->widget, 110, 44, AlignCenter, AlignBottom, FontSecondary, furi_string_get_cstr(str));

I've tried to dig into the code and guessing that this is something related to:
function elements_multiline_text_aligned and its subsequent call to:
size_t chars_fit = elements_get_max_chars_to_fit(canvas, horizontal, start, x); and
line = furi_string_alloc_printf("%.*s-\n", chars_fit, start); where the dash char is added. But I'm unable to quickly determine if this is bug in flipper GUI logic or in the way fapp is using those GUI calls.

@skotopes
Copy link
Member

it's not memory corruption, but incorrect text overflow handling

@nuschpl
Copy link
Author

nuschpl commented Mar 12, 2024

Yes, I've realized that in the middle of writing avove with function widget_add_string_multiline_element being good starting candidate. Maybe someone familiar with how this overflow is supposed to work can point to specific logic which might be te cause here.

@hedger hedger added app:spi_mem_mgr bug Something isn't working labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app:spi_mem_mgr bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants