I recently learned that integer overflow is an undefined behavior in C (side question - is it also UB in C++?)
Often in C programming you need to find the average of two
If you are concerned about overflow, you could cast the values to a larger type to perform the math, and then do the bounds checking.