mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
053a1ce434
Tue May 7 11:24:22 2002 Owen Taylor <otaylor@redhat.com> Fixes for #79347, Ron Arts. * glib/gqsort.c (g_qsort_with_data): Handle 0 elements, don't g_return_if_fail(). * tests/qsort-test.c (main): Add a 0 element test. * glib/garray.c (g_[ptr_]array_sort_with[_data]): Remove invalid assertions that array->pdata != NULL .. it's NULL for 0 elements which is a valid case.
31 lines
525 B
C
31 lines
525 B
C
#include <glib.h>
|
|
|
|
#define SIZE 100000
|
|
|
|
guint32 array[SIZE];
|
|
|
|
static gint
|
|
sort (gconstpointer a, gconstpointer b, gpointer user_data)
|
|
{
|
|
return *(guint32*)a < *(guint32*)b ? -1 : 1;
|
|
}
|
|
|
|
int
|
|
main ()
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < SIZE; i++)
|
|
array[i] = g_random_int ();
|
|
|
|
g_qsort_with_data (array, SIZE, sizeof (guint32), sort, NULL);
|
|
|
|
for (i = 0; i < SIZE - 1; i++)
|
|
g_assert (array[i] <= array[i+1]);
|
|
|
|
/* 0 elemenents is a valid case */
|
|
g_qsort_with_data (array, 0, sizeof (guint32), sort, NULL);
|
|
|
|
return 0;
|
|
}
|