Im need to create a dynamically allocated list of x,y points:
typedef struct
{
uint16_t x;
uint16_t y;
} point_t;
A series of points will be added to a structure:
typedef struct
{
uint32_t length;
uint32_t size;
point_t *pointlist;
} pointlist_t;
So this code will allocate the first pointer to the pointslist_t structure but returns null when trying to allocate the point_t *.
bool pointInit(pointlist_t *pointlist)
{
// get storage for the points list
pointlist = (pointlist_t *)malloc(sizeof(pointlist_t));
if (pointlist == NULL)
{
free(pointlist);
return false;
}
// now the list of points
pointlist->pointlist = (point_t *)malloc(sizeof(point_t));
if (pointlist->pointlist == NULL)
{
free(pointlist->pointlist);
return false;
}
pointlist->length = 0;
pointlist->size = 0;
return true;
}
In the main, I call the list:
pointlist_t * mypointlist;
pointInit(mypointlist);
I cant figure out why. Ideas?