Commit 2efb5e1c authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Add some tests for off-by-one errors.

2004-04-22  Matthias Clasen  <mclasen@redhat.com>

	* tests/queue-test.c (main): Add some tests for off-by-one errors.

	* glib/gqueue.c (g_queue_pop_nth_link): Fix an off-by-one
	error.  (#139703, Philippe Blain)
parent 05501852
2004-04-22 Matthias Clasen <mclasen@redhat.com>
* tests/queue-test.c (main): Add some tests for off-by-one errors.
* glib/gqueue.c (g_queue_pop_nth_link): Fix an off-by-one
error. (#139703, Philippe Blain)
* tests/testglib.c (main): Add testcases for g_message() involving
non-printable and unsafe characters.
......
2004-04-22 Matthias Clasen <mclasen@redhat.com>
* tests/queue-test.c (main): Add some tests for off-by-one errors.
* glib/gqueue.c (g_queue_pop_nth_link): Fix an off-by-one
error. (#139703, Philippe Blain)
* tests/testglib.c (main): Add testcases for g_message() involving
non-printable and unsafe characters.
......
2004-04-22 Matthias Clasen <mclasen@redhat.com>
* tests/queue-test.c (main): Add some tests for off-by-one errors.
* glib/gqueue.c (g_queue_pop_nth_link): Fix an off-by-one
error. (#139703, Philippe Blain)
* tests/testglib.c (main): Add testcases for g_message() involving
non-printable and unsafe characters.
......
2004-04-22 Matthias Clasen <mclasen@redhat.com>
* tests/queue-test.c (main): Add some tests for off-by-one errors.
* glib/gqueue.c (g_queue_pop_nth_link): Fix an off-by-one
error. (#139703, Philippe Blain)
* tests/testglib.c (main): Add testcases for g_message() involving
non-printable and unsafe characters.
......
2004-04-22 Matthias Clasen <mclasen@redhat.com>
* tests/queue-test.c (main): Add some tests for off-by-one errors.
* glib/gqueue.c (g_queue_pop_nth_link): Fix an off-by-one
error. (#139703, Philippe Blain)
* tests/testglib.c (main): Add testcases for g_message() involving
non-printable and unsafe characters.
......
2004-04-22 Matthias Clasen <mclasen@redhat.com>
* tests/queue-test.c (main): Add some tests for off-by-one errors.
* glib/gqueue.c (g_queue_pop_nth_link): Fix an off-by-one
error. (#139703, Philippe Blain)
* tests/testglib.c (main): Add testcases for g_message() involving
non-printable and unsafe characters.
......
......@@ -662,7 +662,7 @@ g_queue_pop_nth_link (GQueue *queue,
g_return_val_if_fail (queue != NULL, NULL);
if (n > queue->length)
if (n >= queue->length)
return NULL;
link = g_queue_peek_nth_link (queue, n);
......
......@@ -927,14 +927,28 @@ int main(int argc, gchar *args[])
g_queue_foreach (q2, remove_item, q2);
check_integrity (q2);
check_integrity (q);
/* some checks for off by one errors */
g_queue_push_tail (q, GINT_TO_POINTER (1234));
check_integrity (q);
node = g_queue_peek_tail_link (q);
g_assert (node != NULL && node->data == GINT_TO_POINTER (1234));
node = g_queue_peek_nth_link (q, g_queue_get_length (q));
g_assert (node == NULL);
node = g_queue_peek_nth_link (q, g_queue_get_length (q) - 1);
g_assert (node->data == GINT_TO_POINTER (1234));
node = g_queue_pop_nth_link (q, g_queue_get_length (q));
g_assert (node == NULL);
node = g_queue_pop_nth_link (q, g_queue_get_length (q) - 1);
g_assert (node != NULL && node->data == GINT_TO_POINTER (1234));
g_queue_free (q);
if (argc > 1)
random_test (strtol (args[1], NULL, 0));
else
random_test (time (0));
random_test (time (0));
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment