Skip to content

Commit

Permalink
Avoid conditional branching on uninitialized values
Browse files Browse the repository at this point in the history
C++ initializes members in the order in which they are defined in class. So the
order is important if the members are accessed by other initializers or methods
called from them.

Class BoxLayerWidget:
  _roundRect is initialized based on _layerType through the st() method.

Class Checkbox:
  Arguments of _text constructor depend on _checkAlignment through the
  countTextMinWidth and the checkRect methods.
  • Loading branch information
mymedia2 authored and john-preston committed Apr 14, 2022
1 parent e5d8e54 commit 258cacf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ui/layers/box_layer_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class BoxLayerWidget : public LayerWidget, public BoxContentDelegate {

const style::Box *_st = nullptr;
not_null<LayerStackWidget*> _layer;
bool _layerType = false;
int _fullHeight = 0;

bool _noContentMargin = false;
Expand All @@ -140,7 +141,6 @@ class BoxLayerWidget : public LayerWidget, public BoxContentDelegate {
rpl::variable<QString> _additionalTitle;
int _titleLeft = 0;
int _titleTop = 0;
bool _layerType = false;
bool _closeByOutsideClick = true;

std::vector<object_ptr<RoundButton>> _buttons;
Expand Down
2 changes: 1 addition & 1 deletion ui/widgets/checkbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ class Checkbox : public RippleButton {
rpl::event_stream<bool> _checkedChanges;
QPixmap _checkCache;

Text::String _text;
style::align _checkAlignment = style::al_left;
Text::String _text;
int _allowTextLines = 1;
bool _textBreakEverywhere = false;

Expand Down

0 comments on commit 258cacf

Please sign in to comment.