Stream: general

Topic: Slice wraps around address space


Jethro (Apr 17 2019 at 16:57, on Zulip):

Is it legal to have a slice of u8 that starts at, say, address !0 - 0xff with a length of 512?

Jethro (Apr 17 2019 at 16:57, on Zulip):

maybe no because one of the elements is at address 0, which it's not legal to have a reference to

Jethro (Apr 17 2019 at 16:58, on Zulip):

what if you have a slice of structs that you happen to have aligned such that no field is at address 0?

Jethro (Apr 17 2019 at 17:02, on Zulip):

not sure how to actually make such a struct because 0 is aligned for all alignments

RalfJ (Apr 17 2019 at 17:08, on Zulip):

no, address computation must not overflow

Jethro (Apr 17 2019 at 17:11, on Zulip):

makes sense

Jethro (Apr 17 2019 at 17:11, on Zulip):

how strict is that?

Jethro (Apr 17 2019 at 17:12, on Zulip):

is it invalid to create a fat raw pointer with a length that's too long?

Jethro (Apr 17 2019 at 17:12, on Zulip):

or is it just for references

RalfJ (Apr 17 2019 at 17:18, on Zulip):

uh. no idea.^^

RalfJ (Apr 17 2019 at 17:19, on Zulip):

this is essnetially the question of whether raw fat ptr metadata must be valid, which is not decided

RalfJ (Apr 17 2019 at 17:19, on Zulip):

but even if you can have the raw ptr, you'd not be allowed to use it

Jethro (Apr 17 2019 at 17:19, on Zulip):

sure

Jethro (Apr 17 2019 at 17:20, on Zulip):

mostly a question of whether I need to check validity before creating the pointer or whether I can do it after

Jethro (Apr 17 2019 at 17:21, on Zulip):

I guess I'm creating the fat pointer by calling slice::from_raw_parts and then converting it to a pointer, which I suppose is always invalid

RalfJ (Apr 17 2019 at 17:44, on Zulip):

yeah then you have a reference (for a short time)

Last update: Nov 20 2019 at 13:15UTC