Open aaronfranke opened 5 years ago
Have you looked at the code to see why it might be done like that?
It was introduced 6 years ago here, cc @memononen
Do you even C, bro?
Here's a hint:
grad = (NSVGgradient*)malloc(sizeof(NSVGgradient) + sizeof(NSVGgradientStop)*(nstops-1));
Btw, this project isn't actively maintained.
It's "oldskool" trick to create variable length array without extra pointer and alloc.
On Sat, Nov 16, 2019 at 4:41 AM Aaron Franke notifications@github.com wrote:
It seems like a bug to have an array with exactly one item, what's the point?
typedef struct NSVGgradient { float xform[6]; char spread; float fx, fy; int nstops; NSVGgradientStop stops[1]; // here } NSVGgradient;
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/memononen/nanosvg/issues/170?email_source=notifications&email_token=ABIBXSD4UMHYLX7N7PJDEVTQT5MVDA5CNFSM4JODB6VKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZYG44Q, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIBXSGQ7E67IXISRBK6Z4DQT5MVDANCNFSM4JODB6VA .
after change from stops[1]
to stops[0]
and nstops-1
to nstops
(gcc), it explicit tell address sanitizer it is a variable size array, no warning message generated.
typedef struct NSVGgradient {
float xform[6];
char spread;
float fx, fy;
int nstops;
NSVGgradientStop stops[0]; // here
} NSVGgradient;
grad = (NSVGgradient*)malloc(sizeof(NSVGgradient) + sizeof(NSVGgradientStop)*(nstops));
It seems like a bug to have an array with exactly one item, what's the point?