From f4ec7192a9f2c3ada9f7676ca90942306f910db3 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 27 Apr 2016 16:42:20 +0000 Subject: 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 --- src/Fl_Copy_Surface.cxx | 31 +++++++++++++++++++++++-------- src/Fl_Image_Surface.cxx | 19 ++++++++++++++----- src/Fl_Native_File_Chooser.cxx | 2 +- src/Fl_Printer.cxx | 1 + 4 files changed, 39 insertions(+), 14 deletions(-) (limited to 'src') 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) -- cgit v1.2.3