size_sub(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 from minuend. 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:

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