recentchooser: fix sort overflow for far-apart times
This commit is contained in:
parent
935817582d
commit
f73ca30823
3 changed files with 23 additions and 2 deletions
|
|
@ -300,9 +300,16 @@ sort_recent_items_mru (GtkRecentInfo *a,
|
|||
GtkRecentInfo *b,
|
||||
gpointer unused)
|
||||
{
|
||||
gint64 time_a, time_b;
|
||||
|
||||
g_assert (a != NULL && b != NULL);
|
||||
|
||||
return gtk_recent_info_get_modified (b) - gtk_recent_info_get_modified (a);
|
||||
/* compared, not subtracted: the difference of two times does not fit
|
||||
* into the gint returned when they are more than 68 years apart */
|
||||
time_a = _gtk_recent_info_get_modified_time (a);
|
||||
time_b = _gtk_recent_info_get_modified_time (b);
|
||||
|
||||
return time_b < time_a ? -1 : (time_b > time_a ? 1 : 0);
|
||||
}
|
||||
|
||||
static gint
|
||||
|
|
@ -312,7 +319,7 @@ sort_recent_items_lru (GtkRecentInfo *a,
|
|||
{
|
||||
g_assert (a != NULL && b != NULL);
|
||||
|
||||
return -1 * (gtk_recent_info_get_modified (b) - gtk_recent_info_get_modified (a));
|
||||
return -sort_recent_items_mru (a, b, unused);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ void _gtk_recent_chooser_set_delegate (GtkRecentChooser *receiver,
|
|||
|
||||
GQuark _gtk_recent_chooser_delegate_get_quark (void);
|
||||
|
||||
gint64 _gtk_recent_info_get_modified_time (GtkRecentInfo *info);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_RECENT_CHOOSER_UTILS_H__ */
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include <gio/gio.h>
|
||||
|
||||
#include "gtkrecentmanager.h"
|
||||
#include "gtkrecentchooserutils.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkstock.h"
|
||||
#include "gtkicontheme.h"
|
||||
|
|
@ -2067,6 +2068,17 @@ gtk_recent_info_get_visited (GtkRecentInfo *info)
|
|||
return recent_time_to_time_t (info->visited);
|
||||
}
|
||||
|
||||
/* The time of the last change as kept, in 64 bits, for sorting inside
|
||||
* GTK+; gtk_recent_info_get_modified() gives a time_t, which may be 32
|
||||
* bits. */
|
||||
gint64
|
||||
_gtk_recent_info_get_modified_time (GtkRecentInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (info != NULL, -1);
|
||||
|
||||
return info->modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_recent_info_get_private_hint:
|
||||
* @info: a #GtkRecentInfo
|
||||
|
|
|
|||
Loading…
Reference in a new issue