Skip to content

Conversation

bearzly
Copy link
Contributor

@bearzly bearzly commented Sep 5, 2025

The cursor_ variable was being default initialized, which causes undefined behaviour when accessing properties in
ScreenInteractive::Draw. This caused a crash when running with UBSAN.

ftxui/src/ftxui/component/screen_interactive.cpp:852:17: runtime error:
load of value 4195502944, which is not a valid value for type 'Shape'

This change causes cursor_ to be value initialized so that its members will be initialized to 0.

@ArthurSonzogni
Copy link
Owner

Thanks! This is greatly appreciated. Maybe I should run the fuzzers with UBSAN too instead of only ASAN.

Could we instead initialize Screen::Cursor::shape_ where is is declared?

class Screen {
  ...
  struct Cursor {
    int x = 0;
    int y = 0;

    enum Shape {
      Hidden = 0,
      BlockBlinking = 1,
      Block = 2,
      UnderlineBlinking = 3,
      Underline = 4,
      BarBlinking = 5,
      Bar = 6,
    };
-   Shape shape;
+   Shape shape = Hidden;
  };
  ...
}

The cursor_ variable was being default initialized, which causes
undefined behaviour when accessing properties in
ScreenInteractive::Draw. This caused a crash when running with UBSAN.

```
ftxui/src/ftxui/component/screen_interactive.cpp:852:17: runtime error:
load of value 4195502944, which is not a valid value for type 'Shape'
```

This change causes the shape variable to be explicitly initialized,
similar to the x and y members.
@bearzly
Copy link
Contributor Author

bearzly commented Sep 8, 2025

Done, tested that this also fixes the issue.

Copy link
Owner

@ArthurSonzogni ArthurSonzogni left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM!

@ArthurSonzogni ArthurSonzogni merged commit f21fcc1 into ArthurSonzogni:main Sep 9, 2025
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.

2 participants