Fix uninitialized vars in calls to fl_clip_box() (issue #6)

The main fixes are only to avoid static code analyzer warnings reported
in issue #5, but there are also minor bug fixes included. These bug
fixes are more of theoretical concerns though.

Close #6.
This commit is contained in:
Albrecht Schlosser 2020-01-15 21:23:26 +01:00
parent 3265d439f3
commit dfaab4ae90
11 changed files with 45 additions and 34 deletions

View File

@ -3,7 +3,7 @@
//
// Fl_Graphics_Driver class for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2018 by Bill Spitzak and others.
// Copyright 2010-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -463,7 +463,13 @@ void Fl_Graphics_Driver::polygon(int x0, int y0, int x1, int y1, int x2, int y2)
void Fl_Graphics_Driver::push_clip(int x, int y, int w, int h) {}
/** see fl_clip_box() */
int Fl_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H) {return 0;}
int Fl_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H) {
X = x;
Y = y;
W = w;
H = h;
return 0; // completely inside
}
/** see fl_not_clipped() */
int Fl_Graphics_Driver::not_clipped(int x, int y, int w, int h) {return 1;}

View File

@ -1,7 +1,7 @@
//
// "$Id$"
//
// Copyright 2001-2018 by Bill Spitzak and others.
// Copyright 2001-2020 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under
// the LGPL for the FLTK library granted by Mark Edel.
//
@ -3798,7 +3798,7 @@ void Fl_Text_Display::draw(void) {
// draw all of the text
if (damage() & (FL_DAMAGE_ALL | FL_DAMAGE_EXPOSE)) {
//printf("drawing all text\n");
int X, Y, W, H;
int X = 0, Y = 0, W = 0, H = 0;
if (fl_clip_box(text_area.x, text_area.y, text_area.w, text_area.h,
X, Y, W, H)) {
// Draw text using the intersected clipping box...

View File

@ -3,7 +3,7 @@
//
// Definition of Android window driver.
//
// Copyright 2018 by Bill Spitzak and others.
// Copyright 2018-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -510,7 +510,8 @@ void Fl_WinAPI_Window_Driver::flush_double()
fl_end_offscreen();
}
int X,Y,W,H; fl_clip_box(0,0,w(),h(),X,Y,W,H);
int X = 0, Y = 0, W = 0, H = 0;
fl_clip_box(0, 0, w(), h(), X, Y, W, H);
if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid, X, Y);
}
@ -540,7 +541,8 @@ void Fl_WinAPI_Window_Driver::flush_overlay()
}
if (eraseoverlay) fl_clip_region(0);
int X, Y, W, H; fl_clip_box(0, 0, w(), h(), X, Y, W, H);
int X = 0, Y = 0, W = 0, H = 0;
fl_clip_box(0, 0, w(), h(), X, Y, W, H);
if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid, X, Y);
if (overlay() == oWindow) oWindow->draw_overlay();

View File

@ -3,7 +3,7 @@
//
// Windows image drawing code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -125,8 +125,8 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
if (!linedelta) linedelta = W*fl_abs(delta);
int x, y, w, h;
fl_clip_box(X,Y,W,H,x,y,w,h);
int x = 0, y = 0, w = 0, h = 0;
fl_clip_box(X, Y, W, H, x, y, w, h);
if (w<=0 || h<=0) return;
if (buf) buf += (x-X)*delta + (y-Y)*linedelta;

View File

@ -3,7 +3,7 @@
//
// Rectangle drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2017 by Bill Spitzak and others.
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -172,7 +172,7 @@ void Fl_OpenGL_Graphics_Driver::push_clip(int x, int y, int w, int h) {
int Fl_OpenGL_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H) {
// TODO: implement OpenGL clipping
X = x; Y = y; W = w, H = h;
X = x; Y = y; W = w; H = h;
return 0;
}

View File

@ -3,7 +3,7 @@
//
// Rectangle drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2016 by Bill Spitzak and others.
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -195,6 +195,7 @@ void Fl_Pico_Graphics_Driver::push_clip(int x, int y, int w, int h)
int Fl_Pico_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H)
{
X = x; Y = y; W = w; H = h;
return 0;
}

View File

@ -3,7 +3,7 @@
//
// Classes Fl_PostScript_File_Device and Fl_PostScript_Graphics_Driver for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2016 by Bill Spitzak and others.
// Copyright 2010-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -1341,16 +1341,16 @@ void Fl_PostScript_Graphics_Driver::pop_clip() {
recover();
}
int Fl_PostScript_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H){
if(!clip_){
X=x;Y=y;W=w;H=h;
int Fl_PostScript_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H) {
if (!clip_) {
X = x; Y = y; W = w; H = h;
return 1;
}
if(clip_->w < 0){
X=x;Y=y;W=w;H=h;
if (clip_->w < 0) {
X = x; Y = y; W = w; H = h;
return 1;
}
int ret=0;
int ret = 0;
if (x > (X=clip_->x)) {X=x; ret=1;}
if (y > (Y=clip_->y)) {Y=y; ret=1;}
if ((x+w) < (clip_->x+clip_->w)) {
@ -1377,12 +1377,12 @@ int Fl_PostScript_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X,
return ret;
}
int Fl_PostScript_Graphics_Driver::not_clipped(int x, int y, int w, int h){
if(!clip_) return 1;
if(clip_->w < 0) return 1;
int X, Y, W, H;
int Fl_PostScript_Graphics_Driver::not_clipped(int x, int y, int w, int h) {
if (!clip_) return 1;
if (clip_->w < 0) return 1;
int X = 0, Y = 0, W = 0, H = 0;
clip_box(x, y, w, h, X, Y, W, H);
if(W) return 1;
if (W) return 1;
return 0;
}

View File

@ -3,7 +3,7 @@
//
// Definition of Apple Cocoa window driver.
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -334,7 +334,8 @@ void Fl_WinAPI_Window_Driver::flush_double()
fl_graphics_driver->gc(sgc);
#endif
}
int X,Y,W,H; fl_clip_box(0,0,w(),h(),X,Y,W,H);
int X = 0, Y = 0, W = 0, H = 0;
fl_clip_box(0, 0, w(), h(), X, Y, W, H);
if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid, X, Y);
}

View File

@ -3,7 +3,7 @@
//
// Definition of X11 window driver.
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -234,7 +234,8 @@ void Fl_X11_Window_Driver::flush_double(int erase_overlay)
fl_window = i->xid;
}
if (erase_overlay) fl_clip_region(0);
int X,Y,W,H; fl_clip_box(0,0,w(),h(),X,Y,W,H);
int X = 0, Y = 0, W = 0, H = 0;
fl_clip_box(0, 0, w(), h(), X, Y, W, H);
if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid, X, Y);
}

View File

@ -3,7 +3,7 @@
//
// Image drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -474,8 +474,8 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
{
if (!linedelta) linedelta = W*abs(delta);
int dx, dy, w, h;
fl_clip_box(X,Y,W,H,dx,dy,w,h);
int dx = 0, dy = 0, w = 0, h = 0;
fl_clip_box(X, Y, W, H, dx, dy, w, h);
if (w<=0 || h<=0) return;
dx -= X;
dy -= Y;

View File

@ -3,7 +3,7 @@
//
// OpenGL context routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -65,7 +65,7 @@ void gl_start() {
}
if (clip_state_number != fl_graphics_driver->fl_clip_state_number) {
clip_state_number = fl_graphics_driver->fl_clip_state_number;
int x, y, w, h;
int x = 0, y = 0, w = 0, h = 0;
if (fl_clip_box(0, 0, Fl_Window::current()->w(), Fl_Window::current()->h(),
x, y, w, h)) {
fl_clip_region(Fl_Graphics_Driver::default_driver().XRectangleRegion(x,y,w,h));