silnrsi / graphite

Graphite is a "smart font" system developed specifically to handle the complexities of lesser-known languages of the world.
http://graphite.sil.org/
Other
147 stars 44 forks source link

Avoid using enum type for a value that may be out of range #2

Closed jfkthame closed 8 years ago

jfkthame commented 8 years ago

Assigning an arbitrary byte value to an opcode variable may result in undefined behavior, because of the limited range of the enum type. So use a byte variable for the value read from the font until it has been validated and confirmed to be a valid opcode.

mhosken commented 8 years ago

I don't know if this helps but I would like to see a cast of opc to opcode in the switch of Machine::Code::decoder::fetch_opcode, or else perhaps a const opcode = opcode(bopc) and bopc = *bc++ or whatever.

mhosken commented 8 years ago

Merged manually with minor change as per comment above