sofa icon indicating copy to clipboard operation
sofa copied to clipboard

Access to data buffer in TypeInfo_FixedArray.h (`&data[0]`)

Open Camille-K opened this issue 3 years ago • 2 comments

I open this issue following a PR on VectorTypeInfo.

The initial PR purpose was to change the default behaviour of the getValuePtr methods from

return &data[0];

(which may lead to problems when dealing with an empty vector), to :

return data.data();

I found this behaviour in two other 'type info' files: TypeInfo_Text.h and FixedArrayTypeInfo.h, but I couldn't apply the same fix to FixedArrayTypeInfo, which involves, at some point, RigidCoord and RigidDeriv data (which don't have a .data() method), leading to this error at build:

FixedArrayTypeInfo.h:195:21: error: ‘const DataType’ {aka ‘const class sofa::defaulttype::RigidDeriv<2, double>’} has no member named ‘data’
  195 |         return data.data();
      |                ~~~~~^~~~

I guess it would be a good thing to remove all occurrences of this kind of &data[0] in the code, but I'm not sure I will find the time to investigate on what would be a proper replacement for TypeInfo_FixedArray.h.

Camille-K avatar Nov 30 '22 11:11 Camille-K

@alxbilger did you fixed this issue in PR #3512, can we close it?

epernod avatar May 25 '23 08:05 epernod

@epernod No I don't think the PR #3512 fixed this specific issue

alxbilger avatar Jun 09 '23 11:06 alxbilger