title: Killed by signal 11(SIGSEGV) and/or 6(SIGABRT)
body: <p>I'm having this slight issue with my program. In Visual Studio 2012 it runs fine, but if I compile it with G++ (yes, for reasons above me, I have to use it to compile), the error signals 11(SIGSEGV) or 6(SIGABRT) get triggered depending on the input. This is a programming excercise and I have another program (on an online server) which tests my program with 10 different inputs. As I said, the program compiles and works well while using Visual Studio 2012.</p>
  
  <p>About the program:
  It finds the shortest path from starting point (x,y) to a number of exits (the amount of exits are irrelevant and differ. There could be only 1 exit or there could be 200).
  The input goes as follows:</p>
  
  <pre><code>7 12          // maze height and width
  ##########.#  //
  #..........#  //
  #.###.######  //
  #..X#.#.....  // the maze blueprint
  #.###.#.####  //
  #..........#  //
  ############  //
  </code></pre>
  
  <p>And my program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  typedef struct _laby_t {
      int h, w;
      char **pohja; // 'pohja' is finnish and means layout
  } laby_t;
  
  typedef std::vector&lt;int&gt; monovector;
  typedef std::vector&lt; std::vector&lt;int&gt; &gt; bivector;
  
  laby_t *laby_allocate (int r, int c)
  {
      laby_t *laby;
      int i;
  
      laby = new laby_t[sizeof (laby_t)];
      laby-&gt;pohja = new char *[r];
      for (i = 0; i &lt; r; i++)
      {
          laby-&gt;pohja[i] = new char[c];
      }
      laby-&gt;h = r;
      laby-&gt;w = c;
  
      return laby;
  }
  
  int wander(int y, int x, laby_t *&amp;_laby, int goals)
  {
      laby_t *laby = _laby;
      int found = 0, depth = 0, min_path = 1000000;
      bool b = 0;
      bivector openList;
      monovector start; start.push_back(y); start.push_back(x);
      bivector closedList;
  
      openList.push_back(start);
  
      while(found &lt; goals)
      {
  
          y = openList.back()[0]; x = openList.back()[1];
          monovector r; r.push_back(y); r.push_back(x); closedList.push_back(r);
          openList.pop_back();
          if(laby-&gt;pohja[y][x] != '*') laby-&gt;pohja[y][x] = '-';
          depth++;
  
          if(y == 0 || y+1 == laby-&gt;h || x == 0 || x+1 == laby-&gt;w) {
              found++;
              if(depth &lt; min_path) min_path = depth;
              if(found &gt;= goals) {
                  std::cout &lt;&lt; min_path &lt;&lt; std::endl;
                  break;
              }
              laby-&gt;pohja[y][x] = '-';
  
              goto back_track;
          }
          else
          {
              b = 0;
              if(laby-&gt;pohja[y+1][x  ] == '.') { monovector r; r.push_back(y+1); r.push_back(x); openList.push_back(r); b=1; }
              if(laby-&gt;pohja[y  ][x+1] == '.') { monovector r; r.push_back(y); r.push_back(x+1); openList.push_back(r); b=1; }
              if(laby-&gt;pohja[y-1][x  ] == '.') { monovector r; r.push_back(y-1); r.push_back(x); openList.push_back(r); b=1; }
              if(laby-&gt;pohja[y  ][x-1] == '.') { monovector r; r.push_back(y); r.push_back(x-1); openList.push_back(r); b=1; }
              if(!b)
              {
  back_track:     while(closedList.size() &gt; 0)
                  {
                      //std::cout &lt;&lt; closedList.size() &lt;&lt; std::endl;
                      int c_y = closedList.back()[0]; int c_x = closedList.back()[1];
                      int o_y = openList.back()[0];   int o_x = openList.back()[1];
  
                      laby-&gt;pohja[y][x] = '*';
  
                      y = c_y; x = c_x;
  
                      laby-&gt;pohja[y][x] = '*';
  
                      if( (c_y+1 == o_y &amp;&amp; c_x   == o_x) ||
                          (c_y   == o_y &amp;&amp; c_x+1 == o_x) ||
                          (c_y-1 == o_y &amp;&amp; c_x   == o_x) ||
                          (c_y   == o_y &amp;&amp; c_x-1 == o_x) )
                      {
                          laby-&gt;pohja[y][x] = '-';
                          y = o_y; x = o_x;
                          closedList.pop_back();
                          depth--;
                          break;
                      }
                      else {
                          closedList.pop_back();
                          depth--;
                      }
                  }
              }
          }
      }
  
      return min_path;
  }
  
  int main()
  {
      int h, w, goals = 0;
      std::cin &gt;&gt; h &gt;&gt; w;
  
      laby_t *laby;
      laby = laby_allocate(h, w);
  
      for(int i = 0; i &lt; laby-&gt;h; i++)
          std::cin &gt;&gt; laby-&gt;pohja[i];
  
      for(int i = 1; i &lt; laby-&gt;h-1; i++) {
          if(laby-&gt;pohja[i][0] == '.') goals++;
          if(laby-&gt;pohja[i][laby-&gt;w-1] == '.') goals++;
      }
  
      for(int i = 1; i &lt; laby-&gt;w-1; i++) {
          if(laby-&gt;pohja[0][i] == '.') goals++;
          if(laby-&gt;pohja[laby-&gt;h-1][i] == '.') goals++;
      }
  
      for(int i = 0; i &lt; laby-&gt;h; i++)
          for(int j = 0; j &lt; laby-&gt;w; j++) {
              if(laby-&gt;pohja[i][j] == 'X') {
                  wander(i, j, laby, goals);
                  goto _exit;
              }
          }
  
  _exit:
  
      //system("pause");
      return 0;
  }
  </code></pre>
  
  <p>I have done my homework concerning the errorsignals, and in case you guys don't know about it: <a href="http://www.yolinux.com/TUTORIALS/C++Signals.html" rel="nofollow">http://www.yolinux.com/TUTORIALS/C++Signals.html</a></p>
  
  <p>Thanks in advance.</p>