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

Remove float->int casts from read_integer/read_index #232

Closed zeux closed 9 months ago

zeux commented 9 months ago

The float->int cast in read_integer is unreachable as this function is only called from read_float, and it handles r_32f separately.

The float->int cast in read_index is reachable since the caller may call accessor_read_index or unpack_indices on a floating-point buffer. However, there should be no valid circumstances to do this as cases when glTF buffers carry index data (geometry indices, sparse accessors) require unnormalized integers by the spec. This is also underscored by read_index only handling unsigned integer types.

Based on the discussion in #227 the support for float->int cast is somewhat accidental and is unlikely to be required by existing users.