diff --git a/meson.build b/meson.build index f594ae71..e87c647a 100644 --- a/meson.build +++ b/meson.build @@ -660,7 +660,6 @@ script_sources = files('./doc/create-doxygen-lua-api.sh', './scripts/authors.sh', './scripts/check-compiles.sh', './scripts/doxygen-help.sh', -'./scripts/doxygen.sh', './scripts/generate-ClayRGB1998-icc-h.sh', './scripts/generate-appimage.sh', './scripts/generate-linuxdeploy-for-arm.sh', diff --git a/src/collect.cc b/src/collect.cc index 57f3387a..e91c8b08 100644 --- a/src/collect.cc +++ b/src/collect.cc @@ -204,20 +204,17 @@ GList *collection_list_sort(GList *list, SortType method) GList *collection_list_randomize(GList *list) { - guint random, length, i; + guint length, i; gpointer tmp; GList *nlist, *olist; length = g_list_length(list); if (!length) return nullptr; - srand(static_cast(time(nullptr))); // Initialize random generator (hasn't to be that much strong) - for (i = 0; i < length; i++) { - random = static_cast(1.0 * length * rand()/(RAND_MAX + 1.0)); olist = g_list_nth(list, i); - nlist = g_list_nth(list, random); + nlist = g_list_nth(list, g_random_int_range(0, length)); tmp = olist->data; olist->data = nlist->data; nlist->data = tmp; diff --git a/src/exif-common.cc b/src/exif-common.cc index ac95a855..bbb63cd0 100644 --- a/src/exif-common.cc +++ b/src/exif-common.cc @@ -211,7 +211,7 @@ static gchar *exif_build_formatted_DateTime(ExifData *exif) memset(&tm, 0, sizeof(tm)); /* Uh, strptime could let garbage in tm! */ if (text && strptime(text, "%Y:%m:%d %H:%M:%S", &tm)) { - buflen = strftime(buf, sizeof(buf), "%x %X", &tm); + buflen = strftime(buf, sizeof(buf), "%F %X", &tm); if (buflen > 0) { tmp = g_locale_to_utf8(buf, buflen, nullptr, nullptr, &error); @@ -262,7 +262,7 @@ static gchar *exif_build_formatted_DateTimeDigitized(ExifData *exif) memset(&tm, 0, sizeof(tm)); /* Uh, strptime could let garbage in tm! */ if (text && strptime(text, "%Y:%m:%d %H:%M:%S", &tm)) { - buflen = strftime(buf, sizeof(buf), "%x %X", &tm); + buflen = strftime(buf, sizeof(buf), "%F %X", &tm); if (buflen > 0) { tmp = g_locale_to_utf8(buf, buflen, nullptr, nullptr, &error); @@ -788,7 +788,7 @@ static gchar *exif_build_formatted_localtime(ExifData *exif) tm_local = localtime(&stamp); /* Convert to localtime using locale */ - buflen = strftime(buf, sizeof(buf), "%x %X", tm_local); + buflen = strftime(buf, sizeof(buf), "%F %X", tm_local); if (buflen > 0) { tmp = g_locale_to_utf8(buf, buflen, nullptr, nullptr, &error); diff --git a/src/filedata.cc b/src/filedata.cc index 52d348af..4e441c53 100644 --- a/src/filedata.cc +++ b/src/filedata.cc @@ -136,7 +136,7 @@ const gchar *text_from_time(time_t t) btime = localtime(&t); /* the %x warning about 2 digit years is not an error */ - buflen = strftime(buf, sizeof(buf), "%x %X", btime); + buflen = strftime(buf, sizeof(buf), "%F %X", btime); if (buflen < 1) return ""; g_free(ret); @@ -705,7 +705,9 @@ void file_data_dump() { list = g_hash_table_get_values(file_data_pool); +#ifdef DEBUG_FILEDATA log_printf("%d", global_file_data_count); +#endif log_printf("%d", g_list_length(list)); while (list) diff --git a/src/filedata.h b/src/filedata.h index 49a1476f..39992652 100644 --- a/src/filedata.h +++ b/src/filedata.h @@ -22,9 +22,7 @@ #ifndef FILEDATA_H #define FILEDATA_H -#ifdef DEBUG -#define DEBUG_FILEDATA -#endif +#undef DEBUG_FILEDATA #define FD_MAGICK 0x12345678u diff --git a/src/image-load-heif.cc b/src/image-load-heif.cc index 68de7f75..d4a89b90 100644 --- a/src/image-load-heif.cc +++ b/src/image-load-heif.cc @@ -63,7 +63,7 @@ static gboolean image_loader_heif_load(gpointer loader, const guchar *buf, gsize error_code = heif_context_read_from_memory_without_copy(ctx, buf, count, NULL); if (error_code.code) { - log_printf("warning: heif reader error: %s\n", error_code.message); + log_printf("warning: heif (heif_context_read_from_memory_without_copy) reader error: %s\n", error_code.message); heif_context_free(ctx); return FALSE; } @@ -80,7 +80,7 @@ static gboolean image_loader_heif_load(gpointer loader, const guchar *buf, gsize error_code = heif_context_get_image_handle(ctx, IDs[ld->page_num], &handle); if (error_code.code) { - log_printf("warning: heif reader error: %s\n", error_code.message); + log_printf("warning: heif (heif_context_get_image_handle) reader error: %s\n", error_code.message); heif_context_free(ctx); return FALSE; } @@ -89,7 +89,7 @@ static gboolean image_loader_heif_load(gpointer loader, const guchar *buf, gsize error_code = heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_24bit, NULL); if (error_code.code) { - log_printf("warning: heif reader error: %s\n", error_code.message); + log_printf("warning: heif (heif_decode_image) reader error: %s\n", error_code.message); heif_context_free(ctx); return FALSE; } diff --git a/src/image-load.cc b/src/image-load.cc index 7f743ec9..18203013 100644 --- a/src/image-load.cc +++ b/src/image-load.cc @@ -1063,7 +1063,7 @@ static gboolean image_loader_setup_source(ImageLoader *il) return FALSE; } - il->mapped_file = static_cast(mmap(nullptr, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0)); + il->mapped_file = static_cast(mmap(nullptr, il->bytes_total, PROT_READ, MAP_PRIVATE, load_fd, 0)); close(load_fd); if (il->mapped_file == MAP_FAILED) { diff --git a/src/main.cc b/src/main.cc index ac6f97fb..85baee74 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1303,10 +1303,6 @@ gint main(gint argc, gchar *argv[]) #ifdef HAVE_LUA lua_init(); #endif - - /* setup random seed for random slideshow */ - srand(time(nullptr)); - #if 0 /* See later comment; this handler leads to UB. */ setup_sigbus_handler(); diff --git a/src/slideshow.cc b/src/slideshow.cc index 0cf242df..6d1369e6 100644 --- a/src/slideshow.cc +++ b/src/slideshow.cc @@ -102,10 +102,9 @@ static void ptr_array_random_shuffle(GPtrArray *array) { guint i; for (i = 0; i < array->len; ++i) - { - guint p = static_cast(rand()) / (static_cast(RAND_MAX) + 1.0) * array->len; - swap(array, i, p); - } + { + swap(array, i, g_random_int_range(0, array->len)); + } } static GList *generate_random_list(SlideShowData *ss) diff --git a/src/thumb-standard.cc b/src/thumb-standard.cc index fa0c5bd0..e6f5b025 100644 --- a/src/thumb-standard.cc +++ b/src/thumb-standard.cc @@ -32,6 +32,7 @@ #include "metadata.h" #include "color-man.h" +#include /** * @file @@ -231,9 +232,13 @@ static gboolean thumb_loader_std_fail_check(ThumbLoaderStd *tl) if (pixbuf) { const gchar *mtime_str; + const gchar *size_str; mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); - if (mtime_str && strtol(mtime_str, nullptr, 10) == tl->source_mtime) + size_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_SIZE); + if (mtime_str && size_str && + strtoll(mtime_str, NULL, 10) == tl->source_mtime && + strtoll(size_str, NULL, 10) == tl->source_size) { result = TRUE; DEBUG_1("thumb fail valid: %s", tl->fd->path); @@ -255,7 +260,9 @@ static gboolean thumb_loader_std_validate(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) const gchar *valid_uri; const gchar *uri; const gchar *mtime_str; + const gchar *size_str; time_t mtime; + off_t fsize; gint w, h; if (!pixbuf) return FALSE; @@ -270,12 +277,16 @@ static gboolean thumb_loader_std_validate(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); + size_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_SIZE); - if (!mtime_str || !uri || !valid_uri) return FALSE; + if (!mtime_str || !size_str || !uri || !valid_uri) return FALSE; if (strcmp(uri, valid_uri) != 0) return FALSE; - mtime = strtol(mtime_str, nullptr, 10); - if (tl->source_mtime != mtime) return FALSE; + errno = 0; + mtime = strtoll(mtime_str, NULL, 10); + if (errno || tl->source_mtime != mtime) return FALSE; + fsize = strtoll(size_str, NULL, 10); + if (errno || tl->source_size != fsize) return FALSE; return TRUE; } @@ -344,6 +355,7 @@ static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) const gchar *mark_uri; gchar *mark_app; gchar *mark_mtime; + gchar *mark_size; gchar *pathl; gboolean success; @@ -351,10 +363,12 @@ static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) mark_app = g_strdup_printf("%s %s", GQ_APPNAME, VERSION); mark_mtime = g_strdup_printf("%llu", static_cast(tl->source_mtime)); + mark_size = g_strdup_printf("%llu", static_cast(tl->source_size)); pathl = path_from_utf8(tmp_path); success = gdk_pixbuf_save(pixbuf, pathl, "png", nullptr, THUMB_MARKER_URI, mark_uri, THUMB_MARKER_MTIME, mark_mtime, + THUMB_MARKER_SIZE, mark_size, THUMB_MARKER_APP, mark_app, NULL); if (success) @@ -366,6 +380,7 @@ static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) g_free(pathl); g_free(mark_mtime); + g_free(mark_size); g_free(mark_app); g_free(tmp_path); @@ -931,10 +946,13 @@ static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *UNUSED( { const gchar *uri; const gchar *mtime_str; + const gchar *size_str; uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); - if (uri && mtime_str) + size_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_SIZE); + + if (uri && mtime_str && size_str) { if (strncmp(uri, "file:", strlen("file:")) == 0) { @@ -943,7 +961,8 @@ static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *UNUSED( target = g_filename_from_uri(uri, nullptr, nullptr); if (stat(target, &st) == 0 && - st.st_mtime == strtol(mtime_str, nullptr, 10)) + st.st_mtime == strtoll(mtime_str, NULL, 10) && + st.st_size == strtoll(size_str, NULL, 10)) { valid = TRUE; } @@ -1098,11 +1117,13 @@ static void thumb_std_maint_move_validate_cb(const gchar *UNUSED(path), gboolean { const gchar *uri; const gchar *mtime_str; + const gchar *size_str; uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); + size_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_SIZE); - if (uri && mtime_str && strcmp(uri, tm->source_uri) == 0) + if (uri && mtime_str && size_str && strcmp(uri, tm->source_uri) == 0) { gchar *pathl; @@ -1116,7 +1137,8 @@ static void thumb_std_maint_move_validate_cb(const gchar *UNUSED(path), gboolean tm->tl->cache_local = FALSE; file_data_unref(tm->tl->fd); tm->tl->fd = file_data_new_group(tm->dest); - tm->tl->source_mtime = strtol(mtime_str, nullptr, 10); + tm->tl->source_mtime = strtoll(mtime_str, NULL, 10); + tm->tl->source_size = strtoll(size_str, NULL, 10); pathl = path_from_utf8(tm->tl->fd->path); g_free(tm->tl->thumb_uri);