From 0fb2a55fc8794f29053434c1ce2a94c7746b2b58 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Thu, 23 Nov 2017 19:34:33 +0000 Subject: Fixes issued raised in STR #3422; Fl_Text_Display constructor order issues; organize member initialization first, method calls last. Also: Reorg'ed member initialization to match order in .H to detect missing member inits. Noticed member mModifyingTabDistance is unused. Tagged with XXX: but left in place, since it's a protected member, and might be utilized by user code. We should probably remove this member. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12570 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Text_Display.cxx | 114 ++++++++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index 36b381721..b70327898 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -97,82 +97,90 @@ static int scroll_x = 0; */ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l) : Fl_Group(X, Y, W, H, l) { - int i; - mMaxsize = 0; + // Member initialization: same order as declared in .H file + // Any Fl_Text_Display methods should only be called /after/ all + // members initialized; avoids methods referencing uninitialized values. + // damage_range1_start = damage_range1_end = -1; damage_range2_start = damage_range2_end = -1; - dragPos = dragging = 0; - dragType = DRAG_CHAR; - display_insert_position_hint = 0; - shortcut_ = 0; - - color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR); - box(FL_DOWN_FRAME); - textsize(FL_NORMAL_SIZE); - textcolor(FL_FOREGROUND_COLOR); - textfont(FL_HELVETICA); - set_flag(SHORTCUT_LABEL); - - text_area.x = 0; - text_area.y = 0; - text_area.w = 0; - text_area.h = 0; - - mVScrollBar = new Fl_Scrollbar(0,0,1,1); - mVScrollBar->callback((Fl_Callback*)v_scrollbar_cb, this); - mHScrollBar = new Fl_Scrollbar(0,0,1,1); - mHScrollBar->callback((Fl_Callback*)h_scrollbar_cb, this); - mHScrollBar->type(FL_HORIZONTAL); - - end(); - - scrollbar_width_ = 0; // 0: uses Fl::scrollbar_size() - scrollbar_align_ = FL_ALIGN_BOTTOM_RIGHT; - - mCursorOn = 0; mCursorPos = 0; + mCursorOn = 0; mCursorOldY = -100; mCursorToHint = NO_HINT; mCursorStyle = NORMAL_CURSOR; mCursorPreferredXPos = -1; - mBuffer = 0; + mNVisibleLines = 1; + mNBufferLines = 0; + mBuffer = NULL; + mStyleBuffer = NULL; mFirstChar = 0; mLastChar = 0; - mNBufferLines = 0; - mTopLineNum = mTopLineNumHint = 1; + mContinuousWrap = 0; + mWrapMarginPix = 0; + mLineStarts = new int[mNVisibleLines]; + { // This code unused unless mNVisibleLines is ever initialized >1 + for (int i=1; icallback((Fl_Callback*)h_scrollbar_cb, this); + mHScrollBar->type(FL_HORIZONTAL); + + mVScrollBar = new Fl_Scrollbar(0,0,1,1); + mVScrollBar->callback((Fl_Callback*)v_scrollbar_cb, this); + + scrollbar_width_ = 0; // 0: default from Fl::scrollbar_size() + scrollbar_align_ = FL_ALIGN_BOTTOM_RIGHT; + + dragPos = 0; + dragType = DRAG_CHAR; + dragging = 0; + display_insert_position_hint = 0; + + text_area.x = 0; + text_area.y = 0; + text_area.w = 0; + text_area.h = 0; + + shortcut_ = 0; + textfont_ = FL_HELVETICA; // textfont() + textsize_ = FL_NORMAL_SIZE; // textsize() + textcolor_ = FL_FOREGROUND_COLOR; // textcolor() + mLineNumLeft = 0; + mLineNumWidth = 0; - mLineNumLeft = mLineNumWidth = 0; - mContinuousWrap = 0; - mWrapMarginPix = 0; - mSuppressResync = mNLinesDeleted = mModifyingTabDistance = 0; linenumber_font_ = FL_HELVETICA; linenumber_size_ = FL_NORMAL_SIZE; linenumber_fgcolor_ = FL_INACTIVE_COLOR; linenumber_bgcolor_ = 53; // ~90% gray linenumber_align_ = FL_ALIGN_RIGHT; linenumber_format_ = strdup("%d"); + + // Method calls -- only AFTER all members initialized + color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR); + box(FL_DOWN_FRAME); + set_flag(SHORTCUT_LABEL); + + end(); } -- cgit v1.2.3