sofa icon indicating copy to clipboard operation
sofa copied to clipboard

[Sofa.Type] Deprecate unsafe Vec constructor from pointer

Open fredroy opened this issue 3 years ago • 3 comments

One of the constructor of type::Vec takes a raw pointer and fill itself from this pointer, using its own size. But the ctor does not know the size of the given array so this can contribute to unsafe behavior. E.g

SReal array[2] = {1.0, 1.0};
sofa::type::Vec<3, SReal> vec(array);

is valid and will compile; but it will lead to unexpected result (in the best case, a crash) GCC detected this case while compiling SpringForcefield with the bbox function on 2d and 1d datatypes. And this leads to an other problem, with the case of TBoundingBox, which relies fully on this mechanism. This PR removes as much as possible the usage of the unsafe ctor (effectuvely removing TBoundingBox usage) but does not deprecate TBoundingBox by itself (I suppose it should be)


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

fredroy avatar Jul 11 '22 08:07 fredroy

[ci-build]

fredroy avatar Jul 14 '22 06:07 fredroy

[ci-build][with-all-tests]

fredroy avatar Jul 15 '22 00:07 fredroy

[ci-build][with-all-tests]

fredroy avatar Jul 27 '22 08:07 fredroy