title: terminated by signal SIGSEGV (Address boundary error) in recursive function
body: <p>I'm trying to implement Karatsuba algorithm for multiplication. I'm kinda follow the pseudocode in this wiki <a href="https://en.wikipedia.org/wiki/Karatsuba_algorithm#Pseudocode" rel="nofollow" title="page">page</a>. But I'm always getting this error:</p>
  
  <blockquote>
    <p>terminated by signal SIGSEGV (Address boundary error)</p>
  </blockquote>
  
  <p>When I replaced the lines that cause the recursion to happen with something else:</p>
  
  <pre><code>z0 = multiply(a, c);
  z1 = multiply(b, d);
  z2 = multiply(a+b, c+d);
  </code></pre>
  
  <p>the error disappeared.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;math.h&gt;
  
  long int multiply(int x, int y);
  int get_length(int val);
  
  int main()
  {
    int x = 0, y = 0;
    long int result = 0;
  
    std::cout &lt;&lt; "Enter x: ";
    std::cin &gt;&gt; x;
    std::cout &lt;&lt; "Enter y: ";
    std::cin &gt;&gt; y;
  
    result = multiply(x, y);
    std::cout &lt;&lt; "Result: " &lt;&lt; result &lt;&lt; std::endl;
    return 0;
  }
  
  long int multiply(int x, int y)
  {
    if(x &lt; 10 || y &lt; 10) {
      return x * y;
    }
  
    int x_len = get_length(x);
    int y_len = get_length(y);
  
    long int z0 = 0 , z1 = 0, z2 = 0;
    int a = 0, b = 0, c = 0, d = 0;
  
    a = x / pow(10, x_len);
    b = x - (a * pow(10, x_len));
    c = y / pow(10, y_len);
    d = y - (c * pow(10, y_len));
  
    z0 = multiply(a, c);
    z1 = multiply(b, d);
    z2 = multiply(a+b, c+d);
  
    return (pow(10, x_len) * z0) + (pow(10, x_len/2) * (z2 - z1 - z0)) + z1;
  }
  
  int get_length(int val)
  {
    int count = 0;
    while(val &gt; 0) {
      count++;
      val /= 10;
    }
    return count;
  }
  </code></pre>