[klibc] large C objects (was Re: [Git][kernel-team/klibc][master] 45 commits: 2.0.8 released, next version is 2.0.9)

Thorsten Glaser tg at debian.org
Sun Dec 26 17:50:12 PST 2021


Ben Hutchings (@benh) dixit:

>Further, it's not legal for a C object to be larger than
>PTRDIFF_MAX (half of SIZE_MAX) as pointer arithmetic within it could
>overflow.  So return failure immediately if size is greater than that.

Not exactly. The problem is >PTRDIFF_MAX *elements* but an element
isn’t necessarily byte-sized, so you _can_ have an unsigned short
object that’s larger than half SIZE_MAX bytes but ≤PTRDIFF_MAX
elements so pointer arithmetics will still work.

Unsure if it’s a good idea in general to restrict allocation like
this. It probably is for klibc, admittedly. But this got me wondering.

Please do correct me, should I be wrong above.

bye,
//mirabilos
-- 
“It is inappropriate to require that a time represented as
 seconds since the Epoch precisely represent the number of
 seconds between the referenced time and the Epoch.”
	-- IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2



More information about the klibc mailing list