size_sub(9)
π size_sub(9) π
okay so bestie, welcome to the Kernel API Manual entry for size_sub β yes, we're doing kernel math today, and no, it's not scary, i promise. this whole page is literally just "subtract two numbers but don't let it wrap around and ruin your life." iconic behaviour, honestly β¨
π NAME π
size_sub β Calculate size_t subtraction with saturation at SIZE_MAX.
like, it's a subtraction, but make it safe. π
π¦ SYNOPSIS π¦
size_t size_sub (size_t minuend , size_t subtrahend );
that's it. two arguments, one size_t back. clean, tiny, slays. π
πΈ ARGUMENTS πΈ
minuendβ the value you're subtracting from. the main character of this operation, lowkey. πsubtrahendβ the value you're subtracting fromminuend. the one doing the taking. π
β RETURN β
so it calculates minuend - subtrahend, with both of them promoted to size_t, and if there's any overflow the return value just becomes SIZE_MAX. no cap, it saturates. π«Ά
and here's the important bit, bestie, listen up π β for composition with the size_add and size_mul helpers, neither argument may be SIZE_MAX (or the result will be forced to SIZE_MAX). fr fr, don't do it. π
also: the lvalue must be size_t to avoid implicit type conversion. like, keep your types honest, okay? the vibe check on your variable types matters. π
π₯ SEE ALSO π₯
Kernel file ./include/linux/overflow.h β and the whole overflow bestie squad:
check_add_overflow(9)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)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)
like, that's a whole friend group and they all ate. ππ§
ngl, if you're doing subtraction on sizes in the kernel without checking overflow, this page is your sign from the universe to stop. π
and that's the whole page, bestie!! π this one lives in ./include/linux and it's dated October 2026 β so like, whenever you're reading this, it's giving timeless. mwah, go forth and subtract safely. ππ¦β¨
π¦ 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