edje_svg: Fix handling of realloc

This amends 8e311db414 as the logic
was badly broken. A "shadow" variable warning
clearly showed that "tmp" was not used properly.

This fixes the "IBM" logo in svg-test (the only one
using polygon/polyline, it seems).
This commit is contained in:
Jean-Philippe Andre 2017-08-01 19:51:03 +09:00
parent 3b8c60954e
commit ae443173ec
1 changed files with 12 additions and 19 deletions

View File

@ -1106,22 +1106,16 @@ _attr_parse_polygon_points(const char *str, double **points, int *point_count)
int tmp_count=0; int tmp_count=0;
int count = 0; int count = 0;
double num; double num;
double *point_array = NULL; double *point_array = NULL, *tmp_array;
while (_parse_number(&str, &num)) while (_parse_number(&str, &num))
{ {
tmp[tmp_count++] = num; tmp[tmp_count++] = num;
if (tmp_count == 50) if (tmp_count == 50)
{ {
double *tmp; tmp_array = realloc(point_array, (count + tmp_count) * sizeof(double));
if (!tmp_array) goto error_alloc;
tmp = realloc(point_array, (count + tmp_count) * sizeof(double)); point_array = tmp_array;
if (!tmp)
{
ERR("allocation for point array failed. out of memory");
abort();
}
point_array = tmp;
memcpy(&point_array[count], tmp, tmp_count * sizeof(double)); memcpy(&point_array[count], tmp, tmp_count * sizeof(double));
count += tmp_count; count += tmp_count;
tmp_count = 0; tmp_count = 0;
@ -1130,20 +1124,19 @@ _attr_parse_polygon_points(const char *str, double **points, int *point_count)
if (tmp_count > 0) if (tmp_count > 0)
{ {
double *tmp; tmp_array = realloc(point_array, (count + tmp_count) * sizeof(double));
if (!tmp_array) goto error_alloc;
tmp = realloc(point_array, (count + tmp_count) * sizeof(double)); point_array = tmp_array;
if (!tmp)
{
ERR("allocation for point array failed. out of memory");
abort();
}
point_array = tmp;
memcpy(&point_array[count], tmp, tmp_count * sizeof(double)); memcpy(&point_array[count], tmp, tmp_count * sizeof(double));
count += tmp_count; count += tmp_count;
} }
*point_count = count; *point_count = count;
*points = point_array; *points = point_array;
return;
error_alloc:
ERR("allocation for point array failed. out of memory");
abort();
} }
/* parse the attributes for a polygon element. /* parse the attributes for a polygon element.