# Help: Bus Error when 'splitting' a String

**URL:** <https://www.ruby-forum.com/t/help-bus-error-when-splitting-a-string/72733>\
**Category:** Ruby\
**Created:** [October 18, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/help-bus-error-when-splitting-a-string/72733 "2006-10-18T16:26:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![diego\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@diego\_v](https://www.ruby-forum.com/u/diego_v)\
**Post date:** [October 18, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/help-bus-error-when-splitting-a-string/72733/1 "2006-10-18T16:26:29Z")

</div>

Hello,  
I’m currently trying to run a little script but I am stuck with this  
error… which I can’t decipher.

The error message says just: [BUG] Bus Error  
and with a few puts statements here and there I could work out it is  
caused by the line with the split method in the following code:

jobs.each {|job|  
outputFile = File.new(SCRIPT\_NAME+".o"+job.id.to\_s,“r”)  
outputStr = outputFile.read  
if(outputStr =~  
/#{STRING\_BEFORE\_RESULTS}((.|\n)\*)#{STRING\_AFTER\_RESULTS}/)  
job.results = $1.split(/\n+/)  
puts “Data gathered successfully from file  
“+SCRIPT\_NAME+”.o”+job.id.to\_s  
else  
puts “Program has failed to gather the data from file  
“+SCRIPT\_NAME+”.o”+job.id.to\_s  
end  
outputFile.close  
}

One of the reason why I am having so much difficult with this bug is  
that if jobs.size is 1 then it runs alright. The problem arises if  
jobs.size is 2 (or more): then it would run fine in the first iteration  
and fail in the second one.

I have also checked by adding a “puts $1” after the if(outputStr…  
line, that for both iterations $1 is actually the correct string.

Any idea???

Thanks in advance

Diego Virsaoro

---

<div class="post-metadata">

**Author:** ![diego\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@diego\_v](https://www.ruby-forum.com/u/diego_v)\
**Post date:** [October 18, 2006, 5:06pm UTC](https://www.ruby-forum.com/t/help-bus-error-when-splitting-a-string/72733/2 "2006-10-18T17:06:55Z")

</div>

Hi,

At Wed, 18 Oct 2006 23:25:13 +0900,  
Diego V. wrote in [ruby-talk:220421]:

> The error message says just: [BUG] Bus Error  
> and with a few puts statements here and there I could work out it is  
> caused by the line with the split method in the following code:

What’s the version and the platform? And debugger available?

---

<div class="post-metadata">

**Author:** ![diego\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@diego\_v](https://www.ruby-forum.com/u/diego_v)\
**Post date:** [October 18, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/help-bus-error-when-splitting-a-string/72733/3 "2006-10-18T17:33:31Z")

</div>

> > The error message says just: [BUG] Bus Error  
> > and with a few puts statements here and there I could work out it is  
> > caused by the line with the split method in the following code:
> 
> What’s the version and the platform? And debugger available?

I think (I don’t have access now) it is ruby 1.6.2 on Solaris 9.

Diego

---

<div class="post-metadata">

**Author:** ![diego\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@diego\_v](https://www.ruby-forum.com/u/diego_v)\
**Post date:** [October 19, 2006, 1:30pm UTC](https://www.ruby-forum.com/t/help-bus-error-when-splitting-a-string/72733/4 "2006-10-19T13:30:52Z")

</div>

> At Wed, 18 Oct 2006 23:25:13 +0900,  
> Diego V. wrote in [ruby-talk:220421]:
> 
> > The error message says just: [BUG] Bus Error  
> > and with a few puts statements here and there I could work out it is  
> > caused by the line with the split method in the following code:
> 
> What’s the version and the platform? And debugger available?

Hi, I got more information now.

ruby -v give this: ruby 1.6.4 (2001-06-04) [sparc-solaris2.9]

Also, I have narrowed down the bug a little further, I think. It seems  
that the splitting is actually fine, but it’s the subsequent assignment  
to job.results which is the problem.

Oh, and using the debbuger there seem to be no problem. In fact from  
time to time it crashes on a different iteration of the loop (but  
predominantly it crashes in the second one).

Any idea? Any info you can give would be very appreciated. In fact, I  
apologize for the newbie question, but what is a bus error? Is it a  
memory problem?

Diego

---

<div class="post-metadata">

**Author:** ![diego\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@diego\_v](https://www.ruby-forum.com/u/diego_v)\
**Post date:** [October 24, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/help-bus-error-when-splitting-a-string/72733/5 "2006-10-24T19:10:19Z")

</div>

Hi,

At Thu, 19 Oct 2006 20:30:07 +0900,  
Diego V. wrote in [ruby-talk:220608]:

> Any idea? Any info you can give would be very appreciated. In fact, I  
> apologize for the newbie question, but what is a bus error? Is it a  
> memory problem?

Upgrade to 1.8.5, or 1.6.8 at least.
