title: Signed integer overflow
body: <p>Below in source code (I've commented the error on code), I get</p>
  <blockquote>
  <p>Line 27: Char 33: runtime error: signed integer overflow: -1094795586+ -1094795586 cannot be represented in type 'int'</p>
  </blockquote>
  <p>I've consulted different articles, like <a href="https://stackoverflow.com/questions/3944505/detecting-signed-overflow-in-c-c">How to detected signed integer overflow</a> but I'm not getting which integer to check.<br>
  Elements of <code>working_array[]</code> are filtered from <code>nums[]</code> if their value is less than <code>target</code> integer.<br>
  Since the elements of <code>nums[]</code> are like <code>[ 3, 6, 11, 19, 2, ...]</code> I'm not worried to checking for overflow during SUM on the last <code>if</code> statement. I'm wrong?</p>
  <pre><code>int* twoSum(int* nums, int numsSize, int target, int* returnSize){
      int count_elem = 0;
      int *working_array = (int*)malloc(numsSize * sizeof(int));
      
      // Going through original array
      for(int i=0;i&lt;numsSize;i++){
          
          // If elem nums[i] is less than target, is accepted on a new working array
          if(nums[i] &lt; target){
              count_elem += 1;
              working_array[count_elem] = nums[i];            
          }        
      }
  
      working_array = realloc(working_array, count_elem*sizeof(int));
      
      // Creating result array
      returnSize = sizeof(int)*2;
      int *result_array = (int*)malloc(returnSize);
  
      // Going through working array
      for(int i=0;i&lt;count_elem;++i)
          for(int j=0;j&lt;count_elem;++j)
  
              // SIGNED INTEGER OVERFLOW IN LINE BELOW
              if( (working_array[i]+working_array[j]) == target){
                  result_array[0] = working_array[i];
                  result_array[1] = working_array[j];
                  free(working_array);
                  return result_array;
              }
      
      free(working_array);
      return;
  }
  </code></pre>
  <p>P.S: I know that <a href="https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc">cast malloc results</a> is useless, but this is a minor issue maybe.</p>