Foundationপ্রথম নীতি থেকে
LEVEL 1 · How Computers Represent Information

Integer Overflow

ইন্টিজার ওভারফ্লো

সত্যিকারের গাণিতিক ফলাফল representation-এর সীমার বাইরে গেলে যা ঘটে — unsigned-এ সংজ্ঞায়িত wraparound, signed-এ C/C++-এ undefined behavior।

also: overflow

দুইটা সম্পূর্ণ ভিন্ন জগৎ, একই নাম দিয়ে ডাকা হয়:

Unsigned overflow — [[modular-arithmetic]]-এর সংজ্ঞা অনুযায়ী mod 2ⁿ — সবসময় পূর্বাভাসযোগ্য, প্রতিটা compiler-এ, প্রতিবার। 250 + 10 একটা uint8_t-তে সবসময় 4 (260 mod 256)।

Signed overflow — C/C++ স্ট্যান্ডার্ডে undefined behavior: ভাষা কোনো গ্যারান্টি দেয় না, আর optimizing compiler ধরেই নেয় এটা “কখনো ঘটে না” — এই অনুমানের ভিত্তিতে মানুষের লেখা overflow-check (যেমন if (x + 1 < x)) সম্পূর্ণ মুছে ফেলতে পারে।

বাস্তব বিপর্যয়: Ariane 5 (১৯৯৬, একটা 64-bit float-থেকে-16-bit- integer conversion overflow, পুরো রকেট ধ্বংস), Y2K38 (32-bit signed time_t ২০৩৮-এ overflow করবে)।

নিরাপদ policy তিনটা:

Policyআচরণকোথায়
Checkederror/None রিটার্নআর্থিক, security-critical
Wrappingসংজ্ঞায়িত mod ফেরতhash, ring buffer index
SaturatingMIN/MAX-এ clampaudio, pixel value, game health