Denys Vlasenko <dvlasenk(a)redhat.com> writes:
On Wed, 2011-07-27 at 16:17 +0200, Nikola Pajkovsky wrote:
> Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
Why is this needed?
> +gint cmp_problem_data(gconstpointer a, gconstpointer b, gpointer filename)
> +{
> + char *endptr;
> + problem_data_t *a_data = (problem_data_t *) ((GPtrArray*) a)->pdata;
This cast looks fishy.
I assume you are using this function as GCompareFunc for
g_ptr_array_sort. Then:
>Note
>The comparison function for g_ptr_array_sort() doesn't take the
>pointers from the array as arguments, it takes pointers to the pointers
>in the array.
IOW: a and b are not pointers to GPtrArray. Thye are pointers to
pointers STORED in a GPtrArray.
The cast as written above works by pure chance, because _GPtrArray is:
struct _GPtrArray
{
gpointer *pdata;
guint len;
};
and (problem_data_t *) ((GPtrArray*) a)->pdata on assembly level
is the same as correct cast: *((problem_data_t**)a).
but if struct _GPtrArray would be
struct _GPtrArray
{
guint len;
gpointer *pdata;
};
it wouldn't be.
> + const char *a_time_str = get_problem_item_content_or_NULL(a_data, filename);
> + unsigned long a_time= strtoul(a_time_str, &endptr, 10);
If you don't use endptr, you don't need to pass it - can just pass NULL
instead of &endptr.
Thanks for the explanation. I was sleepwalking, when I was writing the
patch. Tested, pushed.
--
Save the whales. Feed the hungry. Free the mallocs