diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-12-01 16:53:21 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-12-01 16:53:27 +0100 |
| commit | 96730f80cbc3b2d5aec2967a61f16bb2f02853e6 (patch) | |
| tree | 2efb7ea0cf9f9f71aa7fa1838bd4b349ff9157d2 | |
| parent | ccc21d381a41620a9fb91870ab2a47ef9309d148 (diff) | |
Adds some possible NULL references and small fixes
| -rw-r--r-- | fluid/Fl_Grid_Type.cxx | 33 | ||||
| -rw-r--r-- | fluid/Fl_Widget_Type.cxx | 6 | ||||
| -rw-r--r-- | fluid/factory.cxx | 3 | ||||
| -rw-r--r-- | fluid/shell_command.cxx | 4 | ||||
| -rw-r--r-- | src/Fl_String.cxx | 3 | ||||
| -rw-r--r-- | src/Fl_Text_Buffer.cxx | 4 |
6 files changed, 28 insertions, 25 deletions
diff --git a/fluid/Fl_Grid_Type.cxx b/fluid/Fl_Grid_Type.cxx index 6621a2f03..b27a8be7c 100644 --- a/fluid/Fl_Grid_Type.cxx +++ b/fluid/Fl_Grid_Type.cxx @@ -187,7 +187,11 @@ Fl_Grid::Cell* Fl_Grid_Proxy::transient_widget(Fl_Widget *wi, int row, int col, int mw, mh; old_cell->minimum_size(&mw, &mh); new_cell->minimum_size(mw, mh); - ::free(old_cell); + if (remove_old_cell) { + remove_cell(old_cell->row(), old_cell->col()); + } else { + delete old_cell; + } } if (i == num_transient_) { transient_make_room_(num_transient_ + 1); @@ -195,9 +199,6 @@ Fl_Grid::Cell* Fl_Grid_Proxy::transient_widget(Fl_Widget *wi, int row, int col, num_transient_++; } transient_[i].cell = new_cell; - if (remove_old_cell) { - remove_cell(old_cell->row(), old_cell->col()); - } return new_cell; } @@ -911,12 +912,12 @@ void grid_align_horizontal_cb(Fl_Choice* i, void* v) { Fl_Grid::Cell *cell = g->cell(current_widget->o); if (cell) { old_v = cell->align() & mask; - } - if (old_v != v) { - cell->align((Fl_Grid_Align)(v | (cell->align() & ~mask))); - g->need_layout(true); - g->redraw(); - set_modflag(1); + if (old_v != v) { + cell->align((Fl_Grid_Align)(v | (cell->align() & ~mask))); + g->need_layout(true); + g->redraw(); + set_modflag(1); + } } } } @@ -946,12 +947,12 @@ void grid_align_vertical_cb(Fl_Choice* i, void* v) { Fl_Grid::Cell *cell = g->cell(current_widget->o); if (cell) { old_v = cell->align() & mask; - } - if (old_v != v) { - cell->align((Fl_Grid_Align)(v | (cell->align() & ~mask))); - g->need_layout(true); - g->redraw(); - set_modflag(1); + if (old_v != v) { + cell->align((Fl_Grid_Align)(v | (cell->align() & ~mask))); + g->need_layout(true); + g->redraw(); + set_modflag(1); + } } } } diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index 05260136c..9a5c3251a 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -3659,9 +3659,9 @@ void Fl_Widget_Type::copy_properties() { if (!live_widget) return; - Fl_Font ff; - int fs; - Fl_Color fc; + Fl_Font ff = 0; + int fs = 0; + Fl_Color fc = 0; textstuff(0, ff, fs, fc); // copy all attributes common to all widget types diff --git a/fluid/factory.cxx b/fluid/factory.cxx index a60717e30..59a358bce 100644 --- a/fluid/factory.cxx +++ b/fluid/factory.cxx @@ -1243,7 +1243,8 @@ Fl_Type *add_new_widget_from_user(Fl_Type *inPrototype, Strategy strategy) { if (changed && t->is_a(ID_Menu_Item)) { Fl_Type * tt = t->parent; while (tt && !tt->is_a(ID_Menu_Manager_)) tt = tt->parent; - ((Fl_Menu_Manager_Type*)tt)->build_menu(); + if (tt) + ((Fl_Menu_Manager_Type*)tt)->build_menu(); } } if (t->is_true_widget() && !t->is_a(ID_Window)) { diff --git a/fluid/shell_command.cxx b/fluid/shell_command.cxx index 1af872ae0..79b1609e8 100644 --- a/fluid/shell_command.cxx +++ b/fluid/shell_command.cxx @@ -795,7 +795,7 @@ void Fd_Shell_Command_List::write(Fd_Project_Writer *out) { void Fd_Shell_Command_List::add(Fd_Shell_Command *cmd) { if (list_size == list_capacity) { list_capacity += 16; - list = (Fd_Shell_Command**)::realloc(list, list_capacity * sizeof(Fd_Shell_Command**)); + list = (Fd_Shell_Command**)::realloc(list, list_capacity * sizeof(Fd_Shell_Command*)); } list[list_size++] = cmd; } @@ -809,7 +809,7 @@ void Fd_Shell_Command_List::add(Fd_Shell_Command *cmd) { void Fd_Shell_Command_List::insert(int index, Fd_Shell_Command *cmd) { if (list_size == list_capacity) { list_capacity += 16; - list = (Fd_Shell_Command**)::realloc(list, list_capacity * sizeof(Fd_Shell_Command**)); + list = (Fd_Shell_Command**)::realloc(list, list_capacity * sizeof(Fd_Shell_Command*)); } ::memmove(list+index+1, list+index, (list_size-index)*sizeof(Fd_Shell_Command**)); list_size++; diff --git a/src/Fl_String.cxx b/src/Fl_String.cxx index 1252f1202..8fd8e5f51 100644 --- a/src/Fl_String.cxx +++ b/src/Fl_String.cxx @@ -137,7 +137,8 @@ Fl_String &Fl_String::replace_(int at, int n_del, const char *ins, int n_ins) { ::memmove(buffer_+at, ins, n_ins); } size_ = new_size; - buffer_[size_] = 0; + if (buffer_) + buffer_[size_] = 0; return *this; } diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index caf4b3839..3bb8a10f0 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -1406,11 +1406,11 @@ int Fl_Text_Buffer::insert_(int pos, const char *text, int insertedLength) /* Remove a string from the buffer. Unicode safe. Start and end must be at a character boundary. + Start must be less than end. */ void Fl_Text_Buffer::remove_(int start, int end) { - /* if the gap is not contiguous to the area to remove, move it there */ - + if (start >= end) return; if (mCanUndo) { if (mUndo->undoat == end && mUndo->undocut) { // continue to remove text at the same cursor position |
