-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
extmod/uctypes: fix addressof when returning large values #16440
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
extmod/uctypes: fix addressof when returning large values #16440
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #16440 +/- ##
=======================================
Coverage 98.57% 98.57%
=======================================
Files 164 164
Lines 21349 21349
=======================================
Hits 21045 21045
Misses 304 304 ☔ View full report in Codecov by Sentry. |
extmod/moductypes.c
Outdated
@@ -602,7 +602,7 @@ static mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) { | |||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS); | |||
if (agg_type == PTR) { | |||
byte *p = *(void **)self->addr; | |||
return mp_obj_new_int((mp_int_t)(uintptr_t)p); | |||
return mp_obj_new_int_from_uint((mp_int_t)(uintptr_t)p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return mp_obj_new_int_from_uint((mp_int_t)(uintptr_t)p); | |
return mp_obj_new_int_from_uint((uintptr_t)p); |
(Takes out the unnecessary and maybe-UB-although-realistically-not cast.)
I ran into this last week testing #16311 V2 changes on qemu where the RAM range is quite high in the 32-bit space.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I hit this on qemu as well, testing #8381, which checks the address of ROMFS files are within the address of the ROMFS itself.
Code size report:
|
extmod/moductypes.c
Outdated
@@ -602,7 +602,7 @@ static mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) { | |||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS); | |||
if (agg_type == PTR) { | |||
byte *p = *(void **)self->addr; | |||
return mp_obj_new_int((mp_int_t)(uintptr_t)p); | |||
return mp_obj_new_int_from_uint((mp_int_t)(uintptr_t)p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return mp_obj_new_int_from_uint((mp_int_t)(uintptr_t)p); | |
return mp_obj_new_int_from_uint((uintptr_t)p); |
Probably don't need the 2nd cast since the parameter type is mp_uint_t
already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, I'm too slow, Angus beat me to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two out of two reviewers agree! 😁
This was split out from #8381. |
So they don't return a negative number for an address (prior to this fix they would return negative addresses for values that were larger than the maximum small-int value). Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
cc2ea4c
to
d10cda6
Compare
Thanks for the quick review! I made the recommended change. It should be fine, because |
Summary
This fixes
uctypes.addressof()
so it always returns positive values.Prior to this fix it would return negative addresses for values that were larger than the maximum small-int value.
Testing
Test added as part of this PR which runs under CI. Also tested on PYBD_SF6 (test failed prior to the fix here, now passes).