|
commit 6f36a6362982b08574e27a61d9c8716fe5aac8a8
Author: Matthias Melcher <github@matthiasm.com>
AuthorDate: Thu Nov 24 11:39:20 2022 +0100
Commit: Matthias Melcher <github@matthiasm.com>
CommitDate: Thu Nov 24 11:39:29 2022 +0100
Fixes some FLUID bugs
Fl_Flex would not change type when it had no children.
Function evaluation could read past string end.
Fl_Window_Type would not initialise all member variables.
fluid/Fl_Group_Type.cxx | 48 ++++++++++++++++++++++++-----------------------
fluid/Fl_Window_Type.h | 13 ++++++++++++-
fluid/Shortcut_Button.cxx | 5 +++--
3 files changed, 40 insertions(+), 26 deletions(-)
diff --git fluid/Fl_Group_Type.cxx fluid/Fl_Group_Type.cxx
index d83d7fa..44b83e8 100644
--- fluid/Fl_Group_Type.cxx
+++ fluid/Fl_Group_Type.cxx
@@ -315,30 +315,32 @@ void Fl_Flex_Type::remove_child(Fl_Type* a) {
// We need to relayout existing children.
void Fl_Flex_Type::change_subtype_to(int n) {
Fl_Flex* f = (Fl_Flex*)o;
- int nc = f->children();
- if (f->type()==n || nc==0) return;
+ if (f->type()==n) return;
- int dw = Fl::box_dw(f->box());
- int dh = Fl::box_dh(f->box());
- int lm, tm, rm, bm;
- f->margins(&lm, &tm, &rm, &bm);
- int gap = f->gap();
- int fw = f->w()-dw-lm-rm-(nc*gap);
- if (fw<=nc) fw = nc; // avoid division by zero
- int fh = f->h()-dh-tm-bm-(nc*gap);
- if (fh<=nc) fh = nc; // avoid division by zero
-
- if (f->type()==Fl_Flex::HORIZONTAL && n==Fl_Flex::VERTICAL) {
- float scl = (float)fh/(float)fw;
- for (int i=0; i<nc; i++) {
- Fl_Widget* c = f->child(i);
- c->size(f->w(), (int)(c->w()*scl));
- }
- } else if (f->type()==Fl_Flex::VERTICAL && n==Fl_Flex::HORIZONTAL) {
- float scl = (float)fw/(float)fh;
- for (int i=0; i<nc; i++) {
- Fl_Widget* c = f->child(i);
- c->size((int)(c->h()*scl), f->h());
+ int nc = f->children();
+ if (nc > 0) {
+ int dw = Fl::box_dw(f->box());
+ int dh = Fl::box_dh(f->box());
+ int lm, tm, rm, bm;
+ f->margins(&lm, &tm, &rm, &bm);
+ int gap = f->gap();
+ int fw = f->w()-dw-lm-rm-(nc*gap);
+ if (fw<=nc) fw = nc; // avoid division by zero
+ int fh = f->h()-dh-tm-bm-(nc*gap);
+ if (fh<=nc) fh = nc; // avoid division by zero
+
+ if (f->type()==Fl_Flex::HORIZONTAL && n==Fl_Flex::VERTICAL) {
+ float scl = (float)fh/(float)fw;
+ for (int i=0; i<nc; i++) {
+ Fl_Widget* c = f->child(i);
+ c->size(f->w(), (int)(c->w()*scl));
+ }
+ } else if (f->type()==Fl_Flex::VERTICAL && n==Fl_Flex::HORIZONTAL) {
+ float scl = (float)fw/(float)fh;
+ for (int i=0; i<nc; i++) {
+ Fl_Widget* c = f->child(i);
+ c->size((int)(c->h()*scl), f->h());
+ }
}
}
f->type(n);
diff --git fluid/Fl_Window_Type.h fluid/Fl_Window_Type.h
index 41cf73f..05a2777 100644
--- fluid/Fl_Window_Type.h
+++ fluid/Fl_Window_Type.h
@@ -67,7 +67,18 @@ protected:
public:
- Fl_Window_Type() { drag = dx = dy = 0; sr_min_w = sr_min_h = sr_max_w = sr_max_h = 0; }
+ Fl_Window_Type() :
+ mx(0), my(0),
+ x1(0), y1(0),
+ bx(0), by(0), br(0), bt(0),
+ sx(0), sy(0), sr(0), st(0),
+ dx(0), dy(0),
+ drag(0),
+ numselected(0),
+ recalc(0),
+ modal(0), non_modal(0),
+ sr_min_w(0), sr_min_h(0), sr_max_w(0), sr_max_h(0)
+ { }
uchar modal, non_modal;
Fl_Type *make(Strategy strategy);
diff --git fluid/Shortcut_Button.cxx fluid/Shortcut_Button.cxx
index 517eee6..9c64b76 100644
--- fluid/Shortcut_Button.cxx
+++ fluid/Shortcut_Button.cxx
@@ -283,14 +283,15 @@ int Fluid_Coord_Input::eval(uchar *&s, int prio) const {
} else {
return v; // syntax error
}
- c = *s++;
+ c = *s;
+ if (c) s++;
}
return v;
}
/**
Evaluate a formula into an integer.
- The interpreter understand unary plus and minus, basic integer math
+ The interpreter understands unary plus and minus, basic integer math
(+, -, *, /), brackets, and can handle a user defined list of variables
by name. There is no error checking. We assume that the formula is
entered correctly.
[ Direct Link to Message ] | |