summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2004-04-22 20:51:07 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2004-04-22 20:51:07 +0000
commit2efb5e1cd8b8600eca30a0f188cb522cf24e74ad (patch)
tree245ad01824799480a72d5eac4e69a7c28ee2be6b
parent05501852ecb0bd3d048273c0ac063fe739983d8d (diff)
downloadglib-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--ChangeLog5
-rw-r--r--ChangeLog.pre-2-105
-rw-r--r--ChangeLog.pre-2-125
-rw-r--r--ChangeLog.pre-2-45
-rw-r--r--ChangeLog.pre-2-65
-rw-r--r--ChangeLog.pre-2-85
-rw-r--r--glib/gqueue.c2
-rw-r--r--tests/queue-test.c18
8 files changed, 47 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index fe7d16027..54b41fcc0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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;
}