forked from enlightenment/enlightenment
E17: some alloc checks, and fix a case where we lost a pointer if realloc() fails
patch by Maxime Villard (rustyBSD) SVN revision: 75838
This commit is contained in:
parent
470e744c0f
commit
08aa21eea9
|
@ -209,8 +209,7 @@ e_editable_text_set(Evas_Object *editable, const char *text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sd->password_mode) memset(sd->text, 0, sd->char_length);
|
if (sd->password_mode) memset(sd->text, 0, sd->char_length);
|
||||||
free(sd->text);
|
E_FREE(sd->text);
|
||||||
sd->text = NULL;
|
|
||||||
sd->char_length = 0;
|
sd->char_length = 0;
|
||||||
sd->unicode_length = 0;
|
sd->unicode_length = 0;
|
||||||
sd->allocated_length = -1;
|
sd->allocated_length = -1;
|
||||||
|
@ -280,6 +279,8 @@ e_editable_text_range_get(Evas_Object *editable, int start, int end)
|
||||||
if (end_id <= start_id) return NULL;
|
if (end_id <= start_id) return NULL;
|
||||||
|
|
||||||
range = malloc((end_id - start_id + 1) * sizeof(char));
|
range = malloc((end_id - start_id + 1) * sizeof(char));
|
||||||
|
if (!range) return NULL;
|
||||||
|
|
||||||
strncpy(range, &sd->text[start_id], end_id - start_id);
|
strncpy(range, &sd->text[start_id], end_id - start_id);
|
||||||
range[end_id - start_id] = '\0';
|
range[end_id - start_id] = '\0';
|
||||||
|
|
||||||
|
@ -936,12 +937,13 @@ _e_editable_text_insert(Evas_Object *editable, int pos, const char *text)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sd->text = realloc(sd->text, new_allocated_length + 1);
|
char *p = realloc(sd->text, new_allocated_length + 1);
|
||||||
if (!sd->text)
|
if (!p)
|
||||||
{
|
{
|
||||||
sd->text = old;
|
sd->text = old;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
sd->text = p;
|
||||||
}
|
}
|
||||||
sd->allocated_length = new_allocated_length;
|
sd->allocated_length = new_allocated_length;
|
||||||
}
|
}
|
||||||
|
@ -1080,6 +1082,8 @@ _e_editable_text_update(Evas_Object *editable)
|
||||||
char *text;
|
char *text;
|
||||||
|
|
||||||
text = malloc((sd->unicode_length + 1) * sizeof(char));
|
text = malloc((sd->unicode_length + 1) * sizeof(char));
|
||||||
|
if (!text) return;
|
||||||
|
|
||||||
memset(text, '*', sd->unicode_length * sizeof(char));
|
memset(text, '*', sd->unicode_length * sizeof(char));
|
||||||
text[sd->unicode_length] = '\0';
|
text[sd->unicode_length] = '\0';
|
||||||
edje_object_part_text_set(sd->text_object, "e.text.text", text);
|
edje_object_part_text_set(sd->text_object, "e.text.text", text);
|
||||||
|
@ -1202,6 +1206,8 @@ _e_editable_smart_add(Evas_Object *object)
|
||||||
evas_object_geometry_get(object, &ox, &oy, NULL, NULL);
|
evas_object_geometry_get(object, &ox, &oy, NULL, NULL);
|
||||||
|
|
||||||
sd->text = malloc((E_EDITABLE_BLOCK_SIZE + 1) * sizeof(char));
|
sd->text = malloc((E_EDITABLE_BLOCK_SIZE + 1) * sizeof(char));
|
||||||
|
if (!sd->text) return;
|
||||||
|
|
||||||
sd->text[0] = '\0';
|
sd->text[0] = '\0';
|
||||||
sd->char_length = 0;
|
sd->char_length = 0;
|
||||||
sd->unicode_length = 0;
|
sd->unicode_length = 0;
|
||||||
|
|
|
@ -1314,9 +1314,12 @@ _e_typebuf_add(Evas_Object *obj, const char *s)
|
||||||
len = strlen(sd->typebuf.buf);
|
len = strlen(sd->typebuf.buf);
|
||||||
if (len + strlen(s) + 2 + 1 >= sd->typebuf.size)
|
if (len + strlen(s) + 2 + 1 >= sd->typebuf.size)
|
||||||
{
|
{
|
||||||
sd->typebuf.buf = realloc(sd->typebuf.buf, sd->typebuf.size + strlen(s) + 16);
|
char *p = realloc(sd->typebuf.buf, sd->typebuf.size + strlen(s) + 16);
|
||||||
if (sd->typebuf.buf)
|
if (p)
|
||||||
sd->typebuf.size = sd->typebuf.size + strlen(s) + 16;
|
{
|
||||||
|
sd->typebuf.buf = p;
|
||||||
|
sd->typebuf.size = sd->typebuf.size + strlen(s) + 16;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_e_typebuf_clean(obj);
|
_e_typebuf_clean(obj);
|
||||||
|
|
Loading…
Reference in New Issue