summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-04-27 16:42:20 +0000
committerManolo Gouy <Manolo>2016-04-27 16:42:20 +0000
commitf4ec7192a9f2c3ada9f7676ca90942306f910db3 (patch)
tree332be43a0ec07951d86029126a54840ddd981a5d
parent425fe6ac8c31ff1500a1745d67aa6bbe781f5328 (diff)
Add tests to avoid null pointer errors
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_Copy_Surface.cxx31
-rw-r--r--src/Fl_Image_Surface.cxx19
-rw-r--r--src/Fl_Native_File_Chooser.cxx2
-rw-r--r--src/Fl_Printer.cxx1
-rw-r--r--test/device.cxx14
5 files changed, 47 insertions, 20 deletions
diff --git a/src/Fl_Copy_Surface.cxx b/src/Fl_Copy_Surface.cxx
index c95d787b2..21ad19d40 100644
--- a/src/Fl_Copy_Surface.cxx
+++ b/src/Fl_Copy_Surface.cxx
@@ -31,26 +31,41 @@ Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int
/** the constructor */
Fl_Copy_Surface::Fl_Copy_Surface(int w, int h) : Fl_Widget_Surface(NULL) {
platform_surface = Fl_Copy_Surface_Driver::newCopySurfaceDriver(w, h);
- driver(platform_surface->driver());
+ if (platform_surface) driver(platform_surface->driver());
}
Fl_Copy_Surface::~Fl_Copy_Surface() { delete platform_surface; }
void Fl_Copy_Surface::origin(int x, int y) {platform_surface->origin(x, y);}
-void Fl_Copy_Surface::origin(int *x, int *y) {platform_surface->origin(x, y);}
+void Fl_Copy_Surface::origin(int *x, int *y) {
+ if (platform_surface) platform_surface->origin(x, y);
+}
-void Fl_Copy_Surface::set_current() {platform_surface->set_current();}
+void Fl_Copy_Surface::set_current() {
+ if (platform_surface) platform_surface->set_current();
+}
-void Fl_Copy_Surface::translate(int x, int y) {platform_surface->translate(x, y);}
+void Fl_Copy_Surface::translate(int x, int y) {
+ if (platform_surface) platform_surface->translate(x, y);
+}
-void Fl_Copy_Surface::untranslate() {platform_surface->untranslate();}
+void Fl_Copy_Surface::untranslate() {
+ if (platform_surface) platform_surface->untranslate();
+}
-int Fl_Copy_Surface::w() {return platform_surface->width;}
+int Fl_Copy_Surface::w() {return platform_surface ? platform_surface->width : 0;}
-int Fl_Copy_Surface::h() {return platform_surface->height;}
+int Fl_Copy_Surface::h() {return platform_surface ? platform_surface->height : 0;}
-int Fl_Copy_Surface::printable_rect(int *w, int *h) {return platform_surface->printable_rect(w, h);}
+int Fl_Copy_Surface::printable_rect(int *w, int *h) {
+ if (platform_surface)
+ return platform_surface->printable_rect(w, h);
+ else {
+ *w = *h = 0;
+ }
+ return 1;
+}
//
// End of "$Id$".
diff --git a/src/Fl_Image_Surface.cxx b/src/Fl_Image_Surface.cxx
index 3db192962..d69b34c4a 100644
--- a/src/Fl_Image_Surface.cxx
+++ b/src/Fl_Image_Surface.cxx
@@ -38,7 +38,7 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i
*/
Fl_Image_Surface::Fl_Image_Surface(int w, int h, int high_res, Fl_Offscreen pixmap) : Fl_Widget_Surface(NULL) {
platform_surface = Fl_Image_Surface_Driver::newImageSurfaceDriver(w, h, high_res, pixmap);
- driver(platform_surface->driver());
+ if (platform_surface) driver(platform_surface->driver());
}
@@ -47,16 +47,24 @@ Fl_Image_Surface::~Fl_Image_Surface() { delete platform_surface; }
void Fl_Image_Surface::origin(int x, int y) {platform_surface->origin(x, y);}
-void Fl_Image_Surface::origin(int *x, int *y) {platform_surface->origin(x, y);}
+void Fl_Image_Surface::origin(int *x, int *y) {
+ if (platform_surface) platform_surface->origin(x, y);
+}
-void Fl_Image_Surface::set_current() {platform_surface->set_current();}
+void Fl_Image_Surface::set_current() {
+ if (platform_surface) platform_surface->set_current();
+}
/** Stop sending graphics commands to the surface */
void Fl_Image_Surface::end_current() {platform_surface->end_current();}
-void Fl_Image_Surface::translate(int x, int y) {platform_surface->translate(x, y);}
+void Fl_Image_Surface::translate(int x, int y) {
+ if (platform_surface) platform_surface->translate(x, y);
+}
-void Fl_Image_Surface::untranslate() {platform_surface->untranslate();}
+void Fl_Image_Surface::untranslate() {
+ if (platform_surface) platform_surface->untranslate();
+}
/** Returns the Fl_Offscreen object associated to the image surface */
Fl_Offscreen Fl_Image_Surface::offscreen() {return platform_surface->offscreen;}
@@ -78,6 +86,7 @@ Fl_RGB_Image *Fl_Image_Surface::image() {return platform_surface->image();}
*/
Fl_Shared_Image* Fl_Image_Surface::highres_image()
{
+ if (!platform_surface) return NULL;
Fl_Shared_Image *s_img = Fl_Shared_Image::get(platform_surface->image());
int width, height;
platform_surface->printable_rect(&width, &height);
diff --git a/src/Fl_Native_File_Chooser.cxx b/src/Fl_Native_File_Chooser.cxx
index c5ed7d70d..0fe990995 100644
--- a/src/Fl_Native_File_Chooser.cxx
+++ b/src/Fl_Native_File_Chooser.cxx
@@ -72,7 +72,7 @@ int Fl_Native_File_Chooser::type() const
*/
void Fl_Native_File_Chooser::options(int o)
{
- platform_fnfc->options(o);
+ if (platform_fnfc) platform_fnfc->options(o);
}
/**
diff --git a/src/Fl_Printer.cxx b/src/Fl_Printer.cxx
index a6756acdc..6938a9b5f 100644
--- a/src/Fl_Printer.cxx
+++ b/src/Fl_Printer.cxx
@@ -22,6 +22,7 @@
#ifdef FL_PORTING
# pragma message "FL_PORTING: implement print support for your platform, or define NO_PRINT_SUPPORT"
+#define NO_PRINT_SUPPORT 1
#endif
#if defined(NO_PRINT_SUPPORT)
diff --git a/test/device.cxx b/test/device.cxx
index 1cb7ec6ab..0246de4d1 100644
--- a/test/device.cxx
+++ b/test/device.cxx
@@ -574,12 +574,14 @@ void copy(Fl_Widget *, void *data) {
Fl_Image *img = rgb_surf->highres_image();
delete rgb_surf;
Fl_Display_Device::display_device()->set_current();
- Fl_Window* g2 = new Fl_Window(img->w()+10, img->h()+10);
- g2->color(FL_YELLOW);
- Fl_Box *b = new Fl_Box(FL_NO_BOX,5,5,img->w(), img->h(),0);
- b->image(img);
- g2->end();
- g2->show();
+ if (img) {
+ Fl_Window* g2 = new Fl_Window(img->w()+10, img->h()+10);
+ g2->color(FL_YELLOW);
+ Fl_Box *b = new Fl_Box(FL_NO_BOX,5,5,img->w(), img->h(),0);
+ b->image(img);
+ g2->end();
+ g2->show();
+ }
return;
}