From 2fbee9c1500a7b3862732bdfa2ad6fef9dcc3092 Mon Sep 17 00:00:00 2001
From: Michael R Sweet <michael.r.sweet@gmail.com>
Date: Wed, 5 Dec 2001 00:06:41 +0000
Subject: [PATCH] Segfault fixes...

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1809 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
---
 CHANGES                  | 15 +++++++++++----
 src/Fl_File_Chooser2.cxx |  7 +++++--
 src/Fl_File_Icon.cxx     |  7 +++----
 src/Fl_File_Icon2.cxx    |  7 +++----
 4 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/CHANGES b/CHANGES
index a7430c190..e8810a4ce 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,9 +1,16 @@
 CHANGES IN FLTK 1.1.0b7
-
-	- Some Win32 drivers would draw into wrong buffers
-	  after OpenGL mode change
-	- Message handling and Resources for Mac port
+
 	- More documentation updates...
+	- The file chooser would cause a segfault if you
+	  clicked in an empty area of the file list.
+	- Fl_File_Icon::labeltype() would cause a segfault
+	  if the value pointer was NULL.
+	- Fl_File_Icon::load_image() could cause segfaults
+	  (NULL data and incrementing the data pointer too
+	  often.)
+	- Some Win32 drivers would draw into wrong buffers
+	  after OpenGL mode change.
+	- Message handling and Resources for MacOS port.
 	- Fl_Help_View could get in an infinitely loop when
 	  determining the maximum width of the page; this
 	  was due to a bug in the get_length() method with
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx
index 62af75003..3bcdb90b2 100644
--- a/src/Fl_File_Chooser2.cxx
+++ b/src/Fl_File_Chooser2.cxx
@@ -1,5 +1,5 @@
 //
-// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.4 2001/11/25 16:38:11 easysw Exp $"
+// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.5 2001/12/05 00:06:41 easysw Exp $"
 //
 // More Fl_File_Chooser routines.
 //
@@ -424,6 +424,9 @@ Fl_File_Chooser::fileListCB()
 
 
   filename = (char *)fileList->text(fileList->value());
+  if (!filename)
+    return;
+
   if (directory_[0] != '\0')
     snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
   else
@@ -704,5 +707,5 @@ Fl_File_Chooser::fileNameCB()
 
 
 //
-// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.4 2001/11/25 16:38:11 easysw Exp $".
+// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.5 2001/12/05 00:06:41 easysw Exp $".
 //
diff --git a/src/Fl_File_Icon.cxx b/src/Fl_File_Icon.cxx
index 665b98911..adb80311d 100644
--- a/src/Fl_File_Icon.cxx
+++ b/src/Fl_File_Icon.cxx
@@ -1,5 +1,5 @@
 //
-// "$Id: Fl_File_Icon.cxx,v 1.1.2.5 2001/11/17 15:27:15 easysw Exp $"
+// "$Id: Fl_File_Icon.cxx,v 1.1.2.6 2001/12/05 00:06:41 easysw Exp $"
 //
 // Fl_File_Icon routines.
 //
@@ -461,11 +461,10 @@ Fl_File_Icon::labeltype(const Fl_Label *o,	// I - Label data
   (void)a;
 
   icon = (Fl_File_Icon *)(o->value);
-
-  icon->draw(x, y, w, h, (Fl_Color)(o->color));
+  if (icon) icon->draw(x, y, w, h, (Fl_Color)(o->color));
 }
 
 
 //
-// End of "$Id: Fl_File_Icon.cxx,v 1.1.2.5 2001/11/17 15:27:15 easysw Exp $".
+// End of "$Id: Fl_File_Icon.cxx,v 1.1.2.6 2001/12/05 00:06:41 easysw Exp $".
 //
diff --git a/src/Fl_File_Icon2.cxx b/src/Fl_File_Icon2.cxx
index 7252ce9e6..1f8e77783 100644
--- a/src/Fl_File_Icon2.cxx
+++ b/src/Fl_File_Icon2.cxx
@@ -1,5 +1,5 @@
 //
-// "$Id: Fl_File_Icon2.cxx,v 1.1.2.4 2001/11/25 16:38:11 easysw Exp $"
+// "$Id: Fl_File_Icon2.cxx,v 1.1.2.5 2001/12/05 00:06:41 easysw Exp $"
 //
 // Fl_File_Icon system icon routines.
 //
@@ -333,7 +333,7 @@ Fl_File_Icon::load_image(const char *ifile)	// I - File to read from
 
 
   img = Fl_Shared_Image::get(ifile);
-  if (!img->w() && !img->h()) return -1;
+  if (!img || !img->count() || !img->w() || !img->h()) return -1;
 
   if (img->count() == 1) {
     int		x, y;		// X & Y in image
@@ -521,7 +521,6 @@ Fl_File_Icon::load_image(const char *ifile)	// I - File to read from
       lineptr = *ptr;
       startx  = 0;
       ch      = bg;
-      ptr ++;
 
       for (x = 0; x < img->w(); x ++, lineptr ++)
 	if (*lineptr != ch)
@@ -924,5 +923,5 @@ get_kde_val(char       *str,
 
 
 //
-// End of "$Id: Fl_File_Icon2.cxx,v 1.1.2.4 2001/11/25 16:38:11 easysw Exp $".
+// End of "$Id: Fl_File_Icon2.cxx,v 1.1.2.5 2001/12/05 00:06:41 easysw Exp $".
 //
-- 
GitLab