From: Eric Pouech eric.pouech@gmail.com
GCC 12 complains about accessing a too small object.
In function 'test__AdjustPointer', inlined from 'func_msvcr90' at wine/dlls/msvcr90/tests/msvcr90.c:2515:5: wine/dlls/msvcr90/tests/msvcr90.c:1556:30: warning: array subscript 30 is outside array bounds of 'void[8]' [-Warray-bounds] 1556 | {&obj1, (char*)&obj1 + obj.off, {0, 0, 0}}, | ~~~~~~~~~~~~~^~~~~~~~~
Since we're only checking the addresses and not the underlying objects, use uintptr_t instead of pointers.
Signed-off-by: Eric Pouech eric.pouech@gmail.com --- dlls/msvcr90/tests/msvcr90.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/dlls/msvcr90/tests/msvcr90.c b/dlls/msvcr90/tests/msvcr90.c index 0d28df217ab..cdc9de0d6d2 100644 --- a/dlls/msvcr90/tests/msvcr90.c +++ b/dlls/msvcr90/tests/msvcr90.c @@ -1542,28 +1542,28 @@ static void test__AdjustPointer(void) void *obj1 = &obj.off; void *obj2 = &obj; struct test_data { - void *ptr; - void *ret; + uintptr_t ptr; + uintptr_t ret; struct { int this_offset; int vbase_descr; int vbase_offset; } this_ptr_offsets; } data[] = { - {NULL, NULL, {0, -1, 0}}, - {(void*)0xbeef, (void*)0xbef0, {1, -1, 1}}, - {(void*)0xbeef, (void*)0xbeee, {-1, -1, 0}}, - {&obj1, (char*)&obj1 + obj.off, {0, 0, 0}}, - {(char*)&obj1 - 5, (char*)&obj1 + obj.off, {0, 5, 0}}, - {(char*)&obj1 - 3, (char*)&obj1 + obj.off + 24, {24, 3, 0}}, - {(char*)&obj2 - 17, (char*)&obj2 + obj.off + 4, {4, 17, sizeof(int)}} + {0, 0, {0, -1, 0}}, + {0xbeef, 0xbef0, {1, -1, 1}}, + {0xbeef, 0xbeee, {-1, -1, 0}}, + {(uintptr_t)&obj1, (uintptr_t)&obj1 + obj.off, {0, 0, 0}}, + {(uintptr_t)&obj1 - 5, (uintptr_t)&obj1 + obj.off, {0, 5, 0}}, + {(uintptr_t)&obj1 - 3, (uintptr_t)&obj1 + obj.off + 24, {24, 3, 0}}, + {(uintptr_t)&obj2 - 17, (uintptr_t)&obj2 + obj.off + 4, {4, 17, sizeof(int)}} }; void *ret; int i;
for(i=0; i<ARRAY_SIZE(data); i++) { - ret = p__AdjustPointer(data[i].ptr, &data[i].this_ptr_offsets); - ok(ret == data[i].ret, "%d) __AdjustPointer returned %p, expected %p\n", i, ret, data[i].ret); + ret = p__AdjustPointer((void*)data[i].ptr, &data[i].this_ptr_offsets); + ok(ret == (void*)data[i].ret, "%d) __AdjustPointer returned %p, expected %p\n", i, ret, (void*)data[i].ret); } }
From: Eric Pouech eric.pouech@gmail.com
GCC 12 complains with: wine/dlls/msvcrt/tests/cpp.c: In function 'test_rtti': wine/dlls/msvcrt/tests/cpp.c:1036:45: warning: array subscript 2 is outside array bounds of 'void[4]' [-Warray-bounds] 1036 | ok (casted == (char*)&child_class_sig0+8, "failed cast to simple_class (%p %p)\n", casted, &child_class_sig0); | ~~~~~~~~~~~~~~~~~~~~~~~~^~
As we're only testing the addresses and not the underlying objects, use uintptr_t instead of pointers.
Signed-off-by: Eric Pouech eric.pouech@gmail.com --- dlls/msvcrt/tests/cpp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcrt/tests/cpp.c b/dlls/msvcrt/tests/cpp.c index b2b6a1909b7..ada10060598 100644 --- a/dlls/msvcrt/tests/cpp.c +++ b/dlls/msvcrt/tests/cpp.c @@ -1033,7 +1033,7 @@ static void test_rtti(void) casted = p__RTDynamicCast(&child_class_sig0, 0, NULL, simple_class_sig0_rtti.type_info, 0); if(casted) { - ok (casted == (char*)&child_class_sig0+8, "failed cast to simple_class (%p %p)\n", casted, &child_class_sig0); + ok (casted == (char*)((uintptr_t)&child_class_sig0+8), "failed cast to simple_class (%p %p)\n", casted, &child_class_sig0); }
casted = p__RTDynamicCast(&child_class_sig0, 0, &child_class_sig0_rtti.type_info[0], &child_class_sig0_rtti.type_info[1], 0); @@ -1059,7 +1059,7 @@ static void test_rtti(void) casted = p__RTDynamicCast(&child_class, 0, NULL, simple_class_rtti.type_info, 0); if(casted) { - ok (casted == (char*)&child_class+8, "failed cast to simple_class (%p %p)\n", casted, &child_class); + ok (casted == (char*)((uintptr_t)&child_class+8), "failed cast to simple_class (%p %p)\n", casted, &child_class); }
casted = p__RTDynamicCast(&child_class, 0, &child_class_rtti.type_info[0], &child_class_rtti.type_info[1], 0);
Piotr Caban (@piotr) commented about dlls/msvcrt/tests/cpp.c:
casted = p__RTDynamicCast(&child_class_sig0, 0, NULL, simple_class_sig0_rtti.type_info, 0); if(casted) {
ok (casted == (char*)&child_class_sig0+8, "failed cast to simple_class (%p %p)\n", casted, &child_class_sig0);
ok (casted == (char*)((uintptr_t)&child_class_sig0+8), "failed cast to simple_class (%p %p)\n", casted, &child_class_sig0);
I think it's better to allocate the memory as in real class instance. Does something like [0001-tmp.txt](/uploads/eec7600b8daf35363dbd97b88a1e79c1/0001-tmp.txt) help?
On Tue Dec 6 11:09:51 2022 +0000, Piotr Caban wrote:
I think it's better to allocate the memory as in real class instance. Does something like [0001-tmp.txt](/uploads/eec7600b8daf35363dbd97b88a1e79c1/0001-tmp.txt) help?
Hi Piotr. Yes, it does. gcc doesn't warn with 0001-tmp.txt applied.
On Tue Dec 6 13:38:24 2022 +0000, eric pouech wrote:
Hi Piotr. Yes, it does. gcc doesn't warn with 0001-tmp.txt applied.
Could you please update the MR with this change? FWIW the msvcr90 patch looks good for me (the tests there are more artificial and the object "changes" between tests).