summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKrzesimir Nowak <qdlacz@gmail.com>2011-03-20 19:39:39 +0100
committerMurray Cumming <murrayc@murrayc.com>2011-03-21 09:23:08 +0100
commitdefb0eba23019ab01dbf7a80bfa6b2d87a4bc2a4 (patch)
tree709b35355d52df33f50ff5b7132720b3e8ec5d63 /tests
parent29198769ae1927629186a53642a7de3e13c36c68 (diff)
downloadglibmm-defb0eba23019ab01dbf7a80bfa6b2d87a4bc2a4.tar.gz
Vectorutils, ArrayHandle: Check for NULL pointers.
* glib/glibmm/vectorutils.[h|cc]: Don't crash in compute_array_size2, when NULL is passed - in that case just return 0. Also, array_to_vector method return empty vector in such case. * glib/glibmm/arrayhandle.[h|cc]: Set array_size to zero if passed array is NULL. * tests/glibmm_null_vectorutils/main.cc: New test for NULL arrays and lists for vectorutils. * tests/glibmm_null_containerhandle/main.cc: New test for NULL arrays and lists for containerhandles. * tests/Makefile.am: Added new tests to build. Spotted by Kalev Lember. Bug #645245.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am38
-rw-r--r--tests/glibmm_null_containerhandle/main.cc43
-rw-r--r--tests/glibmm_null_vectorutils/main.cc41
-rw-r--r--tests/glibmm_vector/main.cc4
4 files changed, 108 insertions, 18 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a1f2aa28..dc8bcb45 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-## Copyright (c) 2009, 2010 Openismus GmbH <http://www.openismus.com/>
+## Copyright (c) 2009, 2010, 2011 Openismus GmbH <http://www.openismus.com/>
##
## This file is part of glibmm.
##
@@ -19,7 +19,7 @@ AUTOMAKE_OPTIONS = subdir-objects
check_PROGRAMS = \
giomm_ioerror/test \
- giomm_ioerror_and_iodbuserror/test \
+ giomm_ioerror_and_iodbuserror/test \
giomm_simple/test \
giomm_asyncresult_sourceobject/test \
glibmm_btree/test \
@@ -33,7 +33,9 @@ check_PROGRAMS = \
glibmm_variant/test \
glibmm_vector/test \
glibmm_bool_vector/test \
- glibmm_bool_arrayhandle/test
+ glibmm_bool_arrayhandle/test \
+ glibmm_null_vectorutils/test \
+ glibmm_null_containerhandle/test
TESTS = $(check_PROGRAMS)
@@ -62,16 +64,20 @@ giomm_simple_test_LDADD = $(giomm_ldadd)
giomm_asyncresult_sourceobject_test_SOURCES = giomm_asyncresult_sourceobject/main.cc
giomm_asyncresult_sourceobject_test_LDADD = $(giomm_ldadd)
-glibmm_btree_test_SOURCES = glibmm_btree/main.cc
-glibmm_buildfilename_test_SOURCES = glibmm_buildfilename/main.cc
-glibmm_date_test_SOURCES = glibmm_date/main.cc
-glibmm_nodetree_test_SOURCES = glibmm_nodetree/main.cc
-glibmm_ustring_compose_test_SOURCES = glibmm_ustring_compose/main.cc
-glibmm_ustring_format_test_SOURCES = glibmm_ustring_format/main.cc
-glibmm_value_test_SOURCES = glibmm_value/glibmm_value.cc glibmm_value/main.cc
-glibmm_valuearray_test_SOURCES = glibmm_valuearray/main.cc
-glibmm_variant_test_SOURCES = glibmm_variant/main.cc
-glibmm_vector_test_SOURCES = glibmm_vector/main.cc
-glibmm_vector_test_LDADD = $(giomm_ldadd)
-glibmm_bool_vector_test_SOURCES = glibmm_bool_vector/main.cc
-glibmm_bool_arrayhandle_test_SOURCES = glibmm_bool_arrayhandle/main.cc
+glibmm_btree_test_SOURCES = glibmm_btree/main.cc
+glibmm_buildfilename_test_SOURCES = glibmm_buildfilename/main.cc
+glibmm_date_test_SOURCES = glibmm_date/main.cc
+glibmm_nodetree_test_SOURCES = glibmm_nodetree/main.cc
+glibmm_ustring_compose_test_SOURCES = glibmm_ustring_compose/main.cc
+glibmm_ustring_format_test_SOURCES = glibmm_ustring_format/main.cc
+glibmm_value_test_SOURCES = glibmm_value/glibmm_value.cc glibmm_value/main.cc
+glibmm_valuearray_test_SOURCES = glibmm_valuearray/main.cc
+glibmm_variant_test_SOURCES = glibmm_variant/main.cc
+glibmm_vector_test_SOURCES = glibmm_vector/main.cc
+glibmm_vector_test_LDADD = $(giomm_ldadd)
+glibmm_bool_vector_test_SOURCES = glibmm_bool_vector/main.cc
+glibmm_bool_arrayhandle_test_SOURCES = glibmm_bool_arrayhandle/main.cc
+glibmm_null_vectorutils_test_SOURCES = glibmm_null_vectorutils/main.cc
+glibmm_null_vectorutils_test_LDADD = $(giomm_ldadd)
+glibmm_null_containerhandle_test_SOURCES = glibmm_null_containerhandle/main.cc
+glibmm_null_containerhandle_test_LDADD = $(giomm_ldadd)
diff --git a/tests/glibmm_null_containerhandle/main.cc b/tests/glibmm_null_containerhandle/main.cc
new file mode 100644
index 00000000..596457d0
--- /dev/null
+++ b/tests/glibmm_null_containerhandle/main.cc
@@ -0,0 +1,43 @@
+/* Copyright (C) 2011 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/arrayhandle.h>
+#include <glibmm/listhandle.h>
+#include <glibmm/slisthandle.h>
+
+#include <giomm/credentials.h>
+#include <giomm/init.h>
+
+int
+main()
+{
+ Gio::init();
+ typedef Glib::RefPtr<Gio::Credentials> CrePtr;
+
+ std::vector<CrePtr> v1(Glib::ArrayHandle<CrePtr>(0, Glib::OWNERSHIP_DEEP));
+ std::vector<CrePtr> v2(Glib::ArrayHandle<CrePtr>(0, 5, Glib::OWNERSHIP_DEEP));
+ std::vector<CrePtr> v3(Glib::ListHandle<CrePtr>(0, Glib::OWNERSHIP_DEEP));
+ std::vector<CrePtr> v4(Glib::SListHandle<CrePtr>(0, Glib::OWNERSHIP_DEEP));
+ std::vector<bool> v5(Glib::ArrayHandle<bool>(0, Glib::OWNERSHIP_DEEP));
+ std::vector<bool> v6(Glib::ArrayHandle<bool>(0, 5, Glib::OWNERSHIP_DEEP));
+
+ if (v1.empty() && v2.empty() && v3.empty() && v4.empty() && v5.empty() && v6.empty())
+ {
+ return 0;
+ }
+ return 1;
+}
diff --git a/tests/glibmm_null_vectorutils/main.cc b/tests/glibmm_null_vectorutils/main.cc
new file mode 100644
index 00000000..567d4177
--- /dev/null
+++ b/tests/glibmm_null_vectorutils/main.cc
@@ -0,0 +1,41 @@
+/* Copyright (C) 2011 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/vectorutils.h>
+
+#include <giomm/credentials.h>
+#include <giomm/init.h>
+
+int
+main()
+{
+ Gio::init();
+ typedef Glib::RefPtr<Gio::Credentials> CrePtr;
+
+ std::vector<CrePtr> v1(Glib::ArrayHandler<CrePtr>::array_to_vector(0, Glib::OWNERSHIP_DEEP));
+ std::vector<CrePtr> v2(Glib::ArrayHandler<CrePtr>::array_to_vector(0, 5, Glib::OWNERSHIP_DEEP));
+ std::vector<CrePtr> v3(Glib::ListHandler<CrePtr>::list_to_vector(0, Glib::OWNERSHIP_DEEP));
+ std::vector<CrePtr> v4(Glib::SListHandler<CrePtr>::slist_to_vector(0, Glib::OWNERSHIP_DEEP));
+ std::vector<bool> v5(Glib::ArrayHandler<bool>::array_to_vector(0, Glib::OWNERSHIP_DEEP));
+ std::vector<bool> v6(Glib::ArrayHandler<bool>::array_to_vector(0, 5, Glib::OWNERSHIP_DEEP));
+
+ if (v1.empty() && v2.empty() && v3.empty() && v4.empty() && v5.empty() && v6.empty())
+ {
+ return 0;
+ }
+ return 1;
+}
diff --git a/tests/glibmm_vector/main.cc b/tests/glibmm_vector/main.cc
index db6d2f61..b1ae14bb 100644
--- a/tests/glibmm_vector/main.cc
+++ b/tests/glibmm_vector/main.cc
@@ -46,7 +46,7 @@ create_list()
{
head = g_list_prepend(head, g_credentials_new());
}
-
+
return g_list_reverse(head);
}
@@ -78,7 +78,7 @@ create_slist()
{
head = g_slist_prepend(head, g_credentials_new());
}
-
+
return g_slist_reverse(head);
}