PicoVector: Fix ppp arc memory corruption.

pull/1019/head
Mike Bell 2025-01-08 20:01:41 +00:00 zatwierdzone przez Phil Howard
rodzic 9e7c2640d4
commit 807d4ba7ef
2 zmienionych plików z 17 dodań i 8 usunięć

Wyświetl plik

@ -168,7 +168,7 @@ pp_poly_t* ppp_circle(ppp_circle_def d) {
pp_poly_t* ppp_arc(ppp_arc_def d) {
pp_poly_t *poly = pp_poly_new();
pp_path_t *path = pp_poly_add_path(poly);
pp_path_t *inner = (pp_path_t *)(d.s == 0.0f ? NULL : calloc(1, sizeof(pp_path_t)));
pp_path_t *inner = d.s != 0.0f ? pp_path_new() : NULL;
// no thickness, so add centre point to make pie shape
if(!inner) pp_path_add_point(path, (pp_point_t){d.x, d.y});
@ -185,7 +185,7 @@ pp_poly_t* ppp_arc(ppp_arc_def d) {
if(inner) { // append the inner path
pp_path_add_points(path, inner->points, inner->count);
free(inner->points); free(inner);
pp_path_free(inner);
}
return poly;

Wyświetl plik

@ -270,14 +270,26 @@ pp_poly_t *pp_poly_new() {
return poly;
}
pp_path_t *pp_path_new() {
pp_path_t *path = (pp_path_t *)PP_MALLOC(sizeof(pp_path_t));
memset(path, 0, sizeof(pp_path_t));
path->storage = 8;
path->points = (pp_point_t *)PP_MALLOC(sizeof(pp_point_t) * path->storage);
return path;
}
void pp_path_free(pp_path_t *path) {
PP_FREE(path->points);
PP_FREE(path);
}
void pp_poly_free(pp_poly_t *poly) {
if(poly->paths) {
pp_path_t *path = poly->paths;
while(path) {
PP_FREE(path->points);
pp_path_t *free_path = path;
path = path->next;
PP_FREE(free_path);
pp_path_free(free_path);
}
}
PP_FREE(poly);
@ -302,10 +314,7 @@ int pp_poly_path_count(pp_poly_t *poly) {
}
pp_path_t* pp_poly_add_path(pp_poly_t *poly) {
pp_path_t *path = (pp_path_t *)PP_MALLOC(sizeof(pp_path_t));
memset(path, 0, sizeof(pp_path_t));
path->storage = 8;
path->points = (pp_point_t *)PP_MALLOC(sizeof(pp_point_t) * path->storage);
pp_path_t *path = pp_path_new();
if(!poly->paths) {
poly->paths = path;