From 713c18aa791977debf5fb8bfa6d14eb0c8adda0f Mon Sep 17 00:00:00 2001 From: barbieri Date: Tue, 2 Mar 2010 00:34:40 +0000 Subject: [PATCH] fix llvm/clang and gcc errors. NOTE: mixing write() and fprintf() to the same descriptor (stderr, done by ERR()), will likely cause problems :-/ git-svn-id: https://svn.enlightenment.org/svn/e/trunk/ethumb@46753 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/ethumbd.c | 50 +++++++++++++++++++++++++++++++++++++++---- src/bin/ethumbd_client.c | 2 +- src/lib/Ethumb.c | 6 ++++++ src/plugins/emotion/emotion.c | 1 - 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/bin/ethumbd.c b/src/bin/ethumbd.c index 0401d79..8faec80 100644 --- a/src/bin/ethumbd.c +++ b/src/bin/ethumbd.c @@ -48,6 +48,7 @@ #define INF(...) EINA_LOG_INFO(__VA_ARGS__) #define WRN(...) EINA_LOG_WARN(__VA_ARGS__) #define ERR(...) EINA_LOG_ERR(__VA_ARGS__) +#define CRIT(...) EINA_LOG_CRIT(__VA_ARGS__) static const char _ethumb_dbus_bus_name[] = "org.enlightenment.Ethumb"; static const char _ethumb_dbus_interface[] = "org.enlightenment.Ethumb"; @@ -354,6 +355,28 @@ _generated_cb(struct _Ethumbd *ed, Eina_Bool success, const char *thumb_path, co ed->processing = NULL; } +static Eina_Bool +_write_safe(int fd, void *data, size_t size) +{ + unsigned char *buf = data; + size_t todo = size; + while (todo > 0) + { + size_t r = write(fd, buf, todo); + if (r > 0) + { + todo -= r; + buf += r; + } + else if ((r < 0) && (errno != EINTR)) + { + ERR("could not write to fd=%d: %s", fd, strerror(errno)); + return EINA_FALSE; + } + } + return EINA_TRUE; +} + static void _ethumbd_slave_cmd_ready(struct _Ethumbd *ed) { @@ -369,7 +392,7 @@ _ethumbd_slave_cmd_ready(struct _Ethumbd *ed) size_path = (int *)bufcmd; bufcmd += sizeof(*size_path); - write(STDERR_FILENO, bufcmd, ed->slave.scmd); + _write_safe(STDERR_FILENO, bufcmd, ed->slave.scmd); thumb_path = bufcmd; bufcmd += *size_path; @@ -423,7 +446,8 @@ _ethumbd_slave_data_read_cb(void *data, int type, void *event) ssize = ev->size; sdata = ev->data; - write(STDERR_FILENO, sdata, ssize); + if (!_write_safe(STDERR_FILENO, sdata, ssize)) + return 0; while (ssize > 0) { @@ -713,14 +737,30 @@ _ethumb_table_append(struct _Ethumbd *ed) { int new_max = q->max_count + 5; int start, size; + void *tmp; start = q->max_count; size = new_max - q->max_count; - q->table = realloc(q->table, new_max * sizeof(struct _Ethumb_Object)); - q->list = realloc(q->list, new_max * sizeof(int)); + tmp = realloc(q->table, new_max * sizeof(struct _Ethumb_Object)); + if (!tmp) + { + CRIT("could not realloc q->table to %zd bytes: %s", + new_max * sizeof(struct _Ethumb_Object), strerror(errno)); + return -1; + } + q->table = tmp; memset(&q->table[start], 0, size * sizeof(struct _Ethumb_Object)); + tmp = realloc(q->list, new_max * sizeof(int)); + if (!tmp) + { + CRIT("could not realloc q->list to %zd bytes: %s", + new_max * sizeof(int), strerror(errno)); + return -1; + } + q->list = tmp; + q->max_count = new_max; } @@ -874,6 +914,8 @@ _ethumb_dbus_ethumb_new_cb(E_DBus_Object *object, DBusMessage *msg) goto end_new; i = _ethumb_table_append(ed); + if (i < 0) + goto end_new; odata = calloc(1, sizeof(*odata)); odata->index = i; diff --git a/src/bin/ethumbd_client.c b/src/bin/ethumbd_client.c index edf2d13..a5166fd 100644 --- a/src/bin/ethumbd_client.c +++ b/src/bin/ethumbd_client.c @@ -223,7 +223,7 @@ main(int argc, char *argv[]) { Ethumb_Client *c; Eina_Bool quit_option = 0; - const char *format_str, *aspect_str; + const char *format_str = NULL, *aspect_str; struct options opts = { {-1, -1, -1, -1}, 0, 0, diff --git a/src/lib/Ethumb.c b/src/lib/Ethumb.c index 995f7d1..ee08c0e 100644 --- a/src/lib/Ethumb.c +++ b/src/lib/Ethumb.c @@ -910,6 +910,12 @@ _ethumb_file_generate_path(Ethumb *e) category = eina_stringshare_ref(_thumb_category_normal); else if (e->tw == THUMB_SIZE_LARGE) category = eina_stringshare_ref(_thumb_category_large); + else + { + ERR("fdo_format but size %d is not NORMAL (%d) or LARGE (%d)?", + e->tw, THUMB_SIZE_NORMAL, THUMB_SIZE_LARGE); + category = "unknown"; + } } if (e->format == ETHUMB_THUMB_FDO) diff --git a/src/plugins/emotion/emotion.c b/src/plugins/emotion/emotion.c index efa0497..b3f5950 100644 --- a/src/plugins/emotion/emotion.c +++ b/src/plugins/emotion/emotion.c @@ -317,7 +317,6 @@ _generate_thumb(Ethumb *e) _plugin->video = o; ethumb_file_get(e, &file, NULL); - ethumb_video_start_get(e); f = ethumb_thumb_format_get(e); emotion_object_file_set(o, file); -- 2.7.4