정수 오버플로(integer overflow)는 계산 결과가 정수 자료형으로 표현할 수 있는 범위를 벗어나는 일이다. [[런타임]]이 사용하는 자료형의 크기와 언어의 연산 규칙을 함께 봐야 한다. ([CERT C의 정수 연산 지침](https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/integers-int/int32-c/)) - 길이와 개수를 곱해 저장 공간을 구할 때는 결과가 표현 범위를 넘는지 확인한다. 입력값 각각이 허용 범위에 있어도 곱셈 결과는 넘칠 수 있다. ([곱셈과 메모리 크기](https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/integers-int/int32-c/)) - C의 일반적인 부호 있는 정수 오버플로는 정의되지 않은 동작이다. 가장 작은 음수로 돌아올 것이라고 가정하지 않는다. ([정의되지 않은 동작](https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/integers-int/int32-c/)) - 계산 후 결과를 검사하기 전에 이미 문제가 생길 수 있다. 연산 전에 범위를 확인하거나 오류를 알리는 [[검사 산술]]을 사용한다. ([범위 검사와 안전한 연산](https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/integers-int/int32-c/)) ## 기타 등등 - 가장 작은 부호 있는 정수에 음수 부호를 붙이는 연산도 표현 범위를 넘길 수 있다. [출처](https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/integers-int/int32-c/) - Python의 정수는 고정된 비트 수에 묶이지 않는 정밀도를 제공한다. 다만 메모리와 일부 문자열 변환 제한까지 사라지는 것은 아니다. [출처](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) #프로그래밍 #수학 #데이터