# Temporary TextBuffer causing segmentation faults

**URL:** <https://www.ruby-forum.com/t/temporary-textbuffer-causing-segmentation-faults/131936>\
**Category:** Ruby-Gnome 2\
**Created:** [March 14, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/temporary-textbuffer-causing-segmentation-faults/131936 "2008-03-14T15:46:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [March 14, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/temporary-textbuffer-causing-segmentation-faults/131936/1 "2008-03-14T15:46:46Z")

</div>

I have a script where the program accepts lines of text that contain a  
sort of odd markup that looks similar to XML. In order to convert that  
markup to usable information, like text colors and whatnot, I take this  
text and create a temporary buffer before inserting it into the actual  
text buffer it will end up in. However, sometimes, when inserting text  
from the temporary buffer to the main buffer, I get segmentation faults.

The terminal shows:  
./archlich-lib.rb:962: [BUG] Segmentation fault  
ruby 1.8.6 (2007-03-13) [x86\_64-linux]

Aborted

Lines 959 to 963 are:  
if (widget.buffer.end\_iter.class == Gtk::TextIter and  
tbuffer.start\_iter.class == Gtk::TextIter and tbuffer.end\_iter.class ==  
Gtk::TextIter)  
widget.buffer.insert\_range(widget.buffer.end\_iter, tbuffer.start\_iter,  
tbuffer.end\_iter)  
end

(the conditionals are me trying to figure out just what is going on)

the ‘tbuffer’ variable is defined as follows, on line 782:  
tbuffer = Gtk::TextBuffer.new(widget.buffer.tag\_table)

It doesn’t always happen, either. At first, this code worked great. As  
the program got larger and larger, these segmentation faults started  
becoming more and more frequent. Recently, it is getting to where I can  
hardly run the program without running into a segmentation fault.

Is there anything that I can do about this? Alternatively, is it  
possible to simply search a text buffer using a regular expression (IE,  
via the #forward\_search function)? I suppose I could just insert the  
text into the main buffer without the temporary buffer and attempt to  
manipulate it there, but that would be… troublesome. Considering that  
this code seems to work intermittently, I’m wondering if this is  
something of a bug in GTK.

- Andrew S.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [March 19, 2008, 3:06pm UTC](https://www.ruby-forum.com/t/temporary-textbuffer-causing-segmentation-faults/131936/2 "2008-03-19T15:06:36Z")

</div>

Andrew S. wrote:

> Lines 959 to 963 are:  
> if (widget.buffer.end\_iter.class == Gtk::TextIter and  
> tbuffer.start\_iter.class == Gtk::TextIter and tbuffer.end\_iter.class ==  
> Gtk::TextIter)  
> widget.buffer.insert\_range(widget.buffer.end\_iter, tbuffer.start\_iter,  
> tbuffer.end\_iter)  
> end

Can you provide a complete test program? This will make it easier for  
the developers to check the cause.

Thanks!
