summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2020-08-29 13:09:08 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-30 10:31:04 +0200
commitc9bafa9467e2101cf49b0711d0bf13b6a1d8bd86 (patch)
tree6a2dfc9909ef3e1556a0576ef54c9e0cb3a3c3f4
parent61521315ed41e2659ec9252a9e636f487ab1e297 (diff)
downloadserenity-c9bafa9467e2101cf49b0711d0bf13b6a1d8bd86.zip
FontEditor: Cannot take reference to local lambda
Under the hood, a lambda is just a struct full of pointers/references/copies and whatever else the compiler deems necessary. In the case of 'update_demo', the struct lives on the stack frame of FontEditorWidget::FontEditorWidget(). Hence it is still alive when it's called during the constructor. However, when 'fixed_width_checkbox.on_checked' fires, that stack frame is no longer alive, and thus the *reference* to the (struct of) the lambda is invalid\! This meant that 'update_demo' silently read invalid data, tried to call '.update()' on some innocent arbitrary memory address, and it crashed somewhere unrelated. Passing 'update_demo' by value (like with all the other event handlers) fixes this issue. Note that this solution only works because 'update_demo' itself has no state; otherwise the various copies of 'update_demo' might notice that they are, in fact, independent copies of the original lambda. But that doesn't matter here.
-rw-r--r--Applications/FontEditor/FontEditor.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/Applications/FontEditor/FontEditor.cpp b/Applications/FontEditor/FontEditor.cpp
index a7d32a4706..0d8e68340d 100644
--- a/Applications/FontEditor/FontEditor.cpp
+++ b/Applications/FontEditor/FontEditor.cpp
@@ -263,7 +263,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
info_label.set_text(builder.to_string());
};
- fixed_width_checkbox.on_checked = [&](bool checked) {
+ fixed_width_checkbox.on_checked = [&, update_demo](bool checked) {
m_edited_font->set_fixed_width(checked);
glyph_width_spinbox.set_enabled(!m_edited_font->is_fixed_width());
glyph_width_spinbox.set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph()));