New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_MEM_WRAP_NEEDS_RUNTIME_CHECK (malloc wrapping) in handy.h broken #16231
Comments
From @maukeCreated by @maukeIn handy.h there is this piece of code: # define _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) \ A comment claims: * It's mathematically equivalent to This is false because _MEM_WRAP_NEEDS_RUNTIME_CHECK currently always returns It was lasted touched in commit 004073b The old version was: # define _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) \ I don't understand the new version, so I wrote a little C program to compare ( uchar, char ) max(1) * 1 > UINT4_MAX? | old:no | new:yes | expected:no (!) Perl Info
|
From @maukeOn Tue, 07 Nov 2017 16:31:51 -0800, mauke- wrote:
Code attached. |
From @mauke#include <stdio.h>
#include <limits.h>
#include <stdint.h>
#ifndef MEM_SIZE
#define MEM_SIZE size_t
#endif
#define MEM_SIZE_MAX ((MEM_SIZE)-1)
#define MEM_WRAP_NEEDS_RUNTIME_CHECK_1(n, t) \
( sizeof(MEM_SIZE) < sizeof(n) \
|| sizeof(t) > ((MEM_SIZE)1 << 8*(sizeof(MEM_SIZE) - sizeof(n))))
#define MEM_WRAP_NEEDS_RUNTIME_CHECK_2(n, t) \
(8 * sizeof(n) + sizeof(t) > sizeof(MEM_SIZE))
#define ACTUALLY_OVERFLOWS(n, t) \
((n) > MEM_SIZE_MAX / sizeof(t))
#define TRY_WITH2(n, t) \
printf("(%6s, %-15s) max(%zu) * %5zu > UINT%zu_MAX? | old:%-3s | new:%-3s | expected:%-3s %s\n", \
#n, #t, \
sizeof (n), sizeof (t), \
sizeof (MEM_SIZE), \
MEM_WRAP_NEEDS_RUNTIME_CHECK_1(n, t) ? "yes" : "no", \
MEM_WRAP_NEEDS_RUNTIME_CHECK_2(n, t) ? "yes" : "no", \
ACTUALLY_OVERFLOWS(n, t) ? "yes" : "no", \
MEM_WRAP_NEEDS_RUNTIME_CHECK_1(n, t) != ACTUALLY_OVERFLOWS(n, t) || \
MEM_WRAP_NEEDS_RUNTIME_CHECK_2(n, t) != ACTUALLY_OVERFLOWS(n, t) ? "(!)" : "")
#define TRY_WITH(t) \
do { \
const unsigned char uchar = UCHAR_MAX; \
const unsigned short ushort = USHRT_MAX; \
const unsigned int uint = UINT_MAX; \
const unsigned long ulong = ULONG_MAX; \
const unsigned long long ullong = ULLONG_MAX; \
TRY_WITH2(uchar, t); \
TRY_WITH2(ushort, t); \
TRY_WITH2(uint, t); \
TRY_WITH2(ulong, t); \
TRY_WITH2(ulong, t); \
TRY_WITH2(ullong, t); \
} while (0)
int main(void) {
TRY_WITH(char);
TRY_WITH(char [2]);
TRY_WITH(char [0xffff]);
TRY_WITH(char [0xffff+1]);
}
|
From @maukeOn Tue, 07 Nov 2017 16:31:51 -0800, mauke- wrote:
I have now reverted this commit in 445198b. 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. |
From @iabynOn Sat, Nov 11, 2017 at 04:57:27AM -0800, l.mai@web.de via RT wrote:
I belatedly agree with your analysis. I clearly had a brain fart that -- |
The RT System itself - Status changed from 'new' to 'open' |
From @khwilliamsonOfflist On 03/06/2018 06:08 AM, Dave Mitchell wrote:
I'm glad to find out that happens to younger people than me, too. |
From @demerphqOn 6 March 2018 at 16:21, Karl Williamson <public@khwilliamson.com> wrote:
Happens to the younger folks more probably, shorter attention sp Ooh! Look! A butterfly! Yves -- |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#132415 (status was 'resolved')
Searchable as RT132415$
The text was updated successfully, but these errors were encountered: