A bunch of examples to get away from the brain ache. I'm basically re-writing o0ragman0o's answer. If my answer makes sense, maybe accept his answer instead :)
First example, with no overflow occurring:
uint8 a = 255;
uint8 b = 0;
Then c = 255 + 0 which is 255.
assert(c >= a); // SUCCESS as 255 is equal to a.
Increase the value of b
to create an overflow:
uint8 a = 255;
uint8 b = 1;
Then c = 255 + 1 which is 0.
assert(c >= a); // FAILS because 0 is not greater or equal to 255.
Swap a
and b
around to show it still works:
uint8 a = 1;
uint8 b = 255;
Then c = 1 + 255 which, again, is 0.
assert(c >= a); // FAILS because 0 is not greater or equal to 1.
Increase the amount we're overflowing by - increase a
by 1:
uint8 a = 2;
uint8 b = 255;
Then c = 2 + 255 which is 1.
assert(c >= a); // FAILS because 1 is not greater or equal to 2.
This third example helps show how the number created by the overflow will always be less than either of the constituent parts, meaning we need check only one of them.