Integer Overflow

Integer overflows occur when a computation results in a value outside the range of the data type.

In some cases, the result may wrap around and produce a negative value when adding positive integers or vice versa.

#include <stdio.h>
int main() {
    long a = -9223372036854775808;
    long b = -1;
    long c = a / b;     // overflow => crash
    printf("%ld\n", c); // not called
}
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
    unsigned char arg_len = strlen(argv[1]) + 5;
    if (arg_len < 5) // 251 + 5 => 256 => 0 to bypass the check
        printf("You won!");
}
#include <stdio.h>

int main() {
    unsigned int money = 0;
    printf("$%u\n", money); // $0
    money -= 1;
    if (money <= 0) {       // Not executed
        printf("You lost $1");
    }
    printf("$%u\n", money); // $4294967295
}