title: Stack smashing detected C++
body: <p>I am writing a little program. I have working build on my Windows. I rewrite exact copy of this program on my Ubuntu. But in Ubuntu i get stack smashing error every time i execute my program. In both OS i use Codeblocks IDE. Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  
  double max_elem(double a, double b)
  {
      if (a &lt;= b )
          return a;
      else return b;
  }
  double  min_elem(double a,double b)
  {
      if (a &gt;= b )
          return a;
      else return b;
  }
  double result (int pawn_v, int pawn_h, int knight_v, int knight_h)
  {
      double result_array[7];
      for (int i=0; i&lt;=7; i++)
          result_array[i] = 2;
      double a,b,c,d;
      pawn_h++;
  
      if (pawn_h&gt;8)
          return 1;
      else if ((pawn_v == knight_v + 2) &amp;&amp; (pawn_h == knight_h + 1))
          return -1;
      else if ((pawn_v == knight_v + 2) &amp;&amp; (pawn_h == knight_h - 1))
          return -1;
      else if ((pawn_v == knight_v - 2) &amp;&amp; (pawn_h == knight_h + 1))
          return -1;
      else if ((pawn_v == knight_v - 2) &amp;&amp; (pawn_h == knight_h - 1))
          return -1;
      else if ((pawn_v == knight_v + 1) &amp;&amp; (pawn_h == knight_h + 2))
          return -1;
      else if ((pawn_v == knight_v + 1) &amp;&amp; (pawn_h == knight_h - 2))
          return -1;
      else if ((pawn_v == knight_v - 1) &amp;&amp; (pawn_h == knight_h + 2))
          return -1;
      else if ((pawn_v == knight_v - 1) &amp;&amp; (pawn_h == knight_h - 2))
          return -1;
      else if ((pawn_v == knight_v) &amp;&amp; (pawn_h == knight_h))
          return (0.5f);
      else
      {
  
          result_array[0] = result(pawn_v, pawn_h, knight_v + 2, knight_h + 1);
  
          result_array[1] = result(pawn_v, pawn_h, knight_v + 2, knight_h - 1);
  
          result_array[2] = result(pawn_v, pawn_h, knight_v - 2, knight_h + 1);
  
          result_array[3] = result(pawn_v, pawn_h, knight_v - 2, knight_h - 1);
  
          result_array[4] = result(pawn_v, pawn_h, knight_v + 1, knight_h + 2);
  
          result_array[5] = result(pawn_v, pawn_h, knight_v - 1, knight_h + 2);
  
          result_array[6] = result(pawn_v, pawn_h, knight_v + 1, knight_h - 2);
  
          result_array[7] = result(pawn_v, pawn_h, knight_v - 1, knight_h - 2);
  
          a = max_elem(result_array[0],result_array[1]);
          b = max_elem(result_array[2],result_array[3]);
          c = max_elem(result_array[4],result_array[5]);
          d = max_elem(result_array[6],result_array[7]);
          return (max_elem(max_elem(a,b),max_elem(c,d)));
      }
  }
  int main()
  {
  
      char knight_start, pawn_start;
      int knight_start_horizontal, pawn_start_horizontal, knight_start_vertical, pawn_start_vertical;
  
      scanf("%c%d%*c%c%d%*c", &amp;pawn_start, &amp;pawn_start_horizontal, &amp;knight_start, &amp;knight_start_horizontal);
      knight_start_vertical = int(knight_start)-96;
      pawn_start_vertical = int(pawn_start)-96;
  
      if (pawn_start_horizontal==2) {
          if (min_elem(result(pawn_start_vertical,pawn_start_horizontal,knight_start_vertical,knight_start_horizontal),result(pawn_start_vertical,pawn_start_horizontal+1,knight_start_vertical,knight_start_horizontal))==0.5)
              printf("%.1f", 0.5);
          else printf("%0.f",min_elem(result(pawn_start_vertical,pawn_start_horizontal,knight_start_vertical,knight_start_horizontal),result(pawn_start_vertical,pawn_start_horizontal+1,knight_start_vertical,knight_start_horizontal)));
      }
      else
      {
          if (result(pawn_start_vertical,pawn_start_horizontal,knight_start_vertical,knight_start_horizontal)==0.5)
              printf("%.1f",0.5);
          else printf("%.0f", result(pawn_start_vertical,pawn_start_horizontal,knight_start_vertical,knight_start_horizontal));
      }
      return 0;
  }
  </code></pre>
  
  <p>How can i prevent this error?</p>