forked from enlightenment/efl
Added EINA_SAFETY_*.
Also some additional checks were done to avoid segv. SVN revision: 40029
This commit is contained in:
parent
46984aaf5d
commit
524343cce6
|
@ -23,6 +23,7 @@
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <eina_safety_checks.h>
|
||||||
#include "Ethumb.h"
|
#include "Ethumb.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -94,8 +95,7 @@ ethumb_new(void)
|
||||||
Evas_Object *o, *img;
|
Evas_Object *o, *img;
|
||||||
|
|
||||||
ethumb = calloc(1, sizeof(Ethumb));
|
ethumb = calloc(1, sizeof(Ethumb));
|
||||||
if (!ethumb)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(ethumb, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ethumb->tw = THUMB_SIZE_NORMAL;
|
ethumb->tw = THUMB_SIZE_NORMAL;
|
||||||
ethumb->th = THUMB_SIZE_NORMAL;
|
ethumb->th = THUMB_SIZE_NORMAL;
|
||||||
|
@ -185,8 +185,9 @@ ethumb_free(Ethumb *ethumb)
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_fdo_set(Ethumb *e, Ethumb_Thumb_Size s)
|
ethumb_thumb_fdo_set(Ethumb *e, Ethumb_Thumb_Size s)
|
||||||
{
|
{
|
||||||
if (!e || (s != ETHUMB_THUMB_NORMAL && s != ETHUMB_THUMB_LARGE))
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
return;
|
EINA_SAFETY_ON_FALSE_RETURN(s == ETHUMB_THUMB_NORMAL ||
|
||||||
|
s == ETHUMB_THUMB_LARGE);
|
||||||
|
|
||||||
if (s == ETHUMB_THUMB_NORMAL)
|
if (s == ETHUMB_THUMB_NORMAL)
|
||||||
{
|
{
|
||||||
|
@ -212,81 +213,80 @@ ethumb_thumb_fdo_set(Ethumb *e, Ethumb_Thumb_Size s)
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_size_set(Ethumb *e, int tw, int th)
|
ethumb_thumb_size_set(Ethumb *e, int tw, int th)
|
||||||
{
|
{
|
||||||
if (e && tw > 0 && th > 0)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
EINA_SAFETY_ON_FALSE_RETURN(tw > 0);
|
||||||
|
EINA_SAFETY_ON_FALSE_RETURN(th > 0);
|
||||||
|
|
||||||
e->tw = tw;
|
e->tw = tw;
|
||||||
e->th = th;
|
e->th = th;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_size_get(const Ethumb *e, int *tw, int *th)
|
ethumb_thumb_size_get(const Ethumb *e, int *tw, int *th)
|
||||||
{
|
{
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
*tw = e->tw;
|
if (tw) *tw = e->tw;
|
||||||
*th = e->th;
|
if (th) *th = e->th;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_format_set(Ethumb *e, Ethumb_Thumb_Format f)
|
ethumb_thumb_format_set(Ethumb *e, Ethumb_Thumb_Format f)
|
||||||
{
|
{
|
||||||
if (e && (f == ETHUMB_THUMB_FDO || f == ETHUMB_THUMB_JPEG))
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
|
EINA_SAFETY_ON_FALSE_RETURN(f == ETHUMB_THUMB_FDO ||
|
||||||
|
f == ETHUMB_THUMB_JPEG);
|
||||||
|
|
||||||
e->format = f;
|
e->format = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI Ethumb_Thumb_Format
|
EAPI Ethumb_Thumb_Format
|
||||||
ethumb_thumb_format_get(const Ethumb *e)
|
ethumb_thumb_format_get(const Ethumb *e)
|
||||||
{
|
{
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
||||||
return e->format;
|
return e->format;
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_aspect_set(Ethumb *e, Ethumb_Thumb_Aspect a)
|
ethumb_thumb_aspect_set(Ethumb *e, Ethumb_Thumb_Aspect a)
|
||||||
{
|
{
|
||||||
if (e && (a == ETHUMB_THUMB_KEEP_ASPECT || a == ETHUMB_THUMB_IGNORE_ASPECT
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
|| a == ETHUMB_THUMB_CROP))
|
EINA_SAFETY_ON_FALSE_RETURN(a == ETHUMB_THUMB_KEEP_ASPECT ||
|
||||||
|
a == ETHUMB_THUMB_IGNORE_ASPECT ||
|
||||||
|
a == ETHUMB_THUMB_CROP);
|
||||||
|
|
||||||
e->aspect = a;
|
e->aspect = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI Ethumb_Thumb_Aspect
|
EAPI Ethumb_Thumb_Aspect
|
||||||
ethumb_thumb_aspect_get(const Ethumb *e)
|
ethumb_thumb_aspect_get(const Ethumb *e)
|
||||||
{
|
{
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
||||||
return e->aspect;
|
return e->aspect;
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_crop_align_set(Ethumb *e, float x, float y)
|
ethumb_thumb_crop_align_set(Ethumb *e, float x, float y)
|
||||||
{
|
{
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
e->crop_x = x;
|
e->crop_x = x;
|
||||||
e->crop_y = y;
|
e->crop_y = y;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_crop_align_get(Ethumb *e, float *x, float *y)
|
ethumb_thumb_crop_align_get(Ethumb *e, float *x, float *y)
|
||||||
{
|
{
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
*x = e->crop_x;
|
if (x) *x = e->crop_x;
|
||||||
*y = e->crop_y;
|
if (y) *y = e->crop_y;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI int
|
EAPI int
|
||||||
ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const char *swallow)
|
ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const char *swallow)
|
||||||
{
|
{
|
||||||
if (!e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0);
|
||||||
return 0;
|
|
||||||
|
|
||||||
Ethumb_Frame *frame;
|
Ethumb_Frame *frame;
|
||||||
frame = e->frame;
|
frame = e->frame;
|
||||||
|
@ -307,6 +307,7 @@ ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const cha
|
||||||
{
|
{
|
||||||
ERR("could not create edje frame object.\n");
|
ERR("could not create edje frame object.\n");
|
||||||
_ethumb_frame_free(frame);
|
_ethumb_frame_free(frame);
|
||||||
|
e->frame = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,6 +316,7 @@ ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const cha
|
||||||
{
|
{
|
||||||
ERR("could not load frame theme.\n");
|
ERR("could not load frame theme.\n");
|
||||||
_ethumb_frame_free(frame);
|
_ethumb_frame_free(frame);
|
||||||
|
e->frame = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,6 +325,7 @@ ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const cha
|
||||||
{
|
{
|
||||||
ERR("could not swallow image to edje frame.\n");
|
ERR("could not swallow image to edje frame.\n");
|
||||||
_ethumb_frame_free(frame);
|
_ethumb_frame_free(frame);
|
||||||
|
e->frame = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,8 +347,7 @@ ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const cha
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_dir_path_set(Ethumb *e, const char *path)
|
ethumb_thumb_dir_path_set(Ethumb *e, const char *path)
|
||||||
{
|
{
|
||||||
if (!e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
return;
|
|
||||||
|
|
||||||
path = eina_stringshare_add(path);
|
path = eina_stringshare_add(path);
|
||||||
eina_stringshare_del(e->thumb_dir);
|
eina_stringshare_del(e->thumb_dir);
|
||||||
|
@ -355,8 +357,7 @@ ethumb_thumb_dir_path_set(Ethumb *e, const char *path)
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
ethumb_thumb_dir_path_get(Ethumb *e)
|
ethumb_thumb_dir_path_get(Ethumb *e)
|
||||||
{
|
{
|
||||||
if (!e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return e->thumb_dir;
|
return e->thumb_dir;
|
||||||
}
|
}
|
||||||
|
@ -364,8 +365,7 @@ ethumb_thumb_dir_path_get(Ethumb *e)
|
||||||
EAPI void
|
EAPI void
|
||||||
ethumb_thumb_category_set(Ethumb *e, const char *category)
|
ethumb_thumb_category_set(Ethumb *e, const char *category)
|
||||||
{
|
{
|
||||||
if (!e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
return;
|
|
||||||
|
|
||||||
category = eina_stringshare_add(category);
|
category = eina_stringshare_add(category);
|
||||||
eina_stringshare_del(e->category);
|
eina_stringshare_del(e->category);
|
||||||
|
@ -375,8 +375,7 @@ ethumb_thumb_category_set(Ethumb *e, const char *category)
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
ethumb_thumb_category_get(Ethumb *e)
|
ethumb_thumb_category_get(Ethumb *e)
|
||||||
{
|
{
|
||||||
if (!e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return e->category;
|
return e->category;
|
||||||
}
|
}
|
||||||
|
@ -386,8 +385,8 @@ ethumb_file_new(Ethumb *e, const char *path)
|
||||||
{
|
{
|
||||||
Ethumb_File *ef;
|
Ethumb_File *ef;
|
||||||
|
|
||||||
if (!e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
|
||||||
return NULL;
|
EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
|
||||||
|
|
||||||
if (access(path, R_OK))
|
if (access(path, R_OK))
|
||||||
{
|
{
|
||||||
|
@ -396,6 +395,7 @@ ethumb_file_new(Ethumb *e, const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
ef = calloc(1, sizeof(Ethumb_File));
|
ef = calloc(1, sizeof(Ethumb_File));
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
|
||||||
ef->ethumb = e;
|
ef->ethumb = e;
|
||||||
ef->src_path = eina_stringshare_add(path);
|
ef->src_path = eina_stringshare_add(path);
|
||||||
|
|
||||||
|
@ -413,8 +413,7 @@ _ethumb_generate_hash(const char *file)
|
||||||
|
|
||||||
char uri[PATH_MAX];
|
char uri[PATH_MAX];
|
||||||
|
|
||||||
if (!file)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
||||||
return NULL;
|
|
||||||
snprintf (uri, sizeof(uri), "file://%s", file);
|
snprintf (uri, sizeof(uri), "file://%s", file);
|
||||||
|
|
||||||
MD5Init (&ctx);
|
MD5Init (&ctx);
|
||||||
|
@ -558,6 +557,8 @@ ethumb_file_thumb_path_set(Ethumb_File *ef, const char *path)
|
||||||
char *real_path;
|
char *real_path;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
|
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN(ef);
|
||||||
|
|
||||||
if (ef->thumb_path)
|
if (ef->thumb_path)
|
||||||
eina_stringshare_del(ef->thumb_path);
|
eina_stringshare_del(ef->thumb_path);
|
||||||
|
|
||||||
|
@ -571,6 +572,7 @@ ethumb_file_thumb_path_set(Ethumb_File *ef, const char *path)
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
ethumb_file_thumb_path_get(Ethumb_File *ef)
|
ethumb_file_thumb_path_get(Ethumb_File *ef)
|
||||||
{
|
{
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
|
||||||
if (!ef->thumb_path)
|
if (!ef->thumb_path)
|
||||||
_ethumb_file_generate_path(ef);
|
_ethumb_file_generate_path(ef);
|
||||||
|
|
||||||
|
@ -691,11 +693,7 @@ ethumb_file_generate(Ethumb_File *ef)
|
||||||
int r;
|
int r;
|
||||||
char *dname;
|
char *dname;
|
||||||
|
|
||||||
if (!ef)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(ef, 0);
|
||||||
return 0;
|
|
||||||
|
|
||||||
eth = ef->ethumb;
|
|
||||||
|
|
||||||
|
|
||||||
if (!_ethumb_image_load(ef))
|
if (!_ethumb_image_load(ef))
|
||||||
{
|
{
|
||||||
|
@ -703,6 +701,7 @@ ethumb_file_generate(Ethumb_File *ef)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eth = ef->ethumb;
|
||||||
evas_render(eth->sub_e);
|
evas_render(eth->sub_e);
|
||||||
|
|
||||||
if (!ef->thumb_path)
|
if (!ef->thumb_path)
|
||||||
|
|
|
@ -103,36 +103,36 @@ typedef struct _Ethumb_File Ethumb_File;
|
||||||
EAPI int ethumb_init(void);
|
EAPI int ethumb_init(void);
|
||||||
EAPI int ethumb_shutdown(void);
|
EAPI int ethumb_shutdown(void);
|
||||||
|
|
||||||
EAPI Ethumb * ethumb_new(void);
|
EAPI Ethumb * ethumb_new(void) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
EAPI void ethumb_free(Ethumb *e);
|
EAPI void ethumb_free(Ethumb *e);
|
||||||
|
|
||||||
EAPI void ethumb_thumb_fdo_set(Ethumb *e, Ethumb_Thumb_Size s);
|
EAPI void ethumb_thumb_fdo_set(Ethumb *e, Ethumb_Thumb_Size s) EINA_ARG_NONNULL(1);
|
||||||
|
|
||||||
EAPI void ethumb_thumb_size_set(Ethumb *e, int tw, int th);
|
EAPI void ethumb_thumb_size_set(Ethumb *e, int tw, int th) EINA_ARG_NONNULL(1);
|
||||||
EAPI void ethumb_thumb_size_get(const Ethumb *e, int *tw, int *th);
|
EAPI void ethumb_thumb_size_get(const Ethumb *e, int *tw, int *th) EINA_ARG_NONNULL(1);
|
||||||
|
|
||||||
EAPI void ethumb_thumb_format_set(Ethumb *e, Ethumb_Thumb_Format f);
|
EAPI void ethumb_thumb_format_set(Ethumb *e, Ethumb_Thumb_Format f) EINA_ARG_NONNULL(1);
|
||||||
EAPI Ethumb_Thumb_Format ethumb_thumb_format_get(const Ethumb *e);
|
EAPI Ethumb_Thumb_Format ethumb_thumb_format_get(const Ethumb *e) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
|
||||||
|
|
||||||
EAPI void ethumb_thumb_aspect_set(Ethumb *e, Ethumb_Thumb_Aspect a);
|
EAPI void ethumb_thumb_aspect_set(Ethumb *e, Ethumb_Thumb_Aspect a) EINA_ARG_NONNULL(1);
|
||||||
EAPI Ethumb_Thumb_Aspect ethumb_thumb_aspect_get(const Ethumb *e);
|
EAPI Ethumb_Thumb_Aspect ethumb_thumb_aspect_get(const Ethumb *e) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
|
||||||
|
|
||||||
EAPI void ethumb_thumb_crop_align_set(Ethumb *e, float x, float y);
|
EAPI void ethumb_thumb_crop_align_set(Ethumb *e, float x, float y) EINA_ARG_NONNULL(1);
|
||||||
EAPI void ethumb_thumb_crop_align_get(Ethumb *e, float *x, float *y);
|
EAPI void ethumb_thumb_crop_align_get(Ethumb *e, float *x, float *y) EINA_ARG_NONNULL(1);
|
||||||
|
|
||||||
EAPI int ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const char *swallow);
|
EAPI int ethumb_frame_set(Ethumb *e, const char *theme_file, const char *group, const char *swallow) EINA_ARG_NONNULL(1);
|
||||||
|
|
||||||
EAPI void ethumb_thumb_dir_path_set(Ethumb *e, const char *path);
|
EAPI void ethumb_thumb_dir_path_set(Ethumb *e, const char *path) EINA_ARG_NONNULL(1);
|
||||||
EAPI const char * ethumb_thumb_dir_path_get(Ethumb *e);
|
EAPI const char * ethumb_thumb_dir_path_get(Ethumb *e) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
|
||||||
|
|
||||||
EAPI void ethumb_thumb_category_set(Ethumb *e, const char *category);
|
EAPI void ethumb_thumb_category_set(Ethumb *e, const char *category) EINA_ARG_NONNULL(1);
|
||||||
EAPI const char * ethumb_thumb_category_get(Ethumb *e);
|
EAPI const char * ethumb_thumb_category_get(Ethumb *e) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
|
||||||
|
|
||||||
EAPI Ethumb_File * ethumb_file_new(Ethumb *e, const char *path);
|
EAPI Ethumb_File * ethumb_file_new(Ethumb *e, const char *path) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2);
|
||||||
EAPI void ethumb_file_free(Ethumb_File *ef);
|
EAPI void ethumb_file_free(Ethumb_File *ef);
|
||||||
EAPI void ethumb_file_thumb_path_set(Ethumb_File *ef, const char *path);
|
EAPI void ethumb_file_thumb_path_set(Ethumb_File *ef, const char *path) EINA_ARG_NONNULL(1);
|
||||||
EAPI const char * ethumb_file_thumb_path_get(Ethumb_File *ef);
|
EAPI const char * ethumb_file_thumb_path_get(Ethumb_File *ef) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
|
||||||
EAPI int ethumb_file_generate(Ethumb_File *ef);
|
EAPI int ethumb_file_generate(Ethumb_File *ef) EINA_ARG_NONNULL(1);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue