From e117fd41d8a233216ceb40acc302dc0f89453f43 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Wed, 23 Aug 2006 01:40:23 +0000 Subject: [PATCH] Wave: Fixed a bug resulting in a crash if a macro was redefined with a shorter expansion list as it was defined initially. Added a corresponding test case. [SVN r34926] --- ChangeLog | 5 ++++- include/boost/wave/util/cpp_macromap_utils.hpp | 8 +++++--- test/testwave/testfiles/t_9_018.cpp | 15 +++++++++++++++ test/testwave/testfiles/test.cfg | 1 + tool/cpp.cpp | 6 ++++++ 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 test/testwave/testfiles/t_9_018.cpp diff --git a/ChangeLog b/ChangeLog index 603b5fc..938bd4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -147,7 +147,10 @@ Boost V1.34.0 - Fixed RTTI build issue for VC7.1/bjam --v2 (thanks to Rene Rivera for submitting a patch for the Wave Jamfile.v2). - Fixed certain problems reported by the Boost inspection tool. - +- Fixed a couple of SunPro5.8 warnings. +- Fixed a bug resulting in a crash if a macro was redefined with a shorter + expansion list as it was defined initially. Added a corresponding test case. + Sat Feb 18 2005 - Version 1.2.3 - Added a missing throw() specification to the function diff --git a/include/boost/wave/util/cpp_macromap_utils.hpp b/include/boost/wave/util/cpp_macromap_utils.hpp index b8f4e9c..2b4abd6 100644 --- a/include/boost/wave/util/cpp_macromap_utils.hpp +++ b/include/boost/wave/util/cpp_macromap_utils.hpp @@ -235,7 +235,8 @@ const_iterator_type last1 = definition.end(); const_iterator_type first2 = new_definition.begin(); const_iterator_type last2 = new_definition.end(); - while (first1 != last1 && token_equals(*first1, *first2)) { + while (first1 != last1 && first2 != last2 && token_equals(*first1, *first2)) + { // skip whitespace, if both sequences have a whitespace next token_id id1 = next_token::peek(first1, last1, false); token_id id2 = next_token::peek(first2, last2, false); @@ -279,8 +280,9 @@ parameters_equal(ContainerT const ¶meters, ContainerT const &new_parameters) const_iterator_type first1 = parameters.begin(); const_iterator_type last1 = parameters.end(); const_iterator_type first2 = new_parameters.begin(); +const_iterator_type last2 = new_parameters.end(); - while (first1 != last1) { + while (first1 != last1 && first2 != last2) { // parameters are different, if the corresponding tokens are different using namespace boost::wave; if (token_id(*first1) != token_id(*first2) || @@ -291,7 +293,7 @@ const_iterator_type first2 = new_parameters.begin(); ++first1; ++first2; } - return (first1 == last1) ? true : false; + return (first1 == last1 && first2 == last2) ? true : false; } /////////////////////////////////////////////////////////////////////////////// diff --git a/test/testwave/testfiles/t_9_018.cpp b/test/testwave/testfiles/t_9_018.cpp new file mode 100644 index 0000000..065bab7 --- /dev/null +++ b/test/testwave/testfiles/t_9_018.cpp @@ -0,0 +1,15 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + http://www.boost.org/ + + Copyright (c) 2001-2006 Hartmut Kaiser. Distributed under the Boost + Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ + +// tests, whether macro redefinition does not crash anymore, even if the new +// replacement list is shorter, than the initial one. + +//E t_9_018.cpp(15): warning: illegal macro redefinition: M1 +#define M1 1 +#define M1 diff --git a/test/testwave/testfiles/test.cfg b/test/testwave/testfiles/test.cfg index 2cc0bfa..66119c3 100644 --- a/test/testwave/testfiles/test.cfg +++ b/test/testwave/testfiles/test.cfg @@ -215,3 +215,4 @@ t_9_014.cpp t_9_015.cpp t_9_016.cpp t_9_017.cpp +t_9_018.cpp diff --git a/tool/cpp.cpp b/tool/cpp.cpp index 8c54f3b..454a830 100644 --- a/tool/cpp.cpp +++ b/tool/cpp.cpp @@ -1080,6 +1080,12 @@ main (int argc, char *argv[]) return do_actual_work("", std::cin, vm, true); } else { + if (arguments.size() > 1) { + // this driver understands to parse one input file only + cerr << "wave: more than one input file specified, " + << "ignoring all but the first!" << endl; + } + std::string file_name(arguments[0].value[0]); ifstream instream(file_name.c_str());