Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 6991 - colortail segfaults under newer gcc builds
Summary: colortail segfaults under newer gcc builds
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Karl Trygve Kalleberg (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-24 16:22 UTC by Paul Giordano
Modified: 2003-02-04 19:42 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Attachment per request. (colortail.patch,8.47 KB, patch)
2002-08-28 21:55 UTC, Paul Giordano
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Giordano 2002-08-24 16:22:09 UTC
I've been trying to get colortail to compile clean and to run without segfault   
on newer gcc builds (I'm playing on 3.1.1 now) and have updated the patch to  
reflect more current C++ standards - I've included it here. Please let me know  
if I'm on the right track, or if this was the wrong thing to do?  
  
Regards,  
Gio  
 
diff -Naur colortail-0.3.0.org/CfgFileParser.cc 
colortail-0.3.0/CfgFileParser.cc 
--- colortail-0.3.0.org/CfgFileParser.cc	Tue Aug  3 14:40:44 1999 
+++ colortail-0.3.0/CfgFileParser.cc	Sat Aug 24 16:03:58 2002 
@@ -19,12 +19,12 @@ 
  
 #include "CfgFileParser.h" 
  
-#include <stdio.h> 
-#include <fstream.h> 
+#include <iostream> 
 #include <assert.h> 
-#include <string.h> 
+#include <string> 
 #include <malloc.h> 
  
+using namespace std; 
  
 // ## class SearchData ## 
  
@@ -499,7 +499,7 @@ 
 	  
 	  
  
-int CfgFileParser::parse(char *filename) 
+int CfgFileParser::parse(const char *filename) 
 { 
    // parses the cfg file and sets up the list of SearchData elements 
    // returns number of SearchData items created 
diff -Naur colortail-0.3.0.org/CfgFileParser.h colortail-0.3.0/CfgFileParser.h 
--- colortail-0.3.0.org/CfgFileParser.h	Tue Aug  3 14:40:52 1999 
+++ colortail-0.3.0/CfgFileParser.h	Sat Aug 24 16:03:21 2002 
@@ -25,7 +25,8 @@ 
  
 #include <sys/types.h> 
 #include <regex.h> 
-#include <fstream.h> 
+#include <iostream> 
+#include <fstream> 
  
 #ifdef HAVE_GNUREGEX_H 
 # include <gnuregex.h> 
@@ -80,7 +81,7 @@ 
 { 
   private: 
    List<SearchData*> *m_items_list; 
-   ifstream m_infile; 
+   std::ifstream m_infile; 
    char *m_filename; 
    int m_line; 
  
@@ -97,7 +98,7 @@ 
    CfgFileParser(); 
    ~CfgFileParser(); 
  
-   int parse(char *filename); 
+   int parse(const char *filename); 
    List<SearchData*>* get_items_list(); 
 }; 
  
diff -Naur colortail-0.3.0.org/ColorTail.cc colortail-0.3.0/ColorTail.cc 
--- colortail-0.3.0.org/ColorTail.cc	Tue Aug  3 14:41:02 1999 
+++ colortail-0.3.0/ColorTail.cc	Sat Aug 24 15:28:21 2002 
@@ -17,7 +17,7 @@ 
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
  
-#include <iostream.h> 
+#include <iostream> 
 #include <assert.h> 
 #include <unistd.h> 
  
@@ -26,6 +26,7 @@ 
 #include "OptionsParser.h" 
 #include "Colorizer.h" 
  
+using namespace std; 
  
 // the constructor 
 ColorTail::ColorTail() 
diff -Naur colortail-0.3.0.org/Colorizer.cc colortail-0.3.0/Colorizer.cc 
--- colortail-0.3.0.org/Colorizer.cc	Tue Aug  3 14:41:17 1999 
+++ colortail-0.3.0/Colorizer.cc	Sat Aug 24 16:07:33 2002 
@@ -22,9 +22,10 @@ 
 #include "TailFile.h" 
  
 #include <assert.h> 
-#include <stdio.h> 
-#include <strstream.h> 
+#include <iostream> 
+#include <string> 
  
+using namespace std; 
  
 Colorizer::Colorizer() 
 { 
@@ -58,7 +59,7 @@ 
 } 
  
  
-Colorizer::Colorizer(char *cfg_file) 
+Colorizer::Colorizer(const char *cfg_file) 
 { 
    // other constructor 
     
@@ -85,7 +86,7 @@ 
    free_items(); 
 } 
  
-char* Colorizer::colorize(char *str) 
+const char* Colorizer::colorize(const char *str) 
 { 
    // colorize the string, returns a new string containing 
    // the colorized version of str 
@@ -111,7 +112,7 @@ 
    ListIterator<SearchData*> itr(*m_items_list); 
  
    // will contain the new string 
-   ostrstream newstr; 
+   ostringstream newstr; 
     
    SearchData *current; 
    int i = 0; 
@@ -174,7 +175,7 @@ 
 	    // write ansi reset str and a newline 
 	    newstr << ANSI_RESET_STR << endl << ends; 
 	    // return the new string 
-	    return newstr.str(); 
+	    return newstr.str().c_str(); 
 	 } 
       } 
    } 
@@ -196,7 +197,7 @@ 
       } 
  
       // return the new string 
-      return newstr.str(); 
+      return newstr.str().c_str(); 
    } 
  
    // did we find submatches? 
@@ -250,7 +251,7 @@ 
 //      cout << "DEBUG: " << bla << " END DEBUG" << endl; 
        
 	  
-      return newstr.str(); 
+      return newstr.str().c_str(); 
        
    } 
     
diff -Naur colortail-0.3.0.org/Colorizer.h colortail-0.3.0/Colorizer.h 
--- colortail-0.3.0.org/Colorizer.h	Tue Aug  3 14:41:25 1999 
+++ colortail-0.3.0/Colorizer.h	Sat Aug 24 16:07:43 2002 
@@ -35,10 +35,10 @@ 
    Colorizer(); 
        
   public: 
-      Colorizer(char *cfg_file); 
+      Colorizer(const char *cfg_file); 
       ~Colorizer(); 
  
-      char* colorize(char *str); 
+      const char* colorize(const char *str); 
 }; 
  
  
diff -Naur colortail-0.3.0.org/Info.cc colortail-0.3.0/Info.cc 
--- colortail-0.3.0.org/Info.cc	Tue Aug  3 14:41:38 1999 
+++ colortail-0.3.0/Info.cc	Sat Aug 24 15:58:29 2002 
@@ -17,11 +17,13 @@ 
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
  
-#include <iostream.h> 
+#include <iostream> 
  
 #include "Info.h" 
 #include "config.h" 
  
+using namespace std; 
+ 
 Info::Info() 
 { 
 } 
diff -Naur colortail-0.3.0.org/OptionsParser.cc 
colortail-0.3.0/OptionsParser.cc 
--- colortail-0.3.0.org/OptionsParser.cc	Wed Aug  4 18:23:39 1999 
+++ colortail-0.3.0/OptionsParser.cc	Sat Aug 24 15:59:41 2002 
@@ -17,8 +17,8 @@ 
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
  
-#include <iostream.h> 
-#include <strstream.h> 
+#include <iostream> 
+#include <sstream> 
 #include <string.h> 
 #include <stdio.h> 
 #include <stdlib.h> 
@@ -27,6 +27,7 @@ 
 #include "Info.h" 
 #include "Usage.h" 
  
+using namespace std; 
 // methods for class Options 
  
 Options::Options() 
@@ -130,7 +131,7 @@ 
 	    int loop = 1; 
 	    while (loop) 
 	    { 
-	       ostrstream filename; 
+	       ostringstream filename; 
  
 	       while (1) 
 	       { 
@@ -138,7 +139,7 @@ 
 		  { 
 		     // found seperator 
 		     // set filename in options class 
-		     o->cfg_filenames[o->nr_cfg_files] = filename.str(); 
+		     o->cfg_filenames[o->nr_cfg_files] = 
filename.str().c_str(); 
  
 		     // increase the nr_cfg_files counter 
 		     (o->nr_cfg_files)++; 
@@ -154,7 +155,7 @@ 
 		  { 
 		     // found end of string 
 		     // set filename in options class 
-		     o->cfg_filenames[o->nr_cfg_files] = filename.str(); 
+		     o->cfg_filenames[o->nr_cfg_files] = 
filename.str().c_str(); 
  
 		     // increase the nr_cfg_files counter 
 		     (o->nr_cfg_files)++; 
diff -Naur colortail-0.3.0.org/OptionsParser.h colortail-0.3.0/OptionsParser.h 
--- colortail-0.3.0.org/OptionsParser.h	Wed Aug  4 18:33:08 1999 
+++ colortail-0.3.0/OptionsParser.h	Sat Aug 24 16:00:42 2002 
@@ -77,7 +77,7 @@ 
    int color; 
    int rows; 
    int verbose; 
-   char *cfg_filenames[MAX_FILES]; 
+   const char *cfg_filenames[MAX_FILES]; 
    int nr_cfg_files; 
    int global_cfg_file; 
  
diff -Naur colortail-0.3.0.org/TailFile.cc colortail-0.3.0/TailFile.cc 
--- colortail-0.3.0.org/TailFile.cc	Wed Aug  4 18:09:38 1999 
+++ colortail-0.3.0/TailFile.cc	Sat Aug 24 16:08:12 2002 
@@ -17,7 +17,7 @@ 
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
  
-#include <iostream.h> 
+#include <iostream> 
 #include <string.h> 
 #include <stdio.h> 
 #include <sys/stat.h> 
@@ -25,6 +25,8 @@ 
  
 #include "TailFile.h" 
  
+using namespace std; 
+ 
 TailFile::TailFile() 
 { 
    m_filename = NULL; 
@@ -375,7 +377,7 @@ 
    // check if there isn't a follow buffer 
    if (m_follow_buffer == NULL) 
    { 
-      m_follow_buffer = new ostrstream(); 
+      m_follow_buffer = new ostringstream(); 
    } 
  
    // make buffer 
@@ -454,7 +456,7 @@ 
 	 m_follow_buffer->put('\0'); 
  
 	 // get the string 
-	 char *str = m_follow_buffer->str(); 
+	 const char *str = m_follow_buffer->str().c_str(); 
 	  
 	 // print the line 
 	 print_to_stdout(str); 
@@ -560,7 +562,7 @@ 
 //   delete buf; 
 } 
  
-void TailFile::print_to_stdout(char *str) 
+void TailFile::print_to_stdout(const char *str) 
 { 
    // checks if there is a colorizer. If so the string is colorized 
    // before it's printed. If not the string isn't colorized. 
@@ -575,7 +577,7 @@ 
    if (m_colorizer) 
    { 
       // colorize the string 
-      char *buf = m_colorizer->colorize(str); 
+      const char *buf = m_colorizer->colorize(str); 
       // print the new colorized string 
       cout << buf; 
       // free the mem 
diff -Naur colortail-0.3.0.org/TailFile.h colortail-0.3.0/TailFile.h 
--- colortail-0.3.0.org/TailFile.h	Tue Aug  3 14:42:33 1999 
+++ colortail-0.3.0/TailFile.h	Sat Aug 24 16:06:00 2002 
@@ -23,7 +23,7 @@ 
 #include "Colorizer.h" 
  
 #include <stdio.h> 
-#include <strstream.h> 
+#include <sstream> 
  
 #define MAX_CHARS_READ 1024 
  
@@ -40,12 +40,12 @@ 
    // the stream position 
    long m_position; 
    // the follow buffer, used in follow_print 
-   ostrstream *m_follow_buffer; 
+   std::ostringstream *m_follow_buffer; 
  
    // private methods 
    void find_position(int n); 
    long end_of_file_position(); 
-   void print_to_stdout(char *str); 
+   void print_to_stdout(const char *str); 
     
    // methods    
   public: 
diff -Naur colortail-0.3.0.org/Usage.cc colortail-0.3.0/Usage.cc 
--- colortail-0.3.0.org/Usage.cc	Wed Aug  4 18:44:37 1999 
+++ colortail-0.3.0/Usage.cc	Sat Aug 24 16:08:35 2002 
@@ -17,10 +17,12 @@ 
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
  
-#include <iostream.h> 
+#include <iostream> 
  
 #include "Usage.h" 
  
+using namespace std; 
+ 
 Usage::Usage() 
 { 
 }
Comment 1 Karl Trygve Kalleberg (RETIRED) gentoo-dev 2002-08-28 08:39:46 UTC
For some reason, your patch fails to apply at all, although it appears fine by
visual inspection. I suspect some whitespace issues. Could you upload it as an
attachment ?
Comment 2 Paul Giordano 2002-08-28 21:55:42 UTC
Created attachment 3521 [details, diff]
Attachment per request.
Comment 3 Karl Trygve Kalleberg (RETIRED) gentoo-dev 2002-09-02 10:57:21 UTC
With your patch applied, it segfaults when compiled with 2.95.3:

Starting program: /usr/bin/colortail -k /tmp/fobozz /var/log/everything/current
==> /var/log/everything/current <==
Sep  2 17:36:52 [sshd] Did not receive identification string from 192.168.1.197

Program received signal SIGSEGV, Segmentation fault.
0x4010f691 in free () from /lib/libc.so.6
(gdb) bt
#0  0x4010f691 in free () from /lib/libc.so.6
#1  0x4004df87 in __builtin_delete ()
   from /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/libstdc++-libc6.2-2.so.3
#2  0x0804e350 in TailFile::print_to_stdout (this=0x8057da0, 
    str=0xbffff45c "Sep  2 17:36:52 [sshd] Did not receive identification string
from 192.168.1.197\n") at TailFile.cc:584
#3  0x0804ddd4 in TailFile::print (this=0x8057da0, n=10) at TailFile.cc:134
#4  0x0804c69a in ColorTail::start (this=0x8057be0, argc=4, argv=0xbffffb84)
    at ColorTail.cc:198
#5  0x0804e6ac in main (argc=4, argv=0xbffffb84) at main.cc:41
#6  0x400b53c1 in __libc_start_main () from /lib/libc.so.6

Without your patch applied, it works with works with 2.95.3.

However, with your patch applied, it appears to work nicely when compiled with 3.2. 

Do you know if there's any chance we can modify the patch so that it compiles
and runs cleanly with both 2.95.3 and 3.2 ?
Comment 4 Karl Trygve Kalleberg (RETIRED) gentoo-dev 2002-09-08 16:54:00 UTC
Ebuild now only applies patch if compiled with compilers newer than 2.95.x.
Available as app-misc/colortail-0.3.0-r3