[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#246031: g++-3.3 crashes with segfault on broken c++ code



Package: g++-3.3
Version: 1:3.3.3-6
Severity: normal
Tags: sid

marc@dauntless:~/c-prg/Semester2/Prakt05$ g++ -pedantic -c -o
TextObject.o TextObject.cpp
TextObject.cpp: In member function `void TextObject::expand(int)':
TextObject.cpp:65: error: cannot convert `TextObject::TextLine**' to `
   TextObject::TextLine*' in initialization
TextObject.cpp:66: error: cannot convert `TextObject::TextLine*' to `
   TextObject::TextLine**' in assignment
TextObject.cpp:68: error: cannot convert `TextObject::TextLine' to `
   TextObject::TextLine*' in assignment
TextObject.cpp: In constructor `TextObject::TextObject(char*)':
TextObject.cpp:93: error: statement cannot resolve address of overloaded
   function
g++: Internal error: Segmentation fault (program cc1plus)
Please submit a full bug report.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
For Debian GNU/Linux specific bugs,
please see /usr/share/doc/debian/bug-reporting.txt.

(See attached files)

-- System Information:
Debian Release: 3.0
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.4.24
Locale: LANG=de_DE, LC_CTYPE=de_DE (ignored: LC_ALL set to de_DE)

Versions of packages g++-3.3 depends on:
ii  gcc-3.3                     1:3.3.3-6    The GNU C compiler
ii  gcc-3.3-base                1:3.3.3-6    The GNU Compiler Collection (base 
hi  libc6                       2.3.2.ds1-12 GNU C Library: Shared libraries an
ii  libstdc++5-3.3-dev          1:3.3.3-6    The GNU Standard C++ Library v3 (d

-- no debconf information
#include "TextObject.h"

//////////////////////////////
// Klasse TextObject::TextLine
//////////////////////////////

TextObject::TextLine::TextLine():l("") {
  columns = 0;
  // l = new char[1];
  // strncpy(l, "", 1);
}


TextObject::TextLine::TextLine(char* tl) {
  columns = strlen(tl);
  l = new char[columns+1];
  strncpy(l, tl, columns+1);
}


TextObject::TextLine::TextLine(TextLine& tl) {
  columns = tl.columns;
  l = new char[columns+1];
  strncpy(l, tl.l, columns+1);
}


TextObject::TextLine::~TextLine() {
  delete[] l;
}


TextObject::TextLine& TextObject::TextLine::operator = (TextLine& tl) {
  delete[] l;
  columns = tl.columns;
  l = new char[columns+1];
  strncpy(l, tl.l, columns+1);
  return *this;
}

char& TextObject::TextLine::operator [] (int column) {
  if (column<0) {
    throw TextObject::OutOfBounds();
  }

  if (column>=columns) {
    char* tmp = l;
    columns = column;
    l = new char[columns+1];
    strncpy(l, tmp, strlen(tmp));
    for (int n=strlen(tmp); n<columns; n++) {
      l[n] = ' ';
    }
    delete[] tmp;
  }
  return l[column];
}

////////////////////
// Klasse TextObject
////////////////////

void TextObject::expand(int s) {
  if (s>lines) {
    TextLine *tmp=t;
    t = new TextLine[s];
    for (int n=0; n<lines; n++) {
      t[n] = tmp[n];
    } 
    for (int n=lines; n<s; n++) {
      t[n] = NULL;
    }
    lines=s;
  }
}

TextObject::TextObject() {
  t=NULL;
  size = 0;
  lines = 0;
  filename = NULL;
}


TextObject::TextObject(char* Filename) {
  ifstream in(Filename,ios::in);
  size=0;
  lines=0;
  if (in.bad()){
    ofstream out(Filename,ios::out);
    filename=Filename;
    cout << "Erzeuge neue Datei:" << Filename << endl;
    out.close;
  } else {
    char a[256];
    while (!in.eof()){
      in.getline(a,255,'\n');  //zeilenweise einlesen
      expand(lines+1);
      t[lines-1]=new TextLine(a);
      size+=256;
    }
    in.close(); 
  }
}


TextObject::TextObject(TextObject& copy) {
  size=copy.size;
  lines=copy.lines;
  *t = new TextLine[lines];
  for (int n=0; n<lines; n++) {
    t[n] = copy.t[n];
  }
}


TextObject::~TextObject() {
  delete[] t;
}


TextObject& TextObject::operator = (TextObject& copy) {
  size=copy.size;
  lines=copy.lines;
  *t = new TextLine[lines];
  for (int n=0; n<lines; n++) {
    t[n] = copy.t[n];
  }
}


void TextObject::SetFilename(char* Filename) {
  filename = Filename;
}

TextObject::TextLine& TextObject::operator [] (int line) {
  if (line<0) {
    throw TextObject::OutOfBounds();
  }
  return *t[line];
}
//-------------------------------------------------------------------------------
// Klasse TextObject zur Manipulation von Textdateien mittels
// zweidimensionalem Feldzugriff
//
// Prof. Dr.-Ing. B. Lang
// (c) FH Osnabrueck
// OOP-Praktikum
//-------------------------------------------------------------------------------
#ifndef _TextObject_h_
#define _TextObject_h_

using namespace std;

#include <new>
#include <string.h>
#include <cstring>
#include <iostream>
#include <fstream>

class TextObject {
 public:
  class TextLine;
 private:
  TextLine **t;
  int size;
  int lines;
  char* filename;
  void expand(int s);
 public:
  class OutOfBounds {};
  TextObject();
  TextObject(char* Filename);
  TextObject(TextObject&);
  ~TextObject();
  TextObject& operator= (TextObject&);
  void SetFilename(char* Filename);
  TextLine& operator [] (int line);
  operator int () const { return lines; }
  int MaxColumns () const;
};
class TextObject::TextLine {
  char* l;
  int   columns;
 public:
  TextLine();
  TextLine(char* tl);
  TextLine(TextLine&);
  ~TextLine();
  TextLine& operator= (TextLine&);
  char& operator [] (int column);
  operator int () const { return columns; }
  operator const char* () const { return l; }
};

#endif

Reply to: