summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2017-06-08 19:22:46 +0900
committerThiep Ha <thiepha@gmail.com>2017-06-09 10:18:50 +0900
commitb1d287bbf2f1b7edd4404db93a9365d33a08835c (patch)
tree7dd071ed5dbe6dc1f0346465105caa5a665a55cb
parent824699036aa54177a88849e2a5b8f5626e443204 (diff)
downloadefl-devs/ami/edje_play.tar.gz
map: add more checking on input and memory allocationdevs/ami/edje_play
More checking on input parameter and memory allocation when set number of map points. Thanks jp.
-rw-r--r--src/lib/evas/canvas/efl_gfx_map.c26
-rw-r--r--src/lib/evas/canvas/evas_map.c2
2 files changed, 21 insertions, 7 deletions
diff --git a/src/lib/evas/canvas/efl_gfx_map.c b/src/lib/evas/canvas/efl_gfx_map.c
index 8577ebfbf3..60672c7224 100644
--- a/src/lib/evas/canvas/efl_gfx_map.c
+++ b/src/lib/evas/canvas/efl_gfx_map.c
@@ -175,8 +175,7 @@ _efl_gfx_map_efl_object_destructor(Eo *eo_obj, Efl_Gfx_Map_Data *pd)
if (pd->cow)
{
_map_ops_clean(eo_obj, pd);
- if (pd->cow->points)
- free(pd->cow->points);
+ free(pd->cow->points);
eina_cow_free(gfx_map_cow, (const Eina_Cow_Data **) &pd->cow);
}
efl_destructor(efl_super(eo_obj, MY_CLASS));
@@ -528,7 +527,7 @@ _efl_gfx_map_map_point_count_set(Eo *eo_obj EINA_UNUSED, Efl_Gfx_Map_Data *pd, i
{
Gfx_Map *mcow;
- if (count % 4 != 0)
+ if ((count <= 0) || (count % 4 != 0))
{
ERR("Map point count (%d) should be multiples of 4", count);
return;
@@ -536,11 +535,26 @@ _efl_gfx_map_map_point_count_set(Eo *eo_obj EINA_UNUSED, Efl_Gfx_Map_Data *pd, i
if (pd->cow->count == count) return;
mcow = MAPCOW_BEGIN(pd);
- mcow->count = count;
if (mcow->points == NULL)
- mcow->points = calloc(1, count * sizeof(Gfx_Map_Point));
+ {
+ mcow->points = calloc(1, count * sizeof(Gfx_Map_Point));
+ if (mcow->points)
+ mcow->count = count;
+ else
+ ERR("Failed to allocate memory with calloc");
+ }
else
- mcow->points = realloc(mcow->points, count * sizeof(Gfx_Map_Point));
+ {
+ Gfx_Map_Point *ps = realloc(mcow->points, count * sizeof(Gfx_Map_Point));
+ if (ps)
+ {
+ mcow->points = ps;
+ mcow->count = count;
+ memset(mcow->points, 0, count * sizeof(Gfx_Map_Point));
+ }
+ else
+ ERR("Failed to allocate memory with realloc");
+ }
MAPCOW_END(mcow, pd);
}
diff --git a/src/lib/evas/canvas/evas_map.c b/src/lib/evas/canvas/evas_map.c
index 8ccd4ec418..5dd5fc1d29 100644
--- a/src/lib/evas/canvas/evas_map.c
+++ b/src/lib/evas/canvas/evas_map.c
@@ -649,7 +649,7 @@ evas_object_map_get(const Evas_Object *eo_obj)
EAPI Evas_Map *
evas_map_new(int count)
{
- if (count % 4 != 0)
+ if ((count <= 0) || (count % 4 != 0))
{
ERR("map point count (%i) should be multiples of 4!", count);
return NULL;