diff options
author | Matthias Clasen <mclasen@redhat.com> | 2004-04-22 20:51:07 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2004-04-22 20:51:07 +0000 |
commit | 2efb5e1cd8b8600eca30a0f188cb522cf24e74ad (patch) | |
tree | 245ad01824799480a72d5eac4e69a7c28ee2be6b | |
parent | 05501852ecb0bd3d048273c0ac063fe739983d8d (diff) | |
download | glib-2efb5e1cd8b8600eca30a0f188cb522cf24e74ad.tar.gz |
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)
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 5 | ||||
-rw-r--r-- | ChangeLog.pre-2-12 | 5 | ||||
-rw-r--r-- | ChangeLog.pre-2-4 | 5 | ||||
-rw-r--r-- | ChangeLog.pre-2-6 | 5 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 5 | ||||
-rw-r--r-- | glib/gqueue.c | 2 | ||||
-rw-r--r-- | tests/queue-test.c | 18 |
8 files changed, 47 insertions, 3 deletions
@@ -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. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index fe7d16027..54b41fcc0 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -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. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index fe7d16027..54b41fcc0 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -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. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index fe7d16027..54b41fcc0 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -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. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index fe7d16027..54b41fcc0 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -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. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index fe7d16027..54b41fcc0 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -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. diff --git a/glib/gqueue.c b/glib/gqueue.c index 5d5ef09cc..b81167022 100644 --- a/glib/gqueue.c +++ b/glib/gqueue.c @@ -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); diff --git a/tests/queue-test.c b/tests/queue-test.c index 688b56ef1..aeb1df3e5 100644 --- a/tests/queue-test.c +++ b/tests/queue-test.c @@ -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; } |