Description
I hope this is a good channel to ask this, let me know if I should use something else :)
I was trying to grasp what is considered UB w.r.t. uninitialized data. My current understanding is that there are validity rules, and that by definition uninitialized data is not valid for any type except union
and padding
.
From what I understood from the reference UB happens when the value is produced, and it describes it as:
"Producing" a value happens any time a value is assigned to or read from a place
It seems there is an issue with that definition for code like this:
let mut v: Vec<i32> = Vec::with_capacity(1);
unsafe { v.set_len(1) }
IIUC that second line above should be UB, but the rule of producing doesn't seem to cover that, since there is no data being assigned or read.
My questions are: 1. is it correct to say the above is undefined behavior? 2. am I missing some other rules that would define the above as UB?
Thanks!