range_ptrinbuf(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– range_ptrinbuf(3) πŸ’–

okay bestie, so this one lives in the Library Functions Manual and it's lowkey one of those tiny functions that saves your whole entire program from vibing straight off a cliff 🫢


✨ NAME ✨

range_ptrinbuf β€” range check pointer in buffer 🎯


✨ SYNTAX ✨

#include <libowfat/rangecheck.h>

int range_ptrinbuf(const void* buf,size_t len,const void* ptr);

✨ DESCRIPTION ✨

so the whole girlboss job of range_ptrinbuf is literally just this: it checks if ptr points to buf[0..len-1]. that's it. that's the function. she's not doing your taxes, she's doing a vibe check on a pointer πŸ’…

like... is this pointer actually inside the buffer, or is it out here living its truth in undefined-behaviour land? she'll tell you. no cap. ✨


✨ RETURN VALUE ✨

she's giving a very simple yes/no situation, here's the tea:

  • if the buffer is implausible β€” meaning buf is NULL, or buf+len has an integer overflow 😭 β€” she returns 0.
  • if ptr points to one of buf[0], buf[1], ... or buf[len-1], she returns 1 πŸ‘‘
  • otherwise, she returns 0 πŸ’€
fr fr, that overflow case is the main character of this whole function. a buffer that wraps around is not a buffer, bestie, and she's not about to pretend otherwise.

✨ SEE ALSO ✨


and that's the whole page, gorgeous πŸ’– it's range_ptrinbuf(3) from the Library Functions Manual, and the footer said range_ptrinbuf(3) too, so... yeah she's literally signed her own name at the bottom, iconic behaviour honestly πŸŽ€βœ¨ slay, go range check something πŸ¦‹