This is an automated email from the git hooks/post-receive script. rene pushed a commit to branch master in repository mdds.
commit 1c0e8a4317f3bae10a2f5e06234ce920a281a494 Author: Rene Engelhard <[email protected]> Date: Thu Apr 21 14:50:53 2016 +0200 Imported Upstream version 0.11.1 --- NEWS | 12 ++ configure | 32 ++--- configure.ac | 2 +- include/mdds/flat_segment_tree.hpp | 12 ++ include/mdds/mixed_type_matrix_flag_storage.hpp | 2 + include/mdds/mixed_type_matrix_storage_sparse.inl | 4 +- include/mdds/multi_type_matrix_def.inl | 18 +-- include/mdds/multi_type_vector_def.inl | 4 +- include/mdds/point_quad_tree.hpp | 4 - include/mdds/quad_node.hpp | 15 +- include/mdds/segment_tree.hpp | 12 +- misc/sorted_string_map_perf.cpp | 166 ++++++++++++++++++++++ src/flat_segment_tree_test.cpp | 112 ++++++++------- src/mixed_type_matrix_test.cpp | 82 ++++++----- src/multi_type_matrix_test.cpp | 58 ++++---- src/multi_type_vector_test_custom.cpp | 94 ++++++++++-- src/multi_type_vector_test_default.cpp | 78 +++++----- src/point_quad_tree_test.cpp | 30 ++-- src/rectangle_set_test.cpp | 38 +++-- src/segment_tree_test.cpp | 59 ++++---- 20 files changed, 581 insertions(+), 253 deletions(-) diff --git a/NEWS b/NEWS index 65287d3..b00d0d0 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,15 @@ +mdds 0.11.1 + +* all + + * fixed a large number of outstanding defects reported by Coverity + Scan. + +* multi_type_vector + + * fixed 2 cases of double-free bug in the variant of swap() that + allows segmented swapping. + mdds 0.11.0 * sorted_string_map (new) diff --git a/configure b/configure index 46d9ba5..caa8c78 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for mdds 0.11.0. +# Generated by GNU Autoconf 2.69 for mdds 0.11.1. # # Report bugs to <[email protected]>. # @@ -579,8 +579,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='mdds' PACKAGE_TARNAME='mdds' -PACKAGE_VERSION='0.11.0' -PACKAGE_STRING='mdds 0.11.0' +PACKAGE_VERSION='0.11.1' +PACKAGE_STRING='mdds 0.11.1' PACKAGE_BUGREPORT='[email protected]' PACKAGE_URL='' @@ -1181,7 +1181,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures mdds 0.11.0 to adapt to many kinds of systems. +\`configure' configures mdds 0.11.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1242,7 +1242,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of mdds 0.11.0:";; + short | recursive ) echo "Configuration of mdds 0.11.1:";; esac cat <<\_ACEOF @@ -1335,7 +1335,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -mdds configure 0.11.0 +mdds configure 0.11.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1352,7 +1352,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by mdds $as_me 0.11.0, which was +It was created by mdds $as_me 0.11.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -1701,7 +1701,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -VERSION=0.11.0 +VERSION=0.11.1 PACKAGE_TARNAME=mdds @@ -2298,7 +2298,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by mdds $as_me 0.11.0, which was +This file was extended by mdds $as_me 0.11.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -2351,7 +2351,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -mdds config.status 0.11.0 +mdds config.status 0.11.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -3455,7 +3455,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by mdds $as_me 0.11.0, which was +This file was extended by mdds $as_me 0.11.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -3508,7 +3508,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -mdds config.status 0.11.0 +mdds config.status 0.11.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -4613,7 +4613,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by mdds $as_me 0.11.0, which was +This file was extended by mdds $as_me 0.11.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4666,7 +4666,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -mdds config.status 0.11.0 +mdds config.status 0.11.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -5772,7 +5772,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by mdds $as_me 0.11.0, which was +This file was extended by mdds $as_me 0.11.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5825,7 +5825,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -mdds config.status 0.11.0 +mdds config.status 0.11.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 25e597b..c56e41e 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(mdds, 0.11.0, [email protected]) +AC_INIT(mdds, 0.11.1, [email protected]) VERSION=AC_PACKAGE_VERSION AC_SUBST(VERSION) diff --git a/include/mdds/flat_segment_tree.hpp b/include/mdds/flat_segment_tree.hpp index 184ca34..3630c40 100644 --- a/include/mdds/flat_segment_tree.hpp +++ b/include/mdds/flat_segment_tree.hpp @@ -61,6 +61,12 @@ public: { return low == r.low && high == r.high; } + + nonleaf_value_type() + : low(0) + , high(0) + { + } }; struct leaf_value_type @@ -72,6 +78,12 @@ public: { return key == r.key && value == r.value; } + + leaf_value_type() + : key(0) + , value(0) + { + } }; // Handlers required by the node template class. diff --git a/include/mdds/mixed_type_matrix_flag_storage.hpp b/include/mdds/mixed_type_matrix_flag_storage.hpp index 380557c..768a136 100644 --- a/include/mdds/mixed_type_matrix_flag_storage.hpp +++ b/include/mdds/mixed_type_matrix_flag_storage.hpp @@ -27,6 +27,7 @@ #ifdef MDDS_UNIT_TEST #include <iostream> +#include <boost/io/ios_state.hpp> #endif #include "mdds/hash_container/map.hpp" @@ -85,6 +86,7 @@ public: } cout << "flags stored:" << endl; + boost::io::ios_flags_saver ifs(cout); typename flag_store_type::const_iterator itr = m_flags.begin(), itr_end = m_flags.end(); for (; itr != itr_end; ++itr) { diff --git a/include/mdds/mixed_type_matrix_storage_sparse.inl b/include/mdds/mixed_type_matrix_storage_sparse.inl index a8d79eb..80b8012 100644 --- a/include/mdds/mixed_type_matrix_storage_sparse.inl +++ b/include/mdds/mixed_type_matrix_storage_sparse.inl @@ -79,7 +79,9 @@ public: m_rows(r.m_rows), m_empty_elem(r.m_empty_elem), m_row_size(r.m_row_size), - m_col_size(r.m_col_size) {} + m_col_size(r.m_col_size), + m_numeric(r.m_numeric), + m_valid(r.m_valid) {} ~storage_sparse() {} diff --git a/include/mdds/multi_type_matrix_def.inl b/include/mdds/multi_type_matrix_def.inl index 36f5448..c3b713a 100644 --- a/include/mdds/multi_type_matrix_def.inl +++ b/include/mdds/multi_type_matrix_def.inl @@ -366,31 +366,31 @@ multi_type_matrix<_String>& multi_type_matrix<_String>::transpose() { multi_type_matrix tmp(m_size.column, m_size.row); - for (size_type row = 0; row < m_size.row; ++row) + for (size_type old_row_new_col = 0; old_row_new_col < m_size.row; ++old_row_new_col) { - for (size_type col = 0; col < m_size.column; ++col) + for (size_type old_col_new_row = 0; old_col_new_row < m_size.column; ++old_col_new_row) { - switch (get_type(row,col)) + switch (get_type(old_row_new_col,old_col_new_row)) { case mtm::element_numeric: { double val; - m_store.get(get_pos(row,col), val); - tmp.set(col, row, val); + m_store.get(get_pos(old_row_new_col,old_col_new_row), val); + tmp.set(old_col_new_row, old_row_new_col, val); } break; case mtm::element_boolean: { bool val; - m_store.get(get_pos(row,col), val); - tmp.set(col, row, val); + m_store.get(get_pos(old_row_new_col,old_col_new_row), val); + tmp.set(old_col_new_row, old_row_new_col, val); } break; case mtm::element_string: { string_type val; - m_store.get(get_pos(row,col), val); - tmp.set(col, row, val); + m_store.get(get_pos(old_row_new_col,old_col_new_row), val); + tmp.set(old_col_new_row, old_row_new_col, val); } break; case mtm::element_empty: diff --git a/include/mdds/multi_type_vector_def.inl b/include/mdds/multi_type_vector_def.inl index ba2cfeb..f1f4104 100644 --- a/include/mdds/multi_type_vector_def.inl +++ b/include/mdds/multi_type_vector_def.inl @@ -2009,6 +2009,7 @@ void multi_type_vector<_CellBlockFunc>::swap_single_blocks( { // Append the new elements to the previous block. element_block_func::append_values_from_block(*blk_prev->mp_data, *dst_data); + element_block_func::resize_block(*dst_data, 0); // prevent double-delete. blk_prev->m_size += len; } else @@ -2038,6 +2039,7 @@ void multi_type_vector<_CellBlockFunc>::swap_single_blocks( { // Merge with the next block. element_block_func::prepend_values_from_block(*blk_next->mp_data, *dst_data, 0, len); + element_block_func::resize_block(*dst_data, 0); // prevent double-delete. blk_next->m_size += len; } else @@ -2913,7 +2915,7 @@ multi_type_vector<_CellBlockFunc>::exchange_elements( if (dst_end_pos == blk->m_size) { // The new elements will replace the lower part of the block. - + assert(blk->mp_data && "NULL block mp_data"); element_block_func::resize_block(*blk->mp_data, dst_offset); blk->m_size = dst_offset; diff --git a/include/mdds/point_quad_tree.hpp b/include/mdds/point_quad_tree.hpp index 4ac8f61..ce445b9 100644 --- a/include/mdds/point_quad_tree.hpp +++ b/include/mdds/point_quad_tree.hpp @@ -804,7 +804,6 @@ void point_quad_tree<_Key,_Data>::remove(key_type x, key_type y) adjust_quad(xrange, yrange, delete_node->southeast, dir_north, insert_list); set_new_root(xrange, yrange, delete_node->southwest, quad_northeast, insert_list); break; - case quad_unspecified: default: throw general_error("quadrant for the replacement node is unspecified."); } @@ -837,7 +836,6 @@ void point_quad_tree<_Key,_Data>::remove(key_type x, key_type y) reinsert_tree(delete_node, quad_southwest, root); } break; - case quad_unspecified: default: throw general_error("quadrant for the replacement node is unspecified."); } @@ -869,7 +867,6 @@ void point_quad_tree<_Key,_Data>::remove(key_type x, key_type y) delete_node->southwest = repl_node->southwest; repl_node->southwest.reset(); break; - case quad_unspecified: default: throw general_error("quadrant for the replacement node is unspecified."); } @@ -1533,7 +1530,6 @@ void point_quad_tree<_Key,_Data>::reinsert_tree(node_ptr& dest, node_quadrant_t root->parent = dest; } break; - case quad_unspecified: default: throw general_error("reinsert_tree: quadrant unspecified"); } diff --git a/include/mdds/quad_node.hpp b/include/mdds/quad_node.hpp index 30cd9f4..4ece659 100644 --- a/include/mdds/quad_node.hpp +++ b/include/mdds/quad_node.hpp @@ -232,20 +232,25 @@ struct quad_node_base node_ptr get_quadrant_node(node_quadrant_t quad) const { + node_ptr ret; switch (quad) { case quad_northeast: - return northeast; + ret = northeast; + break; case quad_northwest: - return northwest; + ret = northwest; + break; case quad_southeast: - return southeast; + ret = southeast; + break; case quad_southwest: - return southwest; + ret = southwest; + break; default: throw general_error("unknown quadrant type"); } - return node_ptr(); + return ret; } }; diff --git a/include/mdds/segment_tree.hpp b/include/mdds/segment_tree.hpp index 303630c..b5c5868 100644 --- a/include/mdds/segment_tree.hpp +++ b/include/mdds/segment_tree.hpp @@ -771,15 +771,17 @@ private: }; template<typename _Key, typename _Data> -segment_tree<_Key, _Data>::segment_tree() : - m_valid_tree(false) +segment_tree<_Key, _Data>::segment_tree() + : m_root_node(NULL) + , m_valid_tree(false) { } template<typename _Key, typename _Data> -segment_tree<_Key, _Data>::segment_tree(const segment_tree& r) : - m_segment_data(r.m_segment_data), - m_valid_tree(r.m_valid_tree) +segment_tree<_Key, _Data>::segment_tree(const segment_tree& r) + : m_segment_data(r.m_segment_data) + , m_root_node(NULL) + , m_valid_tree(r.m_valid_tree) { if (m_valid_tree) build_tree(); diff --git a/misc/sorted_string_map_perf.cpp b/misc/sorted_string_map_perf.cpp new file mode 100644 index 0000000..1fd3234 --- /dev/null +++ b/misc/sorted_string_map_perf.cpp @@ -0,0 +1,166 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * Copyright (c) 2014 Kohei Yoshida + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + ************************************************************************/ + +#include "../include/mdds/sorted_string_map.hpp" + +#include <cstdlib> +#include <iostream> +#include <cstring> + +#include <boost/unordered_map.hpp> + +using namespace std; + +#include <stdio.h> +#include <string> +#include <sys/time.h> + +namespace { + +class stack_printer +{ +public: + explicit stack_printer(const char* msg) : + m_msg(msg) + { + fprintf(stdout, "%s: --begin\n", m_msg.c_str()); + m_start_time = getTime(); + } + + ~stack_printer() + { + double end_time = getTime(); + fprintf(stdout, "%s: --end (duration: %g sec)\n", m_msg.c_str(), (end_time - m_start_time)); + } + + void printTime(int line) const + { + double fEndTime = getTime(); + fprintf(stdout, "%s: --(%d) (duration: %g sec)\n", m_msg.c_str(), line, (fEndTime - m_start_time)); + } + +private: + double getTime() const + { + timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + tv.tv_usec / 1000000.0; + } + + ::std::string m_msg; + double m_start_time; +}; + +} + +enum name_type { + name_none = 0, + name_andy, + name_bruce, + name_charlie, + name_david +}; + +typedef mdds::sorted_string_map<name_type> map_type; + +map_type::entry entries[] = +{ + { "andy", name_andy }, + { "andy1", name_andy }, + { "andy13", name_andy }, + { "bruce", name_bruce }, + { "charlie", name_charlie }, + { "david", name_david }, +}; + +typedef boost::unordered_map<std::string, name_type> hashmap_type; + +void init_hash_map(hashmap_type& hm) +{ + size_t n = sizeof(entries) / sizeof(entries[0]); + const map_type::entry* p = entries; + const map_type::entry* pend = p + n; + for (; p != pend; ++p) + hm.insert(hashmap_type::value_type(p->key, p->value)); +} + +void run(map_type& sm, const char* input) +{ + name_type type = sm.find(input, strlen(input)); +} + +void run_hash(hashmap_type& hm, const char* input) +{ + name_type type = name_none; + hashmap_type::const_iterator it = hm.find(input); + if (it != hm.end()) + type = it->second; +} + +const char* tests[] = { + "andy", + "david", + "charlie", + "andy1", + "bruce", + "blah", + "andy13" +}; + +int main() +{ + static const size_t repeat_count = 10000000; + + map_type sorted_map(entries, sizeof(entries)/sizeof(entries[0]), name_none); + size_t n = sorted_map.size(); + cout << "entry count = " << n << endl; + + { + stack_printer __stack_printer__("sorted entry"); + for (size_t rep = 0; rep < repeat_count; ++rep) + { + for (size_t i = 0; i < n; ++i) + run(sorted_map, tests[i]); + } + } + + hashmap_type hm; + init_hash_map(hm); + { + stack_printer __stack_printer__("hash map"); + for (size_t rep = 0; rep < repeat_count; ++rep) + { + for (size_t i = 0; i < n; ++i) + run_hash(hm, tests[i]); + } + } + + return EXIT_SUCCESS; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/src/flat_segment_tree_test.cpp b/src/flat_segment_tree_test.cpp index 0373187..cb1601c 100644 --- a/src/flat_segment_tree_test.cpp +++ b/src/flat_segment_tree_test.cpp @@ -1930,65 +1930,73 @@ void fst_test_assignment() int main (int argc, char **argv) { - cmd_options opt; - if (!parse_cmd_options(argc, argv, opt)) - return EXIT_FAILURE; - - if (opt.test_func) + try { - fst_test_equality(); - fst_test_copy_ctor(); - fst_test_back_insert(); - { - typedef unsigned int key_type; - typedef unsigned short value_type; - for (value_type i = 0; i <= 100; ++i) - fst_test_insert_front_back<key_type, value_type>(0, 100, i); - } + cmd_options opt; + if (!parse_cmd_options(argc, argv, opt)) + return EXIT_FAILURE; + if (opt.test_func) { - typedef int key_type; - typedef short value_type; - for (value_type i = 0; i <= 100; ++i) - fst_test_insert_front_back<key_type, value_type>(0, 100, i); + fst_test_equality(); + fst_test_copy_ctor(); + fst_test_back_insert(); + { + typedef unsigned int key_type; + typedef unsigned short value_type; + for (value_type i = 0; i <= 100; ++i) + fst_test_insert_front_back<key_type, value_type>(0, 100, i); + } + + { + typedef int key_type; + typedef short value_type; + for (value_type i = 0; i <= 100; ++i) + fst_test_insert_front_back<key_type, value_type>(0, 100, i); + } + + { + typedef long key_type; + typedef unsigned int value_type; + for (value_type i = 0; i <= 100; ++i) + fst_test_insert_front_back<key_type, value_type>(0, 100, i); + } + + fst_test_leaf_search(); + fst_test_tree_build(); + fst_test_tree_search(); + fst_test_insert_search_mix(); + fst_test_shift_left(); + fst_test_shift_left_right_edge(); + fst_test_shift_left_append_new_segment(); + fst_test_shift_right_init0(); + fst_test_shift_right_init999(); + fst_test_shift_right_bool(); + fst_test_shift_right_skip_start_node(); + fst_test_shift_right_all_nodes(); + fst_test_const_iterator(); + fst_test_insert_iterator(); + fst_test_insert_state_changed(); + fst_test_position_search(); + fst_test_min_max_default(); + fst_test_swap(); + fst_test_clear(); + fst_test_assignment(); } + if (opt.test_perf) { - typedef long key_type; - typedef unsigned int value_type; - for (value_type i = 0; i <= 100; ++i) - fst_test_insert_front_back<key_type, value_type>(0, 100, i); + fst_perf_test_search_leaf(); + fst_perf_test_search_tree(); + fst_perf_test_insert_front_back(); + fst_perf_test_insert_position(); + fst_perf_test_position_search(); } - - fst_test_leaf_search(); - fst_test_tree_build(); - fst_test_tree_search(); - fst_test_insert_search_mix(); - fst_test_shift_left(); - fst_test_shift_left_right_edge(); - fst_test_shift_left_append_new_segment(); - fst_test_shift_right_init0(); - fst_test_shift_right_init999(); - fst_test_shift_right_bool(); - fst_test_shift_right_skip_start_node(); - fst_test_shift_right_all_nodes(); - fst_test_const_iterator(); - fst_test_insert_iterator(); - fst_test_insert_state_changed(); - fst_test_position_search(); - fst_test_min_max_default(); - fst_test_swap(); - fst_test_clear(); - fst_test_assignment(); - } - - if (opt.test_perf) - { - fst_perf_test_search_leaf(); - fst_perf_test_search_tree(); - fst_perf_test_insert_front_back(); - fst_perf_test_insert_position(); - fst_perf_test_position_search(); + } + catch (const std::exception& e) + { + fprintf(stdout, "Test failed: %s\n", e.what()); + return EXIT_FAILURE; } fprintf(stdout, "Test finished successfully!\n"); diff --git a/src/mixed_type_matrix_test.cpp b/src/mixed_type_matrix_test.cpp index edcf40a..e478231 100644 --- a/src/mixed_type_matrix_test.cpp +++ b/src/mixed_type_matrix_test.cpp @@ -947,48 +947,56 @@ void mtm_perf_test_iterate_elements() int main(int argc, char** argv) { - cmd_options opt; - if (!parse_cmd_options(argc, argv, opt)) - return EXIT_FAILURE; - - if (opt.test_func) + try { - run_tests_on_all_density_types(mtm_test_resize); - run_tests_on_all_density_types(mtm_test_value_store); - run_tests_on_all_density_types(mtm_test_transpose); - run_tests_on_all_density_types(mtm_test_assignment); - - mtm_test_initial_elements(); - mtm_test_numeric_matrix(); - mtm_test_assign(matrix_density_filled_zero, matrix_density_filled_zero); - mtm_test_assign(matrix_density_filled_empty, matrix_density_filled_zero); - mtm_test_assign(matrix_density_filled_zero, matrix_density_filled_empty); - mtm_test_assign(matrix_density_filled_empty, matrix_density_filled_empty); - - run_tests_on_all_density_types(mtm_test_flag_storage); - - mtm_test_iterator_access_filled<mx_type::filled_storage_type>(1, 1); - mtm_test_iterator_access_filled<mx_type::filled_storage_type>(3, 1); - mtm_test_iterator_access_filled<mx_type::filled_storage_type>(1, 3); - mtm_test_iterator_access_filled<mx_type::filled_storage_type>(3, 3); - mtm_test_iterator_access_filled<mx_type::filled_storage_type>(0, 0); - - mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(1, 1); - mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(3, 1); - mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(1, 3); - mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(3, 3); - mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(0, 0); + cmd_options opt; + if (!parse_cmd_options(argc, argv, opt)) + return EXIT_FAILURE; - mtm_test_iterator_access_sparse(); + if (opt.test_func) + { + run_tests_on_all_density_types(mtm_test_resize); + run_tests_on_all_density_types(mtm_test_value_store); + run_tests_on_all_density_types(mtm_test_transpose); + run_tests_on_all_density_types(mtm_test_assignment); + + mtm_test_initial_elements(); + mtm_test_numeric_matrix(); + mtm_test_assign(matrix_density_filled_zero, matrix_density_filled_zero); + mtm_test_assign(matrix_density_filled_empty, matrix_density_filled_zero); + mtm_test_assign(matrix_density_filled_zero, matrix_density_filled_empty); + mtm_test_assign(matrix_density_filled_empty, matrix_density_filled_empty); + + run_tests_on_all_density_types(mtm_test_flag_storage); + + mtm_test_iterator_access_filled<mx_type::filled_storage_type>(1, 1); + mtm_test_iterator_access_filled<mx_type::filled_storage_type>(3, 1); + mtm_test_iterator_access_filled<mx_type::filled_storage_type>(1, 3); + mtm_test_iterator_access_filled<mx_type::filled_storage_type>(3, 3); + mtm_test_iterator_access_filled<mx_type::filled_storage_type>(0, 0); + + mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(1, 1); + mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(3, 1); + mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(1, 3); + mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(3, 3); + mtm_test_iterator_access_filled<mx_type::filled_storage_zero_type>(0, 0); + + mtm_test_iterator_access_sparse(); + + mtm_test_const_iterator(); + } - mtm_test_const_iterator(); + if (opt.test_perf) + { + mtm_perf_test_storage_creation(); + mtm_perf_test_storage_set_numeric(); + mtm_perf_test_iterate_elements(); + } } - - if (opt.test_perf) + catch (const std::exception& e) { - mtm_perf_test_storage_creation(); - mtm_perf_test_storage_set_numeric(); - mtm_perf_test_iterate_elements(); + cout << "Test failed: " << e.what() << endl; + return EXIT_FAILURE; } cout << "Test finished successfully!" << endl; diff --git a/src/multi_type_matrix_test.cpp b/src/multi_type_matrix_test.cpp index 2037ef5..ebba21e 100644 --- a/src/multi_type_matrix_test.cpp +++ b/src/multi_type_matrix_test.cpp @@ -969,34 +969,42 @@ void mtm_perf_test_insert_via_position_object() int main (int argc, char **argv) { - cmd_options opt; - if (!parse_cmd_options(argc, argv, opt)) - return EXIT_FAILURE; - - if (opt.test_func) + try { - mtm_test_construction(); - mtm_test_data_insertion(); - mtm_test_data_insertion_multiple(); - mtm_test_set_empty(); - mtm_test_swap(); - mtm_test_transpose(); - mtm_test_resize(); - mtm_test_copy(); - mtm_test_assignment(); - mtm_test_numeric(); - mtm_test_walk(); - mtm_test_custom_string(); - mtm_test_position(); - mtm_test_set_data_via_position(); - } + cmd_options opt; + if (!parse_cmd_options(argc, argv, opt)) + return EXIT_FAILURE; + + if (opt.test_func) + { + mtm_test_construction(); + mtm_test_data_insertion(); + mtm_test_data_insertion_multiple(); + mtm_test_set_empty(); + mtm_test_swap(); + mtm_test_transpose(); + mtm_test_resize(); + mtm_test_copy(); + mtm_test_assignment(); + mtm_test_numeric(); + mtm_test_walk(); + mtm_test_custom_string(); + mtm_test_position(); + mtm_test_set_data_via_position(); + } - if (opt.test_perf) + if (opt.test_perf) + { + mtm_perf_test_storage_creation(); + mtm_perf_test_storage_set_numeric(); + mtm_perf_test_iterate_elements(); + mtm_perf_test_insert_via_position_object(); + } + } + catch (const std::exception& e) { - mtm_perf_test_storage_creation(); - mtm_perf_test_storage_set_numeric(); - mtm_perf_test_iterate_elements(); - mtm_perf_test_insert_via_position_object(); + fprintf(stdout, "Test failed: %s\n", e.what()); + return EXIT_FAILURE; } cout << "Test finished successfully!" << endl; diff --git a/src/multi_type_vector_test_custom.cpp b/src/multi_type_vector_test_custom.cpp index 96b61ee..2ceaad5 100644 --- a/src/multi_type_vector_test_custom.cpp +++ b/src/multi_type_vector_test_custom.cpp @@ -76,6 +76,7 @@ struct muser_cell muser_cell() : value(0.0) {} muser_cell(const muser_cell& r) : value(r.value) {} muser_cell(double _v) : value(_v) {} + ~muser_cell() {} }; struct date @@ -1449,6 +1450,69 @@ void mtv_test_swap() db2.set(5, new muser_cell(3.3)); db2.swap(3, 4, db1, 3); + + // Another scenario that used to crash on double delete. + + db1.clear(); + db1.resize(10); + db2.clear(); + db2.resize(10); + + db1.set(2, new muser_cell(4.1)); + db1.set(3, 4.2); + db1.set(4, new muser_cell(4.3)); + + db2.set(3, new muser_cell(6.1)); + db2.set(4, 6.2); + db2.set(5, 6.3); + + assert(db1.get<muser_cell*>(2)->value == 4.1); + assert(db1.get<double>(3) == 4.2); + assert(db1.get<muser_cell*>(4)->value == 4.3); + + assert(db2.get<muser_cell*>(3)->value == 6.1); + assert(db2.get<double>(4) == 6.2); + assert(db2.get<double>(5) == 6.3); + + db2.swap(4, 4, db1, 4); + + assert(db1.get<muser_cell*>(2)->value == 4.1); + assert(db1.get<double>(3) == 4.2); + assert(db1.get<double>(4) == 6.2); + + assert(db2.get<muser_cell*>(3)->value == 6.1); + assert(db2.get<muser_cell*>(4)->value == 4.3); + assert(db2.get<double>(5) == 6.3); + + // One more on double deletion... + + db1.clear(); + db1.resize(10); + db2.clear(); + db2.resize(10); + + db1.set(0, 2.1); + db1.set(1, 2.2); + db1.set(2, 2.3); + db1.set(3, new muser_cell(4.5)); + + db2.set(2, new muser_cell(3.1)); + db2.set(3, new muser_cell(3.2)); + db2.set(4, new muser_cell(3.3)); + + db1.swap(2, 2, db2, 3); + + assert(db1.get<double>(0) == 2.1); + assert(db1.get<double>(1) == 2.2); + assert(db1.get<muser_cell*>(2)->value == 3.2); + assert(db1.get<muser_cell*>(3)->value == 4.5); + + assert(db2.get<muser_cell*>(2)->value == 3.1); + assert(db2.get<double>(3) == 2.3); + assert(db2.get<muser_cell*>(4)->value == 3.3); + + assert(db1.check_block_integrity()); + assert(db2.check_block_integrity()); } void mtv_test_custom_block_func3() @@ -1569,17 +1633,25 @@ void mtv_test_construction_with_array() int main (int argc, char **argv) { - mtv_test_types(); - mtv_test_block_identifier(); - mtv_test_basic(); - mtv_test_equality(); - mtv_test_managed_block(); - mtv_test_custom_block_func1(); - mtv_test_transfer(); - mtv_test_swap(); - mtv_test_custom_block_func3(); - mtv_test_release(); - mtv_test_construction_with_array(); + try + { + mtv_test_types(); + mtv_test_block_identifier(); + mtv_test_basic(); + mtv_test_equality(); + mtv_test_managed_block(); + mtv_test_custom_block_func1(); + mtv_test_transfer(); + mtv_test_swap(); + mtv_test_custom_block_func3(); + mtv_test_release(); + mtv_test_construction_with_array(); + } + catch (const std::exception& e) + { + cout << "Test failed: " << e.what() << endl; + return EXIT_FAILURE; + } cout << "Test finished successfully!" << endl; return EXIT_SUCCESS; diff --git a/src/multi_type_vector_test_default.cpp b/src/multi_type_vector_test_default.cpp index 28ff59e..70ee958 100644 --- a/src/multi_type_vector_test_default.cpp +++ b/src/multi_type_vector_test_default.cpp @@ -2964,7 +2964,7 @@ void mtv_test_set_return_iterator() it = db.set(6, string("text")); assert(it->size == 1); assert(it->type == mtv::element_type_string); - assert(it->position = 6); + assert(it->position == 6); check = db.begin(); std::advance(check, 2); assert(it == check); @@ -5071,40 +5071,48 @@ void mtv_test_capacity() int main (int argc, char **argv) { - mtv_test_types(); - mtv_test_construction(); - mtv_test_basic(); - mtv_test_empty_cells(); - mtv_test_swap(); - mtv_test_equality(); - mtv_test_clone(); - mtv_test_resize(); - mtv_test_erase(); - mtv_test_insert_empty(); - mtv_test_set_cells(); - mtv_test_insert_cells(); - mtv_test_iterators(); - mtv_test_data_iterators(); - mtv_test_non_const_data_iterators(); - mtv_test_iterator_private_data(); - mtv_test_set_return_iterator(); - mtv_test_set2_return_iterator(); - mtv_test_insert_cells_return_iterator(); - mtv_test_set_empty_return_iterator(); - mtv_test_insert_empty_return_iterator(); - mtv_test_set_with_position(); - mtv_test_set_cells_with_position(); - mtv_test_insert_cells_with_position(); - mtv_test_set_empty_with_position(); - mtv_test_insert_empty_with_position(); - mtv_test_position(); - mtv_test_next_position(); - mtv_test_swap_range(); - mtv_test_value_type(); - mtv_test_block_identifier(); - mtv_test_transfer(); - mtv_test_push_back(); - mtv_test_capacity(); + try + { + mtv_test_types(); + mtv_test_construction(); + mtv_test_basic(); + mtv_test_empty_cells(); + mtv_test_swap(); + mtv_test_equality(); + mtv_test_clone(); + mtv_test_resize(); + mtv_test_erase(); + mtv_test_insert_empty(); + mtv_test_set_cells(); + mtv_test_insert_cells(); + mtv_test_iterators(); + mtv_test_data_iterators(); + mtv_test_non_const_data_iterators(); + mtv_test_iterator_private_data(); + mtv_test_set_return_iterator(); + mtv_test_set2_return_iterator(); + mtv_test_insert_cells_return_iterator(); + mtv_test_set_empty_return_iterator(); + mtv_test_insert_empty_return_iterator(); + mtv_test_set_with_position(); + mtv_test_set_cells_with_position(); + mtv_test_insert_cells_with_position(); + mtv_test_set_empty_with_position(); + mtv_test_insert_empty_with_position(); + mtv_test_position(); + mtv_test_next_position(); + mtv_test_swap_range(); + mtv_test_value_type(); + mtv_test_block_identifier(); + mtv_test_transfer(); + mtv_test_push_back(); + mtv_test_capacity(); + } + catch (const std::exception& e) + { + cout << "Test failed: " << e.what() << endl; + return EXIT_FAILURE; + } cout << "Test finished successfully!" << endl; return EXIT_SUCCESS; diff --git a/src/point_quad_tree_test.cpp b/src/point_quad_tree_test.cpp index 9d8bb0c..dae82d2 100644 --- a/src/point_quad_tree_test.cpp +++ b/src/point_quad_tree_test.cpp @@ -188,7 +188,8 @@ void pqt_test_insertion_removal() db.remove(x, y); size_t n = db.size(); cout << "removing node at (" << x << "," << y << ") " << "size after removal: " << n << endl; - assert(--node_count == n); + --node_count; + assert(node_count == n); } } } @@ -454,15 +455,24 @@ void pqt_test_node_access() int main() { - pqt_test_basic(); - pqt_test_insertion_removal(); - pqt_test_remove_root(); - pqt_test_equality(); - pqt_test_assignment(); - pqt_test_swap(); - pqt_test_find(); - pqt_test_node_access(); - assert(get_node_instance_count() == 0); + try + { + pqt_test_basic(); + pqt_test_insertion_removal(); + pqt_test_remove_root(); + pqt_test_equality(); + pqt_test_assignment(); + pqt_test_swap(); + pqt_test_find(); + pqt_test_node_access(); + assert(get_node_instance_count() == 0); + } + catch (const std::exception& e) + { + cout << "Test failed: " << e.what() << endl; + return EXIT_FAILURE; + } + cout << "Test finished successfully!" << endl; return EXIT_SUCCESS; } diff --git a/src/rectangle_set_test.cpp b/src/rectangle_set_test.cpp index 85aa88c..aa56c82 100644 --- a/src/rectangle_set_test.cpp +++ b/src/rectangle_set_test.cpp @@ -943,24 +943,32 @@ void rect_test_invalid_range() int main(int argc, char** argv) { - cmd_options opt; - if (!parse_cmd_options(argc, argv, opt)) - return EXIT_FAILURE; - if (opt.test_func) + try { - rect_test_insertion_removal(); - rect_test_search(); - rect_test_copy_constructor(); - rect_test_assignment(); - rect_test_equality(); - rect_test_search_result_iterator(); - rect_test_invalid_range(); - } + cmd_options opt; + if (!parse_cmd_options(argc, argv, opt)) + return EXIT_FAILURE; + if (opt.test_func) + { + rect_test_insertion_removal(); + rect_test_search(); + rect_test_copy_constructor(); + rect_test_assignment(); + rect_test_equality(); + rect_test_search_result_iterator(); + rect_test_invalid_range(); + } - if (opt.test_perf) + if (opt.test_perf) + { + rect_test_perf_insertion_fixed_x(); + rect_test_perf_insertion_fixed_y(); + } + } + catch (const std::exception& e) { - rect_test_perf_insertion_fixed_x(); - rect_test_perf_insertion_fixed_y(); + fprintf(stdout, "Test failed: %s\n", e.what()); + return EXIT_FAILURE; } fprintf(stdout, "Test finished successfully!\n"); diff --git a/src/segment_tree_test.cpp b/src/segment_tree_test.cpp index 455b568..f1d7df1 100644 --- a/src/segment_tree_test.cpp +++ b/src/segment_tree_test.cpp @@ -1084,36 +1084,43 @@ void st_test_empty_result_set() int main(int argc, char** argv) { - cmd_options opt; - if (!parse_cmd_options(argc, argv, opt)) - return EXIT_FAILURE; - - if (opt.test_func) + try { - st_test_insert_search_removal(); - st_test_copy_constructor(); - st_test_equality(); - st_test_clear(); - st_test_duplicate_insertion(); - st_test_search_on_uneven_tree(); - st_test_aggregated_search_results(); - st_test_dense_tree_search(); - st_test_search_on_empty_set(); - st_test_search_iterator_basic(); - st_test_search_iterator_result_check(); - st_test_empty_result_set(); - } + cmd_options opt; + if (!parse_cmd_options(argc, argv, opt)) + return EXIT_FAILURE; - if (opt.test_perf) - { - st_test_perf_insertion(); - } + if (opt.test_func) + { + st_test_insert_search_removal(); + st_test_copy_constructor(); + st_test_equality(); + st_test_clear(); + st_test_duplicate_insertion(); + st_test_search_on_uneven_tree(); + st_test_aggregated_search_results(); + st_test_dense_tree_search(); + st_test_search_on_empty_set(); + st_test_search_iterator_basic(); + st_test_search_iterator_result_check(); + st_test_empty_result_set(); + } - // At this point, all of the nodes created during the test run should have - // been destroyed. If not, we are leaking memory. - typedef segment_tree<uint32_t, void> db_type; - assert(db_type::node::get_instance_count() == 0); + if (opt.test_perf) + { + st_test_perf_insertion(); + } + // At this point, all of the nodes created during the test run should have + // been destroyed. If not, we are leaking memory. + typedef segment_tree<uint32_t, void> db_type; + assert(db_type::node::get_instance_count() == 0); + } + catch (const std::exception& e) + { + fprintf(stdout, "Test failed: %s\n", e.what()); + return EXIT_FAILURE; + } fprintf(stdout, "Test finished successfully!\n"); return EXIT_SUCCESS; } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-openoffice/mdds.git

