check_add_overflow(9)
π check_add_overflow(9) β the kernel API manual, but make it make sense
okay so bestie, welcome to the check_add_overflow page of the Kernel API Manual β¨ this one is short, sweet, and honestly kind of iconic. it does exactly one thing and it does it well. let's get into it π«Ά
πΈ NAME
check_add_overflow β calculate addition with overflow checking π
like, it adds two things and it also tells you if the addition went sideways. multitasking queen behavior.
β¨ SYNOPSIS
check_add_overflow (a , b , d );
that's it. three little args. no cap. π
π¦ ARGUMENTS
aβ first addend πΈ (the first number going into the addition, bestie)bβ second addend π (the other number, obviously)dβ pointer to store sum β¨ (not the sum itself! a pointer to where the sum lives. do not come for me about it)
π₯ DESCRIPTION
Returns true on wrap-around, false otherwise. literally that's the whole personality π
and here's the part you cannot skip, so pay attention:
*d holds the results of the attempted addition, regardless of whether wrap-around occurred.
like. even if the addition wrapped around and everything went to chaos, *d still gets written. so don't go thinking "oh it returned true so *d is garbage" β nope, *d is populated either way, and it's on you to check the return value. main character responsibility π§
π SEE ALSO
okay this is the part where the whole friend group shows up. all of these live in the kernel file ./include/linux/overflow.h and honestly the roster is giving family reunion π
wrapping_add(9)wrapping_assign_add(9)check_sub_overflow(9)wrapping_sub(9)wrapping_assign_sub(9)check_mul_overflow(9)wrapping_mul(9)check_shl_overflow(9)overflows_type(9)range_overflows(9)range_overflows_t(9)range_end_overflows(9)range_end_overflows_t(9)castable_to_type(9)size_mul(9)size_add(9)size_sub(9)array_size(9)array3_size(9)flex_array_size(9)struct_size(9)struct_size_t(9)struct_offset(9)__DEFINE_FLEX(9)_DEFINE_FLEX(9)DEFINE_RAW_FLEX(9)DEFINE_FLEX(9)STACK_FLEX_ARRAY_SIZE(9)typeof_flex_counter(9)overflows_flex_counter_type(9)__set_flex_counter(9)
every single one of them, no skips, no cuts, we support the whole squad π
quick vibe check reminder: this is the checking variant. it tells you about the wrap-around. if you just want the wrap-around with no questions asked, that's what the wrapping_* crew is for. iykyk π
and that's the page, bestie π this came from the ./include/linux corner of the source tree, dated October 2026, and it's filed under check_add_overflow(9) β go forth and check your overflows, you gorgeous little integer wrangler π¦π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms