develooper Front page | perl.perl5.porters | Postings from November 2017

[perl #132415] _MEM_WRAP_NEEDS_RUNTIME_CHECK (malloc wrapping) inhandy.h broken

Thread Next
From:
l.mai@web.de via RT
Date:
November 11, 2017 12:57
Subject:
[perl #132415] _MEM_WRAP_NEEDS_RUNTIME_CHECK (malloc wrapping) inhandy.h broken
Message ID:
rt-4.0.24-12888-1510405047-598.132415-15-0@perl.org
On Tue, 07 Nov 2017 16:31:51 -0800, mauke- wrote:
> 
> In handy.h there is this piece of code:
> 
> #  define _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) \
>     (8 * sizeof(n) + sizeof(t) > sizeof(MEM_SIZE))
> 
> A comment claims:
> 
> * It's mathematically equivalent to
> *    max(n) * sizeof(t) > MEM_SIZE_MAX
> 
> This is false because _MEM_WRAP_NEEDS_RUNTIME_CHECK currently always
> returns
> true (it's broken).
> 
> It was lasted touched in commit
> 004073bac990d90244eb463f435c52d4040b36df
> "Simplify _MEM_WRAP_NEEDS_RUNTIME_CHECK()".
> 
> The old version was:
> 
> #  define _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) \
>     (  sizeof(MEM_SIZE) < sizeof(n) \
>     || sizeof(t) > ((MEM_SIZE)1 << 8*(sizeof(MEM_SIZE) - sizeof(n))))

I have now reverted this commit in 445198b9b50e1018da1c98005a88bdf15c964f23.

I believe the new version could have been fixed by changing

    (8 * sizeof(n) + sizeof(t) > sizeof(MEM_SIZE))

to

    (8 * sizeof(n) + ILOG2(sizeof(t)) > 8 * sizeof(MEM_SIZE))

but then I'd have to define a macro to compute the integer log base 2 (rounded up) of sizeof(t) at compile time. This is possible but annoying (64 separate comparisons). It's also the opposite of a simplification.

So unless we really need to do that, I'd rather not.

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=132415

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About