Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you just specify that a < INT_MAX/2 and b < INT_MAX/2, you are fine.

If not (and you are providing a general purpose addition), then you need a big number library.



You can also overflow by adding two large enough negative numbers.

    /tmp/file.c:2:[kernel] warning: signed overflow. assert -2147483648 ≤ i+j;
    /tmp/file.c:2:[kernel] warning: signed overflow. assert i+j ≤ 2147483647;
(tis-analyzer)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: