0

I finished the binary search algorithm and I get an error Bus error (core dumped) when I try to test it using the generate tool which is given. However, it works fine when I input the haystacks myself. Here is the output (note that I am running this on my Kubuntu 15.04 Vivid Vervet partition and not the appliance):

pythonhax@pythonhax-KUBUNTU:~/Dropbox/CS50x/pset3/find$ ./generate 1000 50 | ./find 127

haystack[0] = 
haystack[1] = 
haystack[2] = 
haystack[3] = 
.
.
.
haystack[999] = 
haystack[1000]= 
Bus error (core dumped)
pythonhax@pythonhax-KUBUNTU:~/Dropbox/CS50x/pset3/find$

When I run the same program on the appliance, I get a similar problem (Segmentation fault (core dumped)):

jharvard@ubuntu:~/Dropbox/CS50x/pset3/find$ ./generate 1000 50 | ./find 127

haystack[0] = 
haystack[1] = 
haystack[2] = 
haystack[3] = 
.
.
.
haystack[999] = 
haystack[1000]= 
Segmentation fault (core dumped)
jharvard@ubuntu:~/Dropbox/CS50x/pset3/find$

What is going on here? It worked perfectly fine with linear search.

  • Did you try to debug it with GDB? Maybe try runnig with smaller haystack like ./generate 10 50 | ./find 127 and look at the proces with GDB – wallek876 Feb 1 '15 at 14:46
  • Seems to work with ./generate 500 50 | ./find 127. – pythonhax Feb 1 '15 at 14:57
  • I can't use more than 580 generated numbers, otherwise I get the Bus error. – pythonhax Feb 1 '15 at 14:58
  • Maybe is related to an invalid read or write, try running valgrind to see if it tells you what part of the code is causing it. – wallek876 Feb 1 '15 at 15:18

You must log in to answer this question.

Browse other questions tagged .