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)
This commit is contained in:
Matthias Clasen 2004-04-22 20:51:07 +00:00 committed by Matthias Clasen
parent 05501852ec
commit 2efb5e1cd8
8 changed files with 47 additions and 3 deletions

View File

@ -1,5 +1,10 @@
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.

View File

@ -1,5 +1,10 @@
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.

View File

@ -1,5 +1,10 @@
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.

View File

@ -1,5 +1,10 @@
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.

View File

@ -1,5 +1,10 @@
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.

View File

@ -1,5 +1,10 @@
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.

View File

@ -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);

View File

@ -928,6 +928,20 @@ int main(int argc, gchar *args[])
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)