sisshiki1969/ruruby

UB in ident table

Closed this issue · 1 comments

IdentId has an inner NonZeroU32 member:

pub struct IdentId(NonZeroU32);

But the <null> ident is defined with symbol ID 0:

table.set_ident_id("<null>", IdentId::from(0));

IdentId::from should probably either be replaced with a TryFrom impl or an unsafe function like IdentId::new_unchchecked. From impls cannot be unsafe and ideally shouldn't have safety pre-conditions (which indicates that the fn should be unsafe).

Hi, Thank you for reading my code and giving me the issue!

Yes, as you may know, IdentId(0) is a kind of dummy data, and not expected to be accessed.
And this code seems to be inappropriate as you pointed out.

Fixed in #29.