ssize_t mid = (n1 + n2) / 2;
if ((n1 + n2) % 2)
For extremely large inputs, these sums could overflow. Since this is signed arithmetic, that's Undefined Behaviour.
For the first, we can now use sd::midpoint; if stuck with C++17 or earlier, then n1 + (n2-n1) / 2 is a safe alternative, since we know they are both positive.
For the second, we could compare ...