jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99
MIT License
1.42k stars 135 forks source link

Explicitly parse primitive type enum #233

Closed zeux closed 8 months ago

zeux commented 9 months ago

Instead of blindly casting int to enum, we handle the values defined in the JSON spec in a switch case.

This may seem redundant, but this fixes a UBSAN error on invalid glTF files, and it's literally the only enum where we rely on the enum values matching glTF values (everything else is either string based in glTF, or using integers that aren't small and sequential so we convert it with a switch). So this is more consistent and a little safer; this also ensures that the values actually conform to the max_enum member.