app segfaults when appending text



Hello

In my program I have a TextView which I would like to append some text.
When I append 2- to 3-times all is ok but when appending more the
program segfaults. Please help.


Code:
========================
char *msg, *tmp;
Glib::ustring chatter;
...
std::cout << "Chatting: " << msg << "\n";
char *text;
tmp = msg; // msg is the string to add
msg += 5;
text = new char[strlen(msg) + 1];
strcpy(text, msg);
msg = tmp;
int line;
Glib::RefPtr<Gtk::TextBuffer> buf = chat_view->get_buffer();
Gtk::TextIter iter;

line = buf->get_line_count(); // but = GtkTextBuffer *
iter =  buf->get_iter_at_line(line);
chatter = text;
buf->insert(iter, chatter);
msg = tmp;
delete [] msg;
..
======================

Greets,
Luka


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