Inconsistent use of int and size_t in C Bindings for std::vector Types · Issue #1089 · elalish/manifold · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The types ManifoldCrossSectionVec, ManifoldPolygon, ManifoldPolygons and ManifoldManifoldVec represent std::vector in the C bindings. However, their API functions mix the use of size_t and int for lengths and indices. For example:
ManifoldCrossSectionVec:
size_tmanifold_cross_section_vec_length(ManifoldCrossSectionVec*csv); // uses size_tManifoldCrossSection*manifold_cross_section_vec_get(void*mem, ManifoldCrossSectionVec*csv, intidx); // uses int
SimplePolygon:
size_tmanifold_simple_polygon_length(ManifoldSimplePolygon*p); // uses size_tManifoldVec2manifold_simple_polygon_get_point(ManifoldSimplePolygon*p, intidx); // uses int
ManifoldPolygons:
size_tmanifold_polygons_length(ManifoldPolygons*ps); // uses size_tManifoldSimplePolygon*manifold_polygons_get_simple(void*mem, ManifoldPolygons*ps, intidx); // uses int
The use of int for indices is problematic because int cannot represent the full range of values that size_t can. This mismatch can lead to:
Potential bugs: Negative or out-of-range values for indices.
Type safety issues: Implicit conversions and sign mismatches.
Platform-specific inconsistencies: Differences in the size of int and size_t across platforms.
Suggested Solution
All int parameters used for indices in the API should be updated to size_t to ensure consistency with the std::vector representation and avoid these issues.
Would be open to contribute a fix 😄
The text was updated successfully, but these errors were encountered:
The types
ManifoldCrossSectionVec
,ManifoldPolygon
,ManifoldPolygons
andManifoldManifoldVec
representstd::vector
in the C bindings. However, their API functions mix the use ofsize_t
andint
for lengths and indices. For example:ManifoldCrossSectionVec:
SimplePolygon:
ManifoldPolygons:
ManifoldManifoldVec:
Problem
The use of
int
for indices is problematic becauseint
cannot represent the full range of values thatsize_t
can. This mismatch can lead to:int
andsize_t
across platforms.Suggested Solution
All
int
parameters used for indices in the API should be updated tosize_t
to ensure consistency with thestd::vector
representation and avoid these issues.Would be open to contribute a fix 😄
The text was updated successfully, but these errors were encountered: