From b0b95667f3249ace0ea1865f9241f60105989b4f Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 11 Mar 2017 14:46:27 -0800 Subject: [PATCH 01/43] Bump version; tweak install script so install-strip works when not sudo'd; detect compiler properly when g++ goes by 'c++' --- configure | 22 +++++++++++----------- configure.ac | 6 +++--- installer/install.sh | 4 +++- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/configure b/configure index a174aa1..e4ddce3 100755 --- a/configure +++ b/configure @@ -1,7 +1,7 @@ #! /bin/sh -# From configure.ac Revision: 2.4.3.4 . +# From configure.ac Revision: 2.4.3.5 . # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for tripwire 2.4.3.4. +# Generated by GNU Autoconf 2.69 for tripwire 2.4.3.5. # # Report bugs to . # @@ -584,8 +584,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='tripwire' PACKAGE_TARNAME='tripwire' -PACKAGE_VERSION='2.4.3.4' -PACKAGE_STRING='tripwire 2.4.3.4' +PACKAGE_VERSION='2.4.3.5' +PACKAGE_STRING='tripwire 2.4.3.5' PACKAGE_BUGREPORT='https://github.com/Tripwire/tripwire-open-source/issues' PACKAGE_URL='https://github.com/Tripwire/tripwire-open-source' @@ -1321,7 +1321,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 tripwire 2.4.3.4 to adapt to many kinds of systems. +\`configure' configures tripwire 2.4.3.5 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1393,7 +1393,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of tripwire 2.4.3.4:";; + short | recursive ) echo "Configuration of tripwire 2.4.3.5:";; esac cat <<\_ACEOF @@ -1504,7 +1504,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -tripwire configure 2.4.3.4 +tripwire configure 2.4.3.5 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2391,7 +2391,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 tripwire $as_me 2.4.3.4, which was +It was created by tripwire $as_me 2.4.3.5, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3365,7 +3365,7 @@ fi # Define the identity of the package. PACKAGE='tripwire' - VERSION='2.4.3.4' + VERSION='2.4.3.5' cat >>confdefs.h <<_ACEOF @@ -7633,7 +7633,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 tripwire $as_me 2.4.3.4, which was +This file was extended by tripwire $as_me 2.4.3.5, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -7700,7 +7700,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="\\ -tripwire config.status 2.4.3.4 +tripwire config.status 2.4.3.5 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index ebefa51..e2f4d84 100644 --- a/configure.ac +++ b/configure.ac @@ -2,14 +2,14 @@ dnl Process this file with autoconf to produce a configure script. dnl dnl -AC_INIT([tripwire], [2.4.3.4], [https://github.com/Tripwire/tripwire-open-source/issues], [tripwire], [https://github.com/Tripwire/tripwire-open-source]) +AC_INIT([tripwire], [2.4.3.5], [https://github.com/Tripwire/tripwire-open-source/issues], [tripwire], [https://github.com/Tripwire/tripwire-open-source]) AC_CONFIG_SRCDIR([src/tw/tw.cpp]) AC_CANONICAL_TARGET([]) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) AC_COPYRIGHT([The developer of the original code and/or files is Tripwire, Inc. Portions created by Tripwire, Inc. are copyright 2000-2017 Tripwire, Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights reserved.]) -AC_REVISION([$Revision: 2.4.3.4 $]) +AC_REVISION([$Revision: 2.4.3.5 $]) dnl ################################# dnl Cleanup Cruft Leftover From Patch @@ -42,7 +42,7 @@ dnl ################### dnl Checks for programs dnl ################### AC_PROG_CC([gcc clang suncc aCC xlC_r xlC cl.exe]) -AC_PROG_CXX([g++ clang++ sunCC aCC xlC_r xlC cl.exe]) +AC_PROG_CXX([g++ c++ clang++ sunCC aCC xlC_r xlC cl.exe]) AC_PROG_RANLIB AC_PROG_YACC AC_PROG_LN_S diff --git a/installer/install.sh b/installer/install.sh index 6957da9..de14eff 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -607,7 +607,9 @@ done if [ -n "$INSTALL_STRIP_FLAG" ] ; then echo "INSTALL_STRIP_FLAG is set, stripping binaries" - strip "$TWBIN/siggen" "$TWBIN/tripwire" "$TWBIN/twadmin" "$TWBIN/twprint" + chmod u+w "$TWBIN/siggen" "$TWBIN/tripwire" "$TWBIN/twadmin" "$TWBIN/twprint" + strip "$TWBIN/siggen" "$TWBIN/tripwire" "$TWBIN/twadmin" "$TWBIN/twprint" + chmod u-w "$TWBIN/siggen" "$TWBIN/tripwire" "$TWBIN/twadmin" "$TWBIN/twprint" fi #Make extra sure we don't install the unit test binary to sbin From db44ff8faf4058fd42f2dab70023bf09f420e027 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 12 Mar 2017 01:59:25 -0800 Subject: [PATCH 02/43] Add 'disable-extrawarnings' configure option to support old compilers that don't support the -Wextra compiler flag. --- configure | 24 ++++++++++++++++++++---- configure.ac | 14 ++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/configure b/configure index e4ddce3..e92f2bd 100755 --- a/configure +++ b/configure @@ -748,6 +748,7 @@ ac_subst_files='' ac_user_opts=' enable_option_checking enable_silent_rules +enable_extrawarnings enable_static enable_debug enable_dependency_tracking @@ -1403,6 +1404,7 @@ Optional Features: --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") + —-disable-extrawarnings do not compile with -Wextra warnings enabled --enable-static compile static binaries --enable-debug compile with debuging enabled --enable-dependency-tracking @@ -3467,8 +3469,21 @@ ac_config_headers="$ac_config_headers config.h" rm -f src/tripwire/syslog.h 2> /dev/null chmod 755 install-sh 2> /dev/null -CFLAGS=${CFLAGS:-"-O -pipe -Wall -Wextra -Wno-unused-parameter -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} -CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -Wextra -Wno-unused-parameter -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} +CFLAGS=${CFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} +CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} + + +# This is primarily to support old compilers that don’t understand -Wextra +# Check whether --enable-extrawarnings was given. +if test "${enable_extrawarnings+set}" = set; then : + enableval=$enable_extrawarnings; +fi + +if test "x$enable_extrawarnings" != "xno" +then + CFLAGS="${CFLAGS} -Wextra -Wno-unused-parameter" + CXXFLAGS="${CXXFLAGS} -Wextra -Wno-unused-parameter" +fi # Check whether --enable-static was given. if test "${enable_static+set}" = set; then : @@ -3478,6 +3493,7 @@ fi if test "x$enable_static" = xyes then LDFLAGS="${LDFLAGS} -static" fi + # Check whether --enable-debug was given. if test "${enable_debug+set}" = set; then : enableval=$enable_debug; @@ -4349,7 +4365,7 @@ if test -z "$CXX"; then CXX=$CCC else if test -n "$ac_tool_prefix"; then - for ac_prog in g++ clang++ sunCC aCC xlC_r xlC cl.exe + for ac_prog in g++ c++ clang++ sunCC aCC xlC_r xlC cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 @@ -4393,7 +4409,7 @@ fi fi if test -z "$CXX"; then ac_ct_CXX=$CXX - for ac_prog in g++ clang++ sunCC aCC xlC_r xlC cl.exe + for ac_prog in g++ c++ clang++ sunCC aCC xlC_r xlC cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 diff --git a/configure.ac b/configure.ac index e2f4d84..e10a6af 100644 --- a/configure.ac +++ b/configure.ac @@ -20,16 +20,26 @@ chmod 755 install-sh 2> /dev/null dnl ############### dnl Setup defaults dnl ############### -CFLAGS=${CFLAGS:-"-O -pipe -Wall -Wextra -Wno-unused-parameter -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} -CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -Wextra -Wno-unused-parameter -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} +CFLAGS=${CFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} +CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} dnl ##################### dnl Configuration options dnl ##################### + +# This is primarily to support old compilers that don’t understand -Wextra +AC_ARG_ENABLE(extrawarnings, [ —-disable-extrawarnings do not compile with -Wextra warnings enabled]) +if test "x$enable_extrawarnings" != "xno" +then + CFLAGS="${CFLAGS} -Wextra -Wno-unused-parameter" + CXXFLAGS="${CXXFLAGS} -Wextra -Wno-unused-parameter" +fi + AC_ARG_ENABLE(static, [ --enable-static compile static binaries]) if test "x$enable_static" = xyes then LDFLAGS="${LDFLAGS} -static" fi + AC_ARG_ENABLE(debug, [ --enable-debug compile with debuging enabled]) if test "x$enable_debug" = xyes then From 306b7a7a5feae486f726a1687df593b4b09e9e78 Mon Sep 17 00:00:00 2001 From: brc0x1 Date: Mon, 13 Mar 2017 15:42:47 -0700 Subject: [PATCH 03/43] Tweak 'make uninstall' to nuke twexes & docs --- Makefile.am | 4 ++++ Makefile.in | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index e0446a1..871e373 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,3 +7,7 @@ install-data-hook: prefix="$(prefix)" sysconfdir="$(sysconfdir)" \ path_to_vi="$(path_to_vi)" path_to_sendmail="$(path_to_sendmail)" \ ./installer/install.sh + +uninstall-hook: + rm -f ${prefix}/sbin/tripwire $(prefix)/sbin/twadmin $(prefix)/sbin/twprint $(prefix)/sbin/siggen + rm -Rf $(prefix)/doc diff --git a/Makefile.in b/Makefile.in index f9e3f25..5c041f2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -774,9 +774,10 @@ ps: ps-recursive ps-am: uninstall-am: - + @$(NORMAL_INSTALL) + $(MAKE) $(AM_MAKEFLAGS) uninstall-hook .MAKE: $(am__recursive_targets) all install-am install-data-am \ - install-strip + install-strip uninstall-am .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ am--refresh check check-am clean clean-cscope clean-generic \ @@ -792,7 +793,7 @@ uninstall-am: install-strip installcheck installcheck-am installdirs \ installdirs-am maintainer-clean maintainer-clean-generic \ mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \ - tags-am uninstall uninstall-am + tags-am uninstall uninstall-am uninstall-hook .PRECIOUS: Makefile @@ -803,6 +804,10 @@ install-data-hook: path_to_vi="$(path_to_vi)" path_to_sendmail="$(path_to_sendmail)" \ ./installer/install.sh +uninstall-hook: + rm -f ${prefix}/sbin/tripwire $(prefix)/sbin/twadmin $(prefix)/sbin/twprint $(prefix)/sbin/siggen + rm -Rf $(prefix)/doc + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: From 58dafd1d9ed9e57a0ebe50d016418f378a4d5572 Mon Sep 17 00:00:00 2001 From: brc0x1 Date: Mon, 13 Mar 2017 17:25:44 -0700 Subject: [PATCH 04/43] Tweak path to install.sh so 'make distcheck' works; update installer to pick up additional files for docs directory. --- Makefile.am | 2 +- Makefile.in | 2 +- installer/install.sh | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 871e373..097fe7c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,7 @@ install-data-hook: export INSTALL_STRIP_FLAG prefix="$(prefix)" sysconfdir="$(sysconfdir)" \ path_to_vi="$(path_to_vi)" path_to_sendmail="$(path_to_sendmail)" \ - ./installer/install.sh + $(top_srcdir)/installer/install.sh uninstall-hook: rm -f ${prefix}/sbin/tripwire $(prefix)/sbin/twadmin $(prefix)/sbin/twprint $(prefix)/sbin/siggen diff --git a/Makefile.in b/Makefile.in index 5c041f2..4c462b6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -802,7 +802,7 @@ install-data-hook: export INSTALL_STRIP_FLAG prefix="$(prefix)" sysconfdir="$(sysconfdir)" \ path_to_vi="$(path_to_vi)" path_to_sendmail="$(path_to_sendmail)" \ - ./installer/install.sh + $(top_srcdir)/installer/install.sh uninstall-hook: rm -f ${prefix}/sbin/tripwire $(prefix)/sbin/twadmin $(prefix)/sbin/twprint $(prefix)/sbin/siggen diff --git a/installer/install.sh b/installer/install.sh index de14eff..fbd26c8 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -584,9 +584,12 @@ f10=' ff=${POLICYSRC} ; d="/policy" ; dd=$TWPOLICY ; rr=0640 ' #f16=' ff=twadmin.8 ; d="/man/man8" ; dd=$TWMAN/man8 ; rr=0444 ' #f17=' ff=twintro.8 ; d="/man/man8" ; dd=$TWMAN/man8 ; rr=0444 ' #f18=' ff=twprint.8 ; d="/man/man8" ; dd=$TWMAN/man8 ; rr=0444 ' +f19=' ff=COMMERCIAL ; d="" ; dd=$TWDOCS ; rr=0444 ' +f20=' ff=ReadMe-2.4.3 ; d="" ; dd=$TWDOCS ; rr=0444 ' +f21=' ff=ChangeLog ; d="" ; dd=$TWDOCS ; rr=0444 ' # Binaries and manpages are already installed by the install target -loosefiles="f3 f4 f5 f6 f7 f8 f9 f10" +loosefiles="f3 f4 f5 f6 f7 f8 f9 f10 f19 f20 f21" for i in $loosefiles; do eval "eval \"\$$i\"" From 2e39db661b2fef134f317bd1e1e038f1d3146624 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Tue, 14 Mar 2017 00:32:16 -0700 Subject: [PATCH 05/43] Comment out a known-problematic assert in zdeflate.cpp (though I haven't actually seen it fail in OST). Later versions of Crypto++ comment out or remove this line, so this seems reasonable to do until I can figure out how to update the whole library --- src/cryptlib/zdeflate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptlib/zdeflate.cpp b/src/cryptlib/zdeflate.cpp index 8a4302a..60d74e3 100644 --- a/src/cryptlib/zdeflate.cpp +++ b/src/cryptlib/zdeflate.cpp @@ -236,7 +236,7 @@ int Deflator::longest_match(IPos cur_match) if (prev_length >= good_match) { chain_length >>= 2; } - assert(strstart <= (unsigned)WINDOW_SIZE-MIN_LOOKAHEAD); + //assert(strstart <= (unsigned)WINDOW_SIZE-MIN_LOOKAHEAD); do { assert(cur_match < strstart); From 062523a60e2a13a12cad1fd031885375c029a920 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Tue, 14 Mar 2017 01:23:23 -0700 Subject: [PATCH 06/43] Add a working 'make check' target, which runs both the test suite in src/test-harness, and all the twtest unit tests; update unit test binary to return standard success/fail values, to keep make happy --- Makefile.am | 5 +++++ Makefile.in | 5 +++++ src/twtest/test.cpp | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 097fe7c..e72b1ee 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,3 +11,8 @@ install-data-hook: uninstall-hook: rm -f ${prefix}/sbin/tripwire $(prefix)/sbin/twadmin $(prefix)/sbin/twprint $(prefix)/sbin/siggen rm -Rf $(prefix)/doc + +check: + rm -Rf $(top_srcdir)/src/test-harness/twtest + cd $(top_srcdir)/src/test-harness && ./twtest.pl + $(top_srcdir)/bin/twtest all diff --git a/Makefile.in b/Makefile.in index 4c462b6..5586cce 100644 --- a/Makefile.in +++ b/Makefile.in @@ -808,6 +808,11 @@ uninstall-hook: rm -f ${prefix}/sbin/tripwire $(prefix)/sbin/twadmin $(prefix)/sbin/twprint $(prefix)/sbin/siggen rm -Rf $(prefix)/doc +check: + rm -Rf $(top_srcdir)/src/test-harness/twtest + cd $(top_srcdir)/src/test-harness && ./twtest.pl + $(top_srcdir)/bin/twtest all + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index c77e7ff..4bdc1df 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -316,11 +316,13 @@ int _tmain(int argc, TCHAR** argv) { cTWUtil::PrintErrorMsg(error); ASSERT(false); + return 1; } catch (...) { TCERR << _T("Unhandled exception caught!"); ASSERT(false); + return 1; } // make sure all the refrence counted objects have been destroyed @@ -329,7 +331,9 @@ int _tmain(int argc, TCHAR** argv) // force user to hit - return 1; + std::cout << std::endl << "Tests completed" << std::endl; + + return 0; } From 63168d9880afb00a94b5e1230f8e351440cd5823 Mon Sep 17 00:00:00 2001 From: brc0x1 Date: Tue, 14 Mar 2017 13:16:43 -0700 Subject: [PATCH 07/43] Update copyright/tm notice in installer script --- installer/install.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index fbd26c8..3d571ae 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -243,9 +243,8 @@ cat << END_OF_TEXT Installer program for: Tripwire(R) 2.4 Open Source -Copyright (C) 1998-2000 Tripwire (R) Security Systems, Inc. Tripwire (R) -is a registered trademark of the Purdue Research Foundation and is -licensed exclusively to Tripwire (R) Security Systems, Inc. +Copyright (C) 1998-2017 Tripwire, Inc. +Tripwire is a registered trademark of Tripwire, Inc. All rights reserved. END_OF_TEXT From d3f859bfbd256322a258c9c5eb58638758bf831e Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 15 Mar 2017 00:47:52 -0700 Subject: [PATCH 08/43] Address some cppcheck warnings around initializers & catching by reference --- src/fco/fcodatasourceiterimpl.cpp | 2 +- src/fco/genreswitcher.cpp | 6 ++---- src/tripwire/tripwiremain.cpp | 4 ++-- src/tripwire/twcmdline.cpp | 2 +- src/tripwire/twcmdline.h | 7 +++++-- src/tw/filemanipulator.cpp | 3 ++- src/tw/textreportviewer.cpp | 4 +++- src/tw/textreportviewer.h | 2 +- src/twadmin/twadminmain.cpp | 4 ++-- src/twprint/twprintmain.cpp | 4 ++-- 10 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/fco/fcodatasourceiterimpl.cpp b/src/fco/fcodatasourceiterimpl.cpp index a21fa80..709c881 100644 --- a/src/fco/fcodatasourceiterimpl.cpp +++ b/src/fco/fcodatasourceiterimpl.cpp @@ -52,7 +52,7 @@ //========================================================================= cFCODataSourceIterImpl::cFCODataSourceIterImpl() - : mFlags(0) + : mpErrorBucket(0), mFlags(0) { } diff --git a/src/fco/genreswitcher.cpp b/src/fco/genreswitcher.cpp index d1e5796..e3bee5e 100644 --- a/src/fco/genreswitcher.cpp +++ b/src/fco/genreswitcher.cpp @@ -99,14 +99,12 @@ cGenre::Genre cGenreSwitcher::GetDefaultGenre() void cGenreSwitcher::RegisterGenre( const cGenreInfo* pGI, RegisterFlags flags /* = REGISTER_FLAGS_NONE */ ) { cDebug d("cGenreSwitcher::RegisterGenre"); - d.TraceDebug( _T("ID: %x, long name: %s, short name: %s\n"), pGI->m_ID, pGI->m_sLongName.c_str(), pGI->m_sShortName.c_str() ); - // - // validate params - // ASSERT( NULL != pGI ); ASSERT( pGI->IsValid() ); + d.TraceDebug( _T("ID: %x, long name: %s, short name: %s\n"), pGI->m_ID, pGI->m_sLongName.c_str(), pGI->m_sShortName.c_str() ); + // // can only be one of each genre ID // diff --git a/src/tripwire/tripwiremain.cpp b/src/tripwire/tripwiremain.cpp index f93d4f1..a94d6c5 100644 --- a/src/tripwire/tripwiremain.cpp +++ b/src/tripwire/tripwiremain.cpp @@ -243,7 +243,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) ret = 8; } - catch (std::bad_alloc e) + catch (std::bad_alloc& e) { // Note: We use fputs rather than TCERR as it will probably require the // least amount of memory to do its thing. If we ran out of memory we @@ -253,7 +253,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) ret = 8; } - catch (std::exception e) + catch (std::exception& e) { TCERR << _T("*** Fatal exception: "); std::cerr << e.what() << std::endl; diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index 8a59a7f..dcd22d0 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -1476,7 +1476,7 @@ public: cFCOReportHeader* mpReportHeader; // ctor can set up some default values - cTWModeDbUpdate_i() : cTWModeCommon(), mbInteractive(true), mbSecureMode(true), /*mSiteProvided(false),*/ mpReport(0), mpDbFile(0), mpReportHeader(0) {} + cTWModeDbUpdate_i() : cTWModeCommon(), mbInteractive(true), mbSecureMode(true), mbEncryptDb(true), /*mSiteProvided(false),*/ mpReport(0), mpDbFile(0), mpReportHeader(0) {} }; /////////////////////////////////////////////////////////////////////////////// diff --git a/src/tripwire/twcmdline.h b/src/tripwire/twcmdline.h index 59e8141..1dd1c45 100644 --- a/src/tripwire/twcmdline.h +++ b/src/tripwire/twcmdline.h @@ -182,14 +182,17 @@ class cTWModeCommon bool mMailNoViolations; // Email out reports with no violations? TSTRING mMailFrom; - cTWModeCommon() : mVerbosity(1), + cTWModeCommon() : mVerbosity(1), mLocalProvided(false), mbLatePassphrase(false), mfLooseDirs(false), mbResetAccessTime(false), mbLogToSyslog(false), mbCrossFileSystems(false), - mbDirectIO(false) + mbDirectIO(false), + mMailMethod(cMailMessage::NO_METHOD), + mSmtpPort(25), + mMailNoViolations(true) { } }; diff --git a/src/tw/filemanipulator.cpp b/src/tw/filemanipulator.cpp index 4ab1283..0ee37c3 100644 --- a/src/tw/filemanipulator.cpp +++ b/src/tw/filemanipulator.cpp @@ -61,7 +61,8 @@ cFileManipulator::cFileManipulator(const TCHAR* filename) } cFileManipulator::cFileManipulator(const cFileManipulator& rhs) -: mFileName(rhs.mFileName), +: mbInit(false), + mFileName(rhs.mFileName), mFileHeader(rhs.mFileHeader) { } diff --git a/src/tw/textreportviewer.cpp b/src/tw/textreportviewer.cpp index bbbf5ea..f29a6f0 100644 --- a/src/tw/textreportviewer.cpp +++ b/src/tw/textreportviewer.cpp @@ -143,7 +143,8 @@ int cTextReportViewer::Init( const cFCOReportHeader& h, cFCOReport& r ) { mpHeader = &h; mpReport = &r; - mpOut = NULL; + mpOut = NULL; + mpIn = NULL; mpCurPD = NULL; mpCurNT = NULL; mfUpdate = false; @@ -152,6 +153,7 @@ int cTextReportViewer::Init( const cFCOReportHeader& h, cFCOReport& r ) mErrorNum = 1; mReportingLevel = FULL_REPORT; mfGotNumbers = false; + mCurrentChar[0] = '\0'; mCurrentCharSize = 0; return 0; } diff --git a/src/tw/textreportviewer.h b/src/tw/textreportviewer.h index b5321f6..6a2762d 100644 --- a/src/tw/textreportviewer.h +++ b/src/tw/textreportviewer.h @@ -153,7 +153,7 @@ protected: int mChangedObjects; TSTRING mStartPoint; - RuleSummaryLine() {} + RuleSummaryLine() : mSeverity(0), mAddedObjects(0), mRemovedObjects(0), mChangedObjects(0) {} RuleSummaryLine(const RuleSummaryLine& rhs) { *this = rhs; } void operator = (const RuleSummaryLine& rhs) { diff --git a/src/twadmin/twadminmain.cpp b/src/twadmin/twadminmain.cpp index 500cef5..718ea82 100644 --- a/src/twadmin/twadminmain.cpp +++ b/src/twadmin/twadminmain.cpp @@ -203,14 +203,14 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) ret = 1; } - catch (std::bad_alloc e) + catch (std::bad_alloc& e) { TCERR << _T("*** Fatal exception: Out of memory "); TCERR << _T("*** Exiting...\n"); ret = 1; } - catch (std::exception e) + catch (std::exception& e) { TCERR << _T("*** Fatal exception: "); std::cerr << e.what() << std::endl; diff --git a/src/twprint/twprintmain.cpp b/src/twprint/twprintmain.cpp index 474b109..85fbe2a 100644 --- a/src/twprint/twprintmain.cpp +++ b/src/twprint/twprintmain.cpp @@ -217,14 +217,14 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ] ) ret = 1; } - catch (std::bad_alloc e) + catch (std::bad_alloc& e) { TCERR << _T("*** Fatal exception: Out of memory "); TCERR << _T("*** Exiting...\n"); ret = 1; } - catch (std::exception e) + catch (std::exception& e) { TCERR << _T("*** Fatal exception: "); std::cerr << e.what() << std::endl; From b2f21c3d55956b2e64ab2093ec90ff553e1c8036 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 15 Mar 2017 19:06:52 -0700 Subject: [PATCH 09/43] Assorted bounds checks (via flawfinder) --- src/core/debug.cpp | 6 +++--- src/core/errorutil.cpp | 6 +++--- src/core/unixfsservices.cpp | 4 ++-- src/fco/fconametbl.cpp | 5 +++-- src/fco/signature.cpp | 16 ++++++++-------- src/tripwire/smtpmailmessage.cpp | 2 +- src/twparser/yyparse.cpp | 4 ++-- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/core/debug.cpp b/src/core/debug.cpp index 7914f93..6870b7d 100644 --- a/src/core/debug.cpp +++ b/src/core/debug.cpp @@ -63,7 +63,7 @@ cDebug::cDebug(const char* label) cDebug::cDebug(const cDebug &rhs) { - strcpy(mLabel, rhs.mLabel); + strcpy(mLabel, rhs.mLabel, MAX_LABEL); } cDebug::~cDebug() @@ -102,7 +102,7 @@ void cDebug::DoTrace(const char *format, va_list &args) char out[2048]; size_t guard2 = 0xBABABABA; - vsprintf(out, format, args); + vsnprintf(out, 2048, format, args); ASSERT(guard1 == 0xBABABABA && guard2 == 0xBABABABA); // string was too long ASSERT(strlen(out) < 1024); @@ -304,7 +304,7 @@ void cDebug::DebugOut( const char* lpOutputString, ... ) // create the output buffer va_list args; va_start(args, lpOutputString); - vsprintf(buf, lpOutputString, args); + vsnprintf(buf, 2048, lpOutputString, args); va_end(args); #ifdef _DEBUG diff --git a/src/core/errorutil.cpp b/src/core/errorutil.cpp index 65f5099..da4aff8 100644 --- a/src/core/errorutil.cpp +++ b/src/core/errorutil.cpp @@ -43,9 +43,9 @@ #if IS_UNIX namespace //unique { - TCHAR* tw_itot( int value, TCHAR* string, int radix) + TCHAR* tw_itot( int value, TCHAR* string, int radix, int size) { - _stprintf( string, "%d", value ); + snprintf( string, size, "%d", value ); return string; } } @@ -61,7 +61,7 @@ eInternal::eInternal(TCHAR* sourceFile, int lineNum) mMsg = _T("File: "); mMsg += sourceFile; mMsg += _T(" Line: "); - mMsg += tw_itot(lineNum, buf, 10); + mMsg += tw_itot(lineNum, buf, 10, 256); } //============================================================================= diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index 5da6073..6ebf4d1 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -264,7 +264,7 @@ TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const throw(eFSSe char szTemplate[iFSServices::TW_MAX_PATH]; int fd; - strcpy( szTemplate, strName.c_str() ); + strncpy( szTemplate, strName.c_str(), iFSServices::TW_MAX_PATH ); #ifdef HAVE_MKSTEMP // create temp filename and check to see if mkstemp failed @@ -605,7 +605,7 @@ bool cUnixFSServices::GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const void cUnixFSServices::ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) const { TCHAR szPerm[11]; //10 permission bits plus the NULL - _tcscpy( szPerm, _T("----------") ); + strncpy( szPerm, _T("----------"), 11); ASSERT( sizeof(unsigned short) <= sizeof(uint32) ); // We do this in case an "unsigned short" is ever larger than the diff --git a/src/fco/fconametbl.cpp b/src/fco/fconametbl.cpp index 26646d4..9eaa605 100644 --- a/src/fco/fconametbl.cpp +++ b/src/fco/fconametbl.cpp @@ -112,8 +112,9 @@ void cFCONameTblNode::SetString(const TSTRING& newStr) mpString = NULL; } - mpString = (TCHAR*)util_AllocMem( sizeof(TCHAR)*(newStr.length()+1) ); - _tcscpy( mpString, newStr.c_str() ); + size_t alloc_size = sizeof(TCHAR)*(newStr.length()+1); + mpString = (TCHAR*)util_AllocMem(alloc_size); + strncpy( mpString, newStr.c_str(), alloc_size ); // NOTE -- the lower case pointer is now invalid. } diff --git a/src/fco/signature.cpp b/src/fco/signature.cpp index cee4240..27e59f9 100644 --- a/src/fco/signature.cpp +++ b/src/fco/signature.cpp @@ -556,8 +556,8 @@ TSTRING cMD5Signature::AsStringHex() const for(int i = 0; i < SIG_BYTE_SIZE; ++i) { - _stprintf(stringBuffer, _T("%02lx"), (unsigned long)dbuf[i]); - _tcscat(sigStringOut, stringBuffer); + snprintf(stringBuffer, 128, _T("%02lx"), (unsigned long)dbuf[i]); + strncat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -679,8 +679,8 @@ TSTRING cSHASignature::AsStringHex() const for (int i=0; i < SIG_UINT32_SIZE*(int)sizeof(uint32); ++i) { - _stprintf(stringBuffer, _T("%02x"), dbuf[i]); - _tcscat(sigStringOut, stringBuffer); + snprintf(stringBuffer, 128, _T("%02x"), dbuf[i]); + strncat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -754,8 +754,8 @@ TSTRING cSHASignature::AsStringHex() const for (int i=0; i < SIG_UINT32_SIZE; ++i) { - _stprintf(stringBuffer, _T("%08x"), mSHAInfo.digest[i]); - _tcscat(sigStringOut, stringBuffer); + snprintf(stringBuffer, 128, _T("%08x"), mSHAInfo.digest[i]); + strncat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -856,8 +856,8 @@ TSTRING cHAVALSignature::AsStringHex() const for (int i=0; i < SIG_BYTE_SIZE; ++i) { - _stprintf(stringBuffer, _T("%02x"), mSignature[i]); - _tcscat(sigStringOut, stringBuffer); + snprintf(stringBuffer, 128, _T("%02x"), mSignature[i]); + strncat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); diff --git a/src/tripwire/smtpmailmessage.cpp b/src/tripwire/smtpmailmessage.cpp index 4a9ee5e..52c6adc 100644 --- a/src/tripwire/smtpmailmessage.cpp +++ b/src/tripwire/smtpmailmessage.cpp @@ -92,7 +92,7 @@ static int gethostname( char* name, int namelen ) if ( strlen( myname.nodename ) < (unsigned int)namelen ) { - strcpy( name, myname.nodename ); + strncpy( name, myname.nodename, namelen ); return 0; } else diff --git a/src/twparser/yyparse.cpp b/src/twparser/yyparse.cpp index 0bb7645..9deb903 100644 --- a/src/twparser/yyparse.cpp +++ b/src/twparser/yyparse.cpp @@ -1393,7 +1393,7 @@ yy_parse::yyExpandName(int num, int isrule, char * buf, int len) for (endp = buf + len - 8; *s; s++) { if (buf >= endp) { /* too large: return 0 */ - full: (void) strcpy(buf, " ...\n"); + full: (void) strncpy(buf, " ...\n", len); return 0; } else if (*s == '%') { /* nonterminal */ type = 0; @@ -1423,7 +1423,7 @@ yy_parse::yyExpandName(int num, int isrule, char * buf, int len) if ((i = strlen(cp)) + buf > endp) goto full; - (void) strcpy(buf, cp); + (void) strncpy(buf, cp, len); buf += i; } else *buf++ = *s; From 1fb5f332e6dfd5a2d009323d40665ee81dd9f8c2 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 15 Mar 2017 20:31:38 -0700 Subject: [PATCH 10/43] For clarity, remove a bunch of IS_UNIX ifdefs, since configure.ac always defines IS_UNIX to 1 no matter the OS. --- src/core/coreerrors.cpp | 6 ++-- src/core/debug.h | 14 +++------ src/core/displayencoder.cpp | 5 +-- src/core/errorutil.cpp | 4 --- src/core/file.h | 5 --- src/core/fixedfilebuf.h | 3 -- src/core/fsservices.h | 19 +++++------- src/core/msystem.cpp | 5 --- src/core/resources.h | 5 --- src/core/tasktimer.h | 3 +- src/core/tchar.h | 6 ---- src/core/tw_signal.cpp | 9 +----- src/core/unixexcept.cpp | 2 -- src/core/unixfsservices.h | 2 +- src/fco/genreswitcher.cpp | 7 +---- src/fs/fspropcalc.cpp | 13 -------- src/siggen/siggencmdline.cpp | 8 ----- src/siggen/siggenmain.cpp | 4 --- src/tripwire/mailmessage.h | 11 ++----- src/tripwire/smtpmailmessage.cpp | 53 ++++++++++++-------------------- src/tripwire/tripwiremain.cpp | 6 ---- src/tripwire/twcmdline.cpp | 30 +++--------------- src/tw/textdbviewer.cpp | 4 +-- src/tw/textreportviewer.cpp | 9 ------ src/tw/twinit.cpp | 4 --- src/tw/twutil.cpp | 5 --- src/twadmin/keygeneration.cpp | 4 --- src/twadmin/twadminmain.cpp | 5 --- src/twprint/twprintmain.cpp | 4 --- src/twtest/tasktimer_t.cpp | 3 +- src/twtest/test.cpp | 4 --- src/twtest/test.h | 9 ------ src/twtest/twutil_t.cpp | 12 +------- src/twtest/unixfsservices_t.cpp | 4 +-- src/util/fileutil.cpp | 7 +---- 35 files changed, 51 insertions(+), 243 deletions(-) diff --git a/src/core/coreerrors.cpp b/src/core/coreerrors.cpp index 2df59aa..2c249d0 100644 --- a/src/core/coreerrors.cpp +++ b/src/core/coreerrors.cpp @@ -98,11 +98,9 @@ TSS_REGISTER_ERROR( eFileFlush(), _T("File could not be flushed.") ) TSS_REGISTER_ERROR( eFileRewind(), _T("File could not be rewound.") ) -/// Win32 - -#if IS_UNIX +/// General API failures TSS_REGISTER_ERROR(eUnix(), _T("Unix API failure.") ) -#endif + /// FSServices diff --git a/src/core/debug.h b/src/core/debug.h index d7b0033..499fcf7 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -208,16 +208,10 @@ inline void cDebug::DebugOut ( const char*, ... ) {} // ASSERT macro ////////////////////////////////////////////////////////////////////////////////// - -#if IS_UNIX - - #define ASSERTMSG( exp, s ) assert( (exp) != 0 ) - #define ASSERT( exp ) assert( (exp) != 0 ) - // if we are not windows we will just use the standard assert() - #define TSS_DebugBreak() ASSERT( false ); - -#endif// IS_UNIX - +#define ASSERTMSG( exp, s ) assert( (exp) != 0 ) +#define ASSERT( exp ) assert( (exp) != 0 ) + // if we are not windows we will just use the standard assert() +#define TSS_DebugBreak() ASSERT( false ); #ifndef ASSERT #error ASSERT did not get defined!!! diff --git a/src/core/displayencoder.cpp b/src/core/displayencoder.cpp index b6027e9..e0e1102 100644 --- a/src/core/displayencoder.cpp +++ b/src/core/displayencoder.cpp @@ -506,11 +506,8 @@ bool cCharEncoderUtil::IsPrintable( TCHAR ch ) return( ! isprint( ch ) ); // kludge for KAI #else // USE_CLIB_LOCALE - -#if IS_UNIX - return( ! std::isprint( ch, std::locale() ) ); - #endif + return( ! std::isprint( ch, std::locale() ) ); #endif // USE_CLIB_LOCALE } diff --git a/src/core/errorutil.cpp b/src/core/errorutil.cpp index da4aff8..e4f7af5 100644 --- a/src/core/errorutil.cpp +++ b/src/core/errorutil.cpp @@ -40,7 +40,6 @@ // class eInternal //============================================================================= -#if IS_UNIX namespace //unique { TCHAR* tw_itot( int value, TCHAR* string, int radix, int size) @@ -49,9 +48,6 @@ namespace //unique return string; } } -#else - #define tw_itot _itot -#endif //IS_UNIX eInternal::eInternal(TCHAR* sourceFile, int lineNum) : eError(_T("")) diff --git a/src/core/file.h b/src/core/file.h index 1964e31..b261da2 100644 --- a/src/core/file.h +++ b/src/core/file.h @@ -74,12 +74,7 @@ struct cFile_i; class cFile { public: -#if IS_UNIX typedef off_t File_t; -#else //WIN32 - typedef int64 File_t; - -#endif // IS_UNIX enum SeekFrom { diff --git a/src/core/fixedfilebuf.h b/src/core/fixedfilebuf.h index adf7d00..8ce2d6e 100644 --- a/src/core/fixedfilebuf.h +++ b/src/core/fixedfilebuf.h @@ -45,10 +45,7 @@ #define __FIXED_FILEBUF_H #include - -#if IS_UNIX #define fixed_basic_ofstream std::basic_ofstream -#endif // IS_WIN32/IS_UNIX #endif//__FIXED_FILEBUF_H diff --git a/src/core/fsservices.h b/src/core/fsservices.h index 8c58a0e..0aed4c1 100644 --- a/src/core/fsservices.h +++ b/src/core/fsservices.h @@ -65,16 +65,15 @@ // STANDARD LIBRARY INCLUDES //========================================================================= -#if IS_UNIX - #if HAVE_SYS_PARAM_H - #include - #endif +#if HAVE_SYS_PARAM_H +# include +#endif #if HAVE_SYS_STAT_H -#include -#endif +# include #endif + //========================================================================= // DEFINES AND MACROS //========================================================================= @@ -209,13 +208,11 @@ class iFSServices // maximum path length on platform //////////////////////////////////////// enum - { -#if IS_UNIX - #ifdef MAXPATHLEN + { +#ifdef MAXPATHLEN TW_MAX_PATH = MAXPATHLEN - #else +#else TW_MAX_PATH = 1024 - #endif #endif }; diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index 09a2653..5c3a4d4 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -66,8 +66,6 @@ #include "stdcore.h" -#if IS_UNIX - /* * set, reset environment to be passed to mpopem */ @@ -1038,6 +1036,3 @@ int pid; */ return(status); } - -#endif //#if IS_UNIX - diff --git a/src/core/resources.h b/src/core/resources.h index 66333fe..6ef4161 100644 --- a/src/core/resources.h +++ b/src/core/resources.h @@ -241,14 +241,9 @@ Resource_Class::Get( ConstKeyRef id ) const if ( at == m_table.end() ) { - #if IS_UNIX #ifdef _DEBUG std::cerr << "*** Error Resource_Class::Get() [" __FILE__ ":" << __LINE__ << "]: Resource not found\n"; #endif - #else - ASSERTMSG( 0, "Resource does not exist!" ); - #endif - // TSS_Raise( eInternal, "Resource does not exist!" ); return DefaultValueRef(); } diff --git a/src/core/tasktimer.h b/src/core/tasktimer.h index c0d7f9b..d65fbe6 100644 --- a/src/core/tasktimer.h +++ b/src/core/tasktimer.h @@ -73,7 +73,6 @@ private: }; -#if IS_UNIX /////////////////////////////////////////////////////////////////////////////// // cUnixTimeFn -- Unix version, inserts proper function call and overloads // operator() @@ -98,7 +97,7 @@ private: typedef cTaskTimer cUnixTaskTimer; typedef cUnixTaskTimer cGenericTaskTimer; -#endif // IS_UNIX + //----------------------------------------------------------------------------- // inline implementation diff --git a/src/core/tchar.h b/src/core/tchar.h index d483883..2871a16 100644 --- a/src/core/tchar.h +++ b/src/core/tchar.h @@ -60,16 +60,12 @@ // A little macro that's useful for finding the number of characters in a TCHAR ARRAY #define countof( x ) ( sizeof( x ) / sizeof( x[0] ) ) -#if IS_UNIX - #include #include #include #include - - #define TCHAR char #define _tmain main @@ -129,7 +125,5 @@ typedef std::ifstream TIFSTREAM; #define __cdecl #endif -#endif // WIN32 - #endif // __TCHAR_H diff --git a/src/core/tw_signal.cpp b/src/core/tw_signal.cpp index 4ce122d..e13feb8 100644 --- a/src/core/tw_signal.cpp +++ b/src/core/tw_signal.cpp @@ -38,9 +38,7 @@ static void util_SignalHandler( int sig ); -#if IS_UNIX static void tw_psignal( int sig, const TCHAR* s ); -#endif tw_sighandler_t tw_signal(int sig, tw_sighandler_t pFunc) { @@ -69,15 +67,10 @@ void util_SignalHandler( int sig ) { //If we're on unix, let's print out a nice error message telling //the user which signal we've recieved. -#if IS_UNIX tw_psignal( sig, (TSS_GetString( cCore, core::STR_SIGNAL).c_str() ) ); -#endif - exit( 8 ); } -#if IS_UNIX - /* For the morbidly curious, here's a thread where a POSIX standards committee wrings its hands about how to define NSIG: http://austingroupbugs.net/view.php?id=741#c1834 */ #ifndef NSIG @@ -126,5 +119,5 @@ void tw_psignal(int sig, const TCHAR *str) _ftprintf(stderr, _T("%s %s\n"), str, sig < NSIG ? siglist[sig] : siglist[0]); } -#endif + diff --git a/src/core/unixexcept.cpp b/src/core/unixexcept.cpp index 5b89795..0ab1c19 100644 --- a/src/core/unixexcept.cpp +++ b/src/core/unixexcept.cpp @@ -41,7 +41,6 @@ eUnix::eUnix( const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCallGetLastError) : eError( _T("")) { -#if IS_UNIX ASSERT( szFunctionName || szObjectName || fCallGetLastError ); // // construct the error message: @@ -78,7 +77,6 @@ eUnix::eUnix( const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCall mMsg += strErr; } } -#endif // IS_UNIX } // eof - unixexcept.cpp diff --git a/src/core/unixfsservices.h b/src/core/unixfsservices.h index 4bde573..c0fd1bc 100644 --- a/src/core/unixfsservices.h +++ b/src/core/unixfsservices.h @@ -39,7 +39,7 @@ #define __UNIXFSSERVICES_H #if !IS_UNIX -#error unixfsservices.h should only be included for instantiating cUnixFSServices objects. If you just want to use iFSServices methods, include fsservices.h. Same goes for cWin32FSServices. +#error unixfsservices.h should only be included for instantiating cUnixFSServices objects. If you just want to use iFSServices methods, include fsservices.h. #endif //========================================================================= diff --git a/src/fco/genreswitcher.cpp b/src/fco/genreswitcher.cpp index e3bee5e..1702f98 100644 --- a/src/fco/genreswitcher.cpp +++ b/src/fco/genreswitcher.cpp @@ -143,12 +143,7 @@ bool cGenreSwitcher::IsGenreRegistered( cGenre::Genre g ) bool cGenreSwitcher::IsGenreAppropriate( cGenre::Genre g ) { -#if IS_UNIX - const uint32 platformMask = cGenre::PLATFORM_MASK_UNIX; - #else - #error who am I? - #endif - + const uint32 platformMask = cGenre::PLATFORM_MASK_UNIX; return( ( platformMask & g ) != 0 ); } diff --git a/src/fs/fspropcalc.cpp b/src/fs/fspropcalc.cpp index 585df89..f575bfd 100644 --- a/src/fs/fspropcalc.cpp +++ b/src/fs/fspropcalc.cpp @@ -45,10 +45,7 @@ #include "fspropcalc.h" #include "fsobject.h" - -#if IS_UNIX #include -#endif cFSPropCalc::cFSPropCalc() : @@ -93,11 +90,6 @@ static bool NeedsStat(const cFCOPropVector& v) static bool GetSymLinkStr(const cFCOName& fileName, cArchive& arch) { -#if !IS_WIN32 -#ifdef _UNICODE -#error GetSymLinkStr in fspropcalc.cpp is not unicode compliant -#else // ifdef _UNICODE - char buf[1024]; #if defined(O_PATH) int fd = open(iTWFactory::GetInstance()->GetNameTranslator()->ToStringAPI( fileName ).c_str(), @@ -116,11 +108,6 @@ static bool GetSymLinkStr(const cFCOName& fileName, cArchive& arch) arch.WriteBlob(buf, rtn); return true; - -#endif // ifdef _UNICODE -#else // if !IS_WIN32 - return false; // TODO: find better way to do this -- just a place holder -#endif // if !IS_WIN32 } diff --git a/src/siggen/siggencmdline.cpp b/src/siggen/siggencmdline.cpp index 347f87c..370d965 100644 --- a/src/siggen/siggencmdline.cpp +++ b/src/siggen/siggencmdline.cpp @@ -46,8 +46,6 @@ #include // for the FileExists() stuff - -#if IS_UNIX #include #include #if SUPPORTS_TERMIOS @@ -56,7 +54,6 @@ #endif //#include int _getch(void); -#endif using namespace std; @@ -373,11 +370,6 @@ void PrintHeader( TSTRING filename) bool util_FileExists(const TSTRING& fileName) { -#if IS_UNIX - // for unix we may be able to use the same logic as above, but - // it is too close to 2.2.1 release to make that change w/o testing. - // I know the above works for windows. return _taccess(fileName.c_str(), F_OK) == 0; -#endif } diff --git a/src/siggen/siggenmain.cpp b/src/siggen/siggenmain.cpp index c669722..0427b71 100644 --- a/src/siggen/siggenmain.cpp +++ b/src/siggen/siggenmain.cpp @@ -55,10 +55,8 @@ #include #include -#if IS_UNIX #include "core/unixfsservices.h" #include -#endif /////////////////////////////////////////////////////////////////////////////// // terminate and unexpected handlers @@ -93,9 +91,7 @@ static void SiggenInit() // // set up the file system services // -#if IS_UNIX static cUnixFSServices fss; -#endif iFSServices::SetInstance( &fss ); // diff --git a/src/tripwire/mailmessage.h b/src/tripwire/mailmessage.h index b8ef197..dfec57c 100644 --- a/src/tripwire/mailmessage.h +++ b/src/tripwire/mailmessage.h @@ -36,13 +36,10 @@ #include "core/error.h" #endif - -#if IS_UNIX -# if HAVE_SYS_SOCKET_H -# include -# endif -# define SOCKET int +#if HAVE_SYS_SOCKET_H +# include #endif +#define SOCKET int /////////////////////////////////////////////////////////////////////////////// @@ -250,8 +247,6 @@ private: }; -//#ifdef IS_UNIX - /////////////////////////////////////////////////////////////////////////////// // // This class implements sending a message through a unix pipe to a program diff --git a/src/tripwire/smtpmailmessage.cpp b/src/tripwire/smtpmailmessage.cpp index 52c6adc..9e63bc7 100644 --- a/src/tripwire/smtpmailmessage.cpp +++ b/src/tripwire/smtpmailmessage.cpp @@ -40,8 +40,6 @@ #include "core/msystem.h" #include "core/file.h" -#if IS_UNIX - #include //All the spleck that it takes to run sockets in Unix... @@ -106,24 +104,24 @@ static int gethostname( char* name, int namelen ) #endif } -#endif - // Unix does not require us to go though any silly DLL hoops, so we'll - // just #define the pointers to functions needed by Windows to be the - // berkely functions. - #define mPfnSocket socket - #define mPfnInetAddr inet_addr - #define mPfnGethostname gethostname - #define mPfnGethostbyname gethostbyname - #define mPfnConnect connect - #define mPfnCloseSocket close - #define mPfnSend send - #define mPfnRecv recv - #define mPfnSelect select - #define mPfnNtohl ntohl - #define mPfnHtonl htonl - #define mPfnNtohs ntohs - #define mPfnHtons htons -#endif +#endif //HAVE_GETHOSTNAME + +// Unix does not require us to go though any silly DLL hoops, so we'll +// just #define the pointers to functions needed by Windows to be the +// berkely functions. +#define mPfnSocket socket +#define mPfnInetAddr inet_addr +#define mPfnGethostname gethostname +#define mPfnGethostbyname gethostbyname +#define mPfnConnect connect +#define mPfnCloseSocket close +#define mPfnSend send +#define mPfnRecv recv +#define mPfnSelect select +#define mPfnNtohl ntohl +#define mPfnHtonl htonl +#define mPfnNtohs ntohs +#define mPfnHtons htons // // TODO - maybe convert this SMTP code to non-blocking socket calls, or use @@ -215,9 +213,8 @@ bool cSMTPMailMessage::OpenConnection() sockAddrIn.sin_port = mPfnHtons(mPortNumber); uint32 iServerAddress = GetServerAddress(); -#if IS_UNIX sockAddrIn.sin_addr.s_addr = iServerAddress; -#endif + if ( iServerAddress == INADDR_NONE ) { DecodeError(); @@ -494,14 +491,8 @@ bool cSMTPMailMessage::GetAcknowledgement() // need comment timeval tv; - -#if IS_UNIX FD_ZERO( &socketSet ); FD_SET( mSocket, &socketSet ); -#else - socketSet.fd_count = 1; - socketSet.fd_array[0] = mSocket; -#endif // set the timeout time to sixty seconds tv.tv_sec = 60; @@ -567,15 +558,9 @@ void cSMTPMailMessage::SendString( const std::string& str ) void cSMTPMailMessage::DecodeError() { #if defined(_DEBUG) - -#if IS_UNIX - // // TODO - Write what ever error reporting will be needed under unix. // - -#endif // IS_UNIX - #endif // defined(_DEBUG) } diff --git a/src/tripwire/tripwiremain.cpp b/src/tripwire/tripwiremain.cpp index a94d6c5..67a81f2 100644 --- a/src/tripwire/tripwiremain.cpp +++ b/src/tripwire/tripwiremain.cpp @@ -55,12 +55,8 @@ #include "fco/fcogenre.h" #include "fco/genreswitcher.h" -#if IS_UNIX #include "core/unixfsservices.h" #include -#else -#error Who the hell am I? -#endif static TSTRING util_GetWholeCmdLine( int argc, const TCHAR *argv[] ); @@ -171,13 +167,11 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) TSTRING commandLine = util_GetWholeCmdLine( argc, argv ); - #if IS_UNIX // erase the command line // TODO: it might be a good idea to move this to cTWUtil int i; for (i = 1; i < argc; ++i) memset((char*)argv[i], 0, strlen(argv[i])*sizeof(TCHAR)); - #endif cCmdLineIter iter(cmdLine); if (iter.SeekToArg(cTWCmdLine::HELP)) diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index dcd22d0..e6de6a4 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -78,11 +78,8 @@ #include "tasktimer.h" #endif -#if IS_UNIX #include "fs/fsdatasourceiter.h" // for cross file systems flag #include // for _exit() -#endif - //----------------------------------------------------------------------------- // #defines @@ -277,15 +274,10 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf) } if(cf.Lookup(TSTRING(_T("RESETACCESSTIME")), str)) { - - -#if IS_UNIX // We do not support reset access time on Unix, so we issue a warning. // This used to be a fatal error, however this prevents // cross platform config files. cTWUtil::PrintErrorMsg(eTWInvalidConfigFileKey(_T("RESETACCESSTIME"), eError::NON_FATAL)); -#endif - } if(cf.Lookup(TSTRING(_T("LOOSEDIRECTORYCHECKING")), str)) { @@ -649,12 +641,9 @@ bool cTWModeDbInit::Init(const cConfigFile& cf, const cCmdLineParser& cmdLine) if (cTWUtil::VerifyCfgSiteKey( mstrConfigFile, mpData->mSiteKeyFile ) == false) cTWUtil::PrintErrorMsg(eTWCfgUnencrypted(_T(""), eError::NON_FATAL|eError::SUPRESS_THIRD_MSG)); - #if IS_UNIX // Set the cross file systems flag appropriately. cFSDataSourceIter::SetFileSystemCrossing(mpData->mbCrossFileSystems); - #endif - - return true; + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -1021,13 +1010,10 @@ bool cTWModeIC::Init(const cConfigFile& cf, const cCmdLineParser& cmdLine) // if (cTWUtil::VerifyCfgSiteKey( mstrConfigFile, mpData->mSiteKeyFile ) == false) cTWUtil::PrintErrorMsg(eTWCfgUnencrypted(_T(""), eError::NON_FATAL|eError::SUPRESS_THIRD_MSG)); - - #if IS_UNIX + // Set the cross file systems flag appropriately. cFSDataSourceIter::SetFileSystemCrossing(mpData->mbCrossFileSystems); - #endif - - return true; + return true; } @@ -1586,12 +1572,9 @@ bool cTWModeDbUpdate::Init(const cConfigFile& cf, const cCmdLineParser& cmdLine) if (cTWUtil::VerifyCfgSiteKey( mstrConfigFile, mpData->mSiteKeyFile ) == false) cTWUtil::PrintErrorMsg(eTWCfgUnencrypted(_T(""), eError::NON_FATAL|eError::SUPRESS_THIRD_MSG)); - #if IS_UNIX // Set the cross file systems flag appropriately. cFSDataSourceIter::SetFileSystemCrossing(mpData->mbCrossFileSystems); - #endif - - return true; + return true; } void cTWModeDbUpdate::Init(const cTWModeIC_i* pICData, cFCODatabaseFile* dbFile, cFCOReportHeader* prh, cFCOReport* pReport, bool bEncryptDb) @@ -1958,12 +1941,9 @@ bool cTWModePolUpdate::Init(const cConfigFile& cf, const cCmdLineParser& cmdLine if (cTWUtil::VerifyCfgSiteKey( mstrConfigFile, mpData->mSiteKeyFile ) == false) cTWUtil::PrintErrorMsg(eTWCfgUnencrypted(_T(""), eError::NON_FATAL|eError::SUPRESS_THIRD_MSG)); - #if IS_UNIX // Set the cross file systems flag appropriately. cFSDataSourceIter::SetFileSystemCrossing(mpData->mbCrossFileSystems); - #endif - - return true; + return true; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/tw/textdbviewer.cpp b/src/tw/textdbviewer.cpp index 3b7647b..d6dd5c3 100644 --- a/src/tw/textdbviewer.cpp +++ b/src/tw/textdbviewer.cpp @@ -283,8 +283,6 @@ static void OutputDatabaseHeader( const cFCODbHeader& dbHeader, TOSTREAM* pOut ) (*pOut) << TSS_GetString( cTW, tw::STR_HOST_IP ) << dbHeader.GetIPAddress() << endl; -// only output host ID on UNIX systems -#if IS_UNIX (*pOut).width(headerColumnWidth); (*pOut) << TSS_GetString( cTW, tw::STR_HOST_ID ); @@ -292,7 +290,7 @@ static void OutputDatabaseHeader( const cFCODbHeader& dbHeader, TOSTREAM* pOut ) (*pOut) << dbHeader.GetHostID() << endl; else (*pOut) << TSS_GetString( cTW, tw::STR_NONE ) << endl; -#endif + (*pOut) << setw(headerColumnWidth) << TSS_GetString( cTW, tw::STR_POLICY_FILE_USED ) diff --git a/src/tw/textreportviewer.cpp b/src/tw/textreportviewer.cpp index f29a6f0..2d6986d 100644 --- a/src/tw/textreportviewer.cpp +++ b/src/tw/textreportviewer.cpp @@ -696,9 +696,6 @@ bool cTextReportViewer::LaunchEditorOnFile( const TSTRING& strFilename, const TS // make sure we can read from this file cFileUtil::TestFileReadable( strFilename ); -#if IS_UNIX - - // editor is going to need terminal type, so tell msystem to include // it in environment when it makes its system call. le_set("TERM"); @@ -720,8 +717,6 @@ bool cTextReportViewer::LaunchEditorOnFile( const TSTRING& strFilename, const TS //ASSERT( false ); throw eTextReportViewerEditorLaunch( edName ); } - -#endif //if IS_WIN32 return( fRanViewer ); } @@ -1166,8 +1161,6 @@ void cTextReportViewer::OutputReportHeader() (*mpOut).width(headerColumnWidth); (*mpOut) << TSS_GetString( cTW, tw::STR_HOST_IP ) << mpHeader->GetIPAddress() << endl; -// only output host ID on UNIX systems -#if IS_UNIX (*mpOut).width(headerColumnWidth); (*mpOut) << TSS_GetString( cTW, tw::STR_HOST_ID ); @@ -1175,8 +1168,6 @@ void cTextReportViewer::OutputReportHeader() (*mpOut) << mpHeader->GetHostID() << endl; else (*mpOut) << TSS_GetString( cTW, tw::STR_NONE ) << endl; -#endif - (*mpOut) << setw(headerColumnWidth) << TSS_GetString( cTW, tw::STR_POLICY_FILE_USED ) diff --git a/src/tw/twinit.cpp b/src/tw/twinit.cpp index 99e2947..cac48aa 100644 --- a/src/tw/twinit.cpp +++ b/src/tw/twinit.cpp @@ -74,10 +74,8 @@ #include "fco/fconame.h" #include "fs/fs.h" // object initialization -#if IS_UNIX #include "core/unixfsservices.h" #include "core/tw_signal.h" // to ignore SIGPIPE -#endif #if IS_AROS #include @@ -252,9 +250,7 @@ void cTWInit::Init( const TSTRING& strArgv0 ) // // set up the file system services // -#if IS_UNIX mpData->pFSServices = new cUnixFSServices; -#endif ASSERT( mpData->pFSServices != 0 ); iFSServices::SetInstance( mpData->pFSServices ); diff --git a/src/tw/twutil.cpp b/src/tw/twutil.cpp index 4172aaa..46b9ab8 100644 --- a/src/tw/twutil.cpp +++ b/src/tw/twutil.cpp @@ -71,13 +71,11 @@ #include "core/fsservices.h" // for the util_IsDir() stuff -#if IS_UNIX #include #include #if SUPPORTS_TERMIOS # include # include -#endif #include "core/tw_signal.h" int _getch(void); @@ -1117,8 +1115,6 @@ void cTWUtil::CreatePrivateKey(cPrivateKeyProxy& proxy, cKeyFile& keyFile, const // GetStringNoEcho -- Get a string from the user without echoing it /////////////////////////////////////////////////////////////////////////////// - -#if IS_UNIX static void (*old_SIGINT)(int); static void (*old_SIGQUIT)(int); @@ -1216,7 +1212,6 @@ void cTWUtil::GetStringNoEcho(wc16_string& ret) NoEcho noEcho; GetString(ret); } -#endif /////////////////////////////////////////////////////////////////////////////// // ParseObjectList diff --git a/src/twadmin/keygeneration.cpp b/src/twadmin/keygeneration.cpp index f8843eb..600f3a8 100644 --- a/src/twadmin/keygeneration.cpp +++ b/src/twadmin/keygeneration.cpp @@ -143,18 +143,14 @@ bool GenerateKey(const TCHAR* keyPath, wc16_string passphrase, const cElGamalSig iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, TSS_GetString(cTWAdmin, twadmin::STR_GENERATING_KEYS).c_str()); -#if IS_UNIX fflush(stdout); -#endif tGK gk; gk.passphrase = (int8*)passphrase.data(); gk.passphraseLen = passphrase.length() * sizeof(WCHAR16); gk.keyPath = keyPath; -#if IS_UNIX GeneratePublicPrivateKeys(&gk, key_size); -#endif if (gk.retValue != tGK::OK) { diff --git a/src/twadmin/twadminmain.cpp b/src/twadmin/twadminmain.cpp index 718ea82..b24fe6d 100644 --- a/src/twadmin/twadminmain.cpp +++ b/src/twadmin/twadminmain.cpp @@ -49,10 +49,7 @@ #include "twadmin.h" // for package initialization #include - -#if IS_UNIX #include -#endif /////////////////////////////////////////////////////////////////////////////// // terminate and unexpected handlers @@ -131,13 +128,11 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) goto exit; } - #if IS_UNIX // erase the command line // TODO: it might be a good idea to move this to cTWUtil int i; for (i = 1; i < argc; ++i) memset((char*)argv[i], 0, strlen(argv[i])*sizeof(TCHAR)); - #endif cCmdLineIter iter(cmdLine); if (iter.SeekToArg(cTWAdminCmdLine::HELP)) diff --git a/src/twprint/twprintmain.cpp b/src/twprint/twprintmain.cpp index 85fbe2a..c55631e 100644 --- a/src/twprint/twprintmain.cpp +++ b/src/twprint/twprintmain.cpp @@ -53,10 +53,8 @@ #include "twprint.h" // package initialization -#if IS_UNIX #include "core/unixfsservices.h" #include -#endif #include // for auto_ptr #include @@ -155,13 +153,11 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ] ) goto exit; } - #if IS_UNIX // erase the command line // TODO: it might be a good idea to move this to cTWUtil int i; for (i = 1; i < argc; ++i) memset((char*)argv[i], 0, strlen(argv[i])*sizeof(char)); - #endif cCmdLineIter iter(cmdLine); if (iter.SeekToArg(cTWPrintCmdLine::HELP)) diff --git a/src/twtest/tasktimer_t.cpp b/src/twtest/tasktimer_t.cpp index 617e54f..2770e28 100644 --- a/src/twtest/tasktimer_t.cpp +++ b/src/twtest/tasktimer_t.cpp @@ -32,9 +32,8 @@ // tasktimer_t -- test driver for cTaskTimer #include "core/stdcore.h" -#if IS_UNIX void TestTaskTimer() { } -#endif // IS_UNIX/WIN32 + diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index 4bdc1df..88db4f0 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -91,9 +91,7 @@ void TestSerializerImpl(); void TestRefCountObj(); void TestSignature(); void TestSerRefCountObj(); -#if IS_UNIX void TestUnixFSServices(); -#endif //void TestFCODatabase(); void TestError(); void TestDebug(); @@ -203,9 +201,7 @@ static void Test(int testID) //case 41: TestFCODatabase(); break; case 42: TestHashTable(); break; case 43: TestTCHAR(); break; - #if IS_UNIX case 44: TestUnixFSServices(); break; - #endif case 46: TestConfigFile(); break; #ifdef PARSER_PRESENT case 47: TestPolicyParser(); break; diff --git a/src/twtest/test.h b/src/twtest/test.h index 83c36bd..6931009 100644 --- a/src/twtest/test.h +++ b/src/twtest/test.h @@ -48,10 +48,8 @@ #include "core/debug.h" #endif -#if IS_UNIX #include using namespace std; -#endif //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Dependencies @@ -68,23 +66,16 @@ TSS_EndPackage( cTest ) /////////////////////////////////////////////////////////////////////////////// // TEST() -- Works like ASSERT() but it also breaks during release mode - -#if IS_UNIX - #define TEST(exp) if (!(exp)) \ { \ std::cerr<<"TEST(" << #exp << ") failure, file " << __FILE__ << " line " << __LINE__ << std::endl; \ exit(-1); \ } -#endif /////////////////////////////////////////////////////////////////////////////// // Platform dependancies - -#if IS_UNIX #define TEMP_DIR _T("/tmp") #define TEMP_DIR_N "/tmp" -#endif #endif // __TEST_H diff --git a/src/twtest/twutil_t.cpp b/src/twtest/twutil_t.cpp index 3ed11e1..545c4bd 100644 --- a/src/twtest/twutil_t.cpp +++ b/src/twtest/twutil_t.cpp @@ -37,13 +37,9 @@ #include "twtest/test.h" #include - - -#if IS_UNIX //#include #include #include -#endif std::string WideToNarrow( const TSTRING& strWide ); @@ -69,12 +65,7 @@ void TestTWUtil() tmpFN += _T("/fileexiststest.tmp"); // make a subdir in the TEMP_DIR - #if IS_UNIX _tmkdir(tmpDir.c_str(), 0700); - #else - _tmkdir(tmpDir.c_str()); - #endif - _tchmod(tmpDir.c_str(), 0700); // make sure file is not there @@ -88,11 +79,10 @@ void TestTWUtil() TEST(cTWUtil::FileExists(tmpFN) == false); // make the dir read only and make sure write tests false - #if IS_UNIX // windows fails this test, perhaps because I am an administrator? + // windows fails this test, perhaps because I am an administrator? _tchmod(tmpDir.c_str(), 0500); TEST(cTWUtil::FileWritable(tmpFN) == false); _tchmod(tmpDir.c_str(), 0700); - #endif // create the file { diff --git a/src/twtest/unixfsservices_t.cpp b/src/twtest/unixfsservices_t.cpp index 09fb401..5f46f32 100644 --- a/src/twtest/unixfsservices_t.cpp +++ b/src/twtest/unixfsservices_t.cpp @@ -38,8 +38,6 @@ #include "core/archive.h" #include "fco/fconame.h" -#if IS_UNIX - #ifndef __TEST_H #include "twtest/test.h" #endif @@ -182,7 +180,7 @@ void TestUnixFSServices() } } -#endif // IS_UNIX + diff --git a/src/util/fileutil.cpp b/src/util/fileutil.cpp index 1b9368f..69dd3a6 100644 --- a/src/util/fileutil.cpp +++ b/src/util/fileutil.cpp @@ -47,12 +47,11 @@ #include // for the FileExists() stuff -#if IS_UNIX #include #include #include #include -#endif + /////////////////////////////////////////////////////////////////////////////// @@ -237,8 +236,6 @@ bool cFileUtil::BackupFile(const TSTRING& filename, bool printWarningOnFailure) bool cFileUtil::Copy(const TSTRING& src_path, const TSTRING& dest_path) { -#if IS_UNIX - enum { BUF_SIZE = 4096 }; int8 buf[BUF_SIZE]; int nBytesRead; @@ -266,8 +263,6 @@ bool cFileUtil::Copy(const TSTRING& src_path, const TSTRING& dest_path) srcFile.Close(); destFile.Close(); - -#endif return true; } From 900fad8ca4e8d7a441a95bd5a801df3d5a57a06e Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 15 Mar 2017 20:58:49 -0700 Subject: [PATCH 11/43] Remove some dead code, including objectpool & Unicode-only utf8 stuff --- src/core/Makefile.am | 8 +- src/core/Makefile.in | 25 +++-- src/core/archive.h | 23 ----- src/core/objectpool.cpp | 131 ------------------------- src/core/objectpool.h | 140 --------------------------- src/core/utf8.cpp | 152 ----------------------------- src/core/utf8.h | 187 ------------------------------------ src/fco/fconametbl.cpp | 2 - src/fco/fconametbl.h | 9 -- src/fs/fsobject.cpp | 3 - src/twtest/Makefile.am | 1 - src/twtest/Makefile.in | 17 ++-- src/twtest/objectpool_t.cpp | 114 ---------------------- src/twtest/test.cpp | 4 +- 14 files changed, 26 insertions(+), 790 deletions(-) delete mode 100644 src/core/objectpool.cpp delete mode 100644 src/core/objectpool.h delete mode 100644 src/core/utf8.cpp delete mode 100644 src/core/utf8.h delete mode 100644 src/twtest/objectpool_t.cpp diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 17ac252..484e642 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -12,11 +12,11 @@ libcore_a_SOURCES = \ displayutil.cpp error.cpp errorbucketimpl.cpp errortable.cpp \ errorutil.cpp fileerror.cpp fileheader.cpp fsservices.cpp \ growheap.cpp hashtable.cpp haval.cpp msystem.cpp ntmbs.cpp \ - objectpool.cpp refcountobj.cpp serializable.cpp serializer.cpp \ + refcountobj.cpp serializable.cpp serializer.cpp \ serializerimpl.cpp serializerutil.cpp serstring.cpp \ srefcountobj.cpp srefcounttbl.cpp stdcore.cpp stringutil.cpp \ timebomb.cpp timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \ - unixexcept.cpp usernotify.cpp usernotifystdout.cpp utf8.cpp \ + unixexcept.cpp usernotify.cpp usernotifystdout.cpp \ wchar16.cpp libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ @@ -24,12 +24,12 @@ libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ displayutil.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \ errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \ fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \ - ntmbs.h objectpool.h package.h platform.h refcountobj.h resources.h \ + ntmbs.h package.h platform.h refcountobj.h resources.h \ serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \ sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \ tchar.h timebomb.h timeconvert.h tw_signal.h twlimits.h twlocale.h \ twstringslang.h typed.h types.h unixexcept.h unixfsservices.h upperbound.h \ - usernotify.h usernotifystdout.h utf8.h wchar16.h + usernotify.h usernotifystdout.h wchar16.h libcore_a_LIBADD = @CORE_CRYPT_O@ libcore_a_DEPENDENCIES = @CORE_CRYPT_O@ diff --git a/src/core/Makefile.in b/src/core/Makefile.in index b838a07..c013c55 100644 --- a/src/core/Makefile.in +++ b/src/core/Makefile.in @@ -118,15 +118,14 @@ am_libcore_a_OBJECTS = file_unix.$(OBJEXT) unixfsservices.$(OBJEXT) \ errorutil.$(OBJEXT) fileerror.$(OBJEXT) fileheader.$(OBJEXT) \ fsservices.$(OBJEXT) growheap.$(OBJEXT) hashtable.$(OBJEXT) \ haval.$(OBJEXT) msystem.$(OBJEXT) ntmbs.$(OBJEXT) \ - objectpool.$(OBJEXT) refcountobj.$(OBJEXT) \ - serializable.$(OBJEXT) serializer.$(OBJEXT) \ - serializerimpl.$(OBJEXT) serializerutil.$(OBJEXT) \ - serstring.$(OBJEXT) srefcountobj.$(OBJEXT) \ - srefcounttbl.$(OBJEXT) stdcore.$(OBJEXT) stringutil.$(OBJEXT) \ - timebomb.$(OBJEXT) timeconvert.$(OBJEXT) tw_signal.$(OBJEXT) \ - twlimits.$(OBJEXT) twlocale.$(OBJEXT) unixexcept.$(OBJEXT) \ - usernotify.$(OBJEXT) usernotifystdout.$(OBJEXT) utf8.$(OBJEXT) \ - wchar16.$(OBJEXT) + refcountobj.$(OBJEXT) serializable.$(OBJEXT) \ + serializer.$(OBJEXT) serializerimpl.$(OBJEXT) \ + serializerutil.$(OBJEXT) serstring.$(OBJEXT) \ + srefcountobj.$(OBJEXT) srefcounttbl.$(OBJEXT) \ + stdcore.$(OBJEXT) stringutil.$(OBJEXT) timebomb.$(OBJEXT) \ + timeconvert.$(OBJEXT) tw_signal.$(OBJEXT) twlimits.$(OBJEXT) \ + twlocale.$(OBJEXT) unixexcept.$(OBJEXT) usernotify.$(OBJEXT) \ + usernotifystdout.$(OBJEXT) wchar16.$(OBJEXT) libcore_a_OBJECTS = $(am_libcore_a_OBJECTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -339,11 +338,11 @@ libcore_a_SOURCES = \ displayutil.cpp error.cpp errorbucketimpl.cpp errortable.cpp \ errorutil.cpp fileerror.cpp fileheader.cpp fsservices.cpp \ growheap.cpp hashtable.cpp haval.cpp msystem.cpp ntmbs.cpp \ - objectpool.cpp refcountobj.cpp serializable.cpp serializer.cpp \ + refcountobj.cpp serializable.cpp serializer.cpp \ serializerimpl.cpp serializerutil.cpp serstring.cpp \ srefcountobj.cpp srefcounttbl.cpp stdcore.cpp stringutil.cpp \ timebomb.cpp timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \ - unixexcept.cpp usernotify.cpp usernotifystdout.cpp utf8.cpp \ + unixexcept.cpp usernotify.cpp usernotifystdout.cpp \ wchar16.cpp libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ @@ -351,12 +350,12 @@ libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ displayutil.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \ errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \ fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \ - ntmbs.h objectpool.h package.h platform.h refcountobj.h resources.h \ + ntmbs.h package.h platform.h refcountobj.h resources.h \ serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \ sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \ tchar.h timebomb.h timeconvert.h tw_signal.h twlimits.h twlocale.h \ twstringslang.h typed.h types.h unixexcept.h unixfsservices.h upperbound.h \ - usernotify.h usernotifystdout.h utf8.h wchar16.h + usernotify.h usernotifystdout.h wchar16.h libcore_a_LIBADD = @CORE_CRYPT_O@ libcore_a_DEPENDENCIES = @CORE_CRYPT_O@ diff --git a/src/core/archive.h b/src/core/archive.h index d70d977..7c25092 100644 --- a/src/core/archive.h +++ b/src/core/archive.h @@ -324,28 +324,5 @@ private: }; - -/* -// TODO: fill these out - -/////////////////////////////////////////////////////////////////////////////// -// class cMMFileArchive -- -/////////////////////////////////////////////////////////////////////////////// - -class cMMFileArchive : public cMemMappedArchive -{ -public: -}; - -/////////////////////////////////////////////////////////////////////////////// -// class cNetArchive -- -/////////////////////////////////////////////////////////////////////////////// - -class cNetArchive : public cArchive -{ -public: -}; -*/ - #endif diff --git a/src/core/objectpool.cpp b/src/core/objectpool.cpp deleted file mode 100644 index 86c0ba9..0000000 --- a/src/core/objectpool.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// -// The developer of the original code and/or files is Tripwire, Inc. -// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire, -// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights -// reserved. -// -// This program is free software. The contents of this file are subject -// to the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2 of the License, or (at your -// option) any later version. You may redistribute it and/or modify it -// only in compliance with the GNU General Public License. -// -// This program is distributed in the hope that it will be useful. -// However, this program is distributed AS-IS WITHOUT ANY -// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS -// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// Nothing in the GNU General Public License or any other license to use -// the code or files shall permit you to use Tripwire's trademarks, -// service marks, or other intellectual property without Tripwire's -// prior written consent. -// -// If you have any questions, please contact Tripwire, Inc. at either -// info@tripwire.org or www.tripwire.org. -// -// objectpool.cpp -#include "stdcore.h" -#include "objectpool.h" -#include "debug.h" - -//----------------------------------------------------------------------------- -// cBlockLink -//----------------------------------------------------------------------------- -class cBlockLink -{ -public: - cBlockLink(cBlockLink* pNext) : mpNext(pNext) {} - cBlockLink* Next() { return mpNext; } -private: - cBlockLink* mpNext; // pointer to the next link, or NULL -}; - - -//----------------------------------------------------------------------------- -// cBlockList -//----------------------------------------------------------------------------- - -/////////////////////////////////////////////////////////////////////////////// -// ctor, dtor -/////////////////////////////////////////////////////////////////////////////// -cBlockList::cBlockList() : - mpBlocks(0) -{ -} - -cBlockList::~cBlockList() -{ - Clear(); -} - -/////////////////////////////////////////////////////////////////////////////// -// Allocate -/////////////////////////////////////////////////////////////////////////////// -void* cBlockList::Allocate(int size) -{ - char* mem = new char[size + sizeof(cBlockLink)]; - mpBlocks = new(mem) cBlockLink(mpBlocks); - return mem + sizeof(cBlockLink); -} - -/////////////////////////////////////////////////////////////////////////////// -// Clear -/////////////////////////////////////////////////////////////////////////////// -void cBlockList::Clear() -{ - while(mpBlocks) - { - cBlockLink* pLink = mpBlocks; - mpBlocks = mpBlocks->Next(); - pLink->~cBlockLink(); - delete [] (char*)(pLink); - } -} - -//----------------------------------------------------------------------------- -// cObjectPoolBase -//----------------------------------------------------------------------------- - -/////////////////////////////////////////////////////////////////////////////// -// ctor, dtor -/////////////////////////////////////////////////////////////////////////////// -cObjectPoolBase::cObjectPoolBase(int objSize, int chunkSize) : - mObjectSize(objSize), - mChunkSize(chunkSize), - mpNextFree(0) -{ -} - -cObjectPoolBase::~cObjectPoolBase() -{ - //TODO -- assert that the number of instances left are 0. - Clear(); -} - -/////////////////////////////////////////////////////////////////////////////// -// AllocNewChunk -/////////////////////////////////////////////////////////////////////////////// -void cObjectPoolBase::AllocNewChunk() -{ - ASSERT(mpNextFree == 0); - - int size = mObjectSize * mChunkSize; - char* pBlock = (char*)mBlockList.Allocate(size); - - char* pLast = pBlock + size - mObjectSize; - for(char* pc = pBlock; pc < pLast; pc += mObjectSize) - { - ((cLink*)pc)->mpNext = (cLink*)(pc + mObjectSize); - } - ((cLink*)pLast)->mpNext = 0; - - mpNextFree = (cLink*)pBlock; -} - - diff --git a/src/core/objectpool.h b/src/core/objectpool.h deleted file mode 100644 index 6877b34..0000000 --- a/src/core/objectpool.h +++ /dev/null @@ -1,140 +0,0 @@ -// -// The developer of the original code and/or files is Tripwire, Inc. -// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire, -// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights -// reserved. -// -// This program is free software. The contents of this file are subject -// to the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2 of the License, or (at your -// option) any later version. You may redistribute it and/or modify it -// only in compliance with the GNU General Public License. -// -// This program is distributed in the hope that it will be useful. -// However, this program is distributed AS-IS WITHOUT ANY -// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS -// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// Nothing in the GNU General Public License or any other license to use -// the code or files shall permit you to use Tripwire's trademarks, -// service marks, or other intellectual property without Tripwire's -// prior written consent. -// -// If you have any questions, please contact Tripwire, Inc. at either -// info@tripwire.org or www.tripwire.org. -// -/////////////////////////////////////////////////////////////////////////////// -// objectpool.h -// -// cBlockList -- a linked list of blocks of memory -// cObjectPoolBase -- a pool of equal-sized objects; constant time allocation -#ifndef __OBJECTPOOL_H -#define __OBJECTPOOL_H - -class cBlockLink; - -//----------------------------------------------------------------------------- -// cBlockList -//----------------------------------------------------------------------------- -class cBlockList -{ -public: - cBlockList(); - ~cBlockList(); - - void* Allocate(int size); - void Clear(); // releases everything in the block list -private: - cBlockLink* mpBlocks; // linked list of blocks -}; - -//----------------------------------------------------------------------------- -// cObjectPoolBase -//----------------------------------------------------------------------------- -class cObjectPoolBase -{ -public: - cObjectPoolBase(int objSize, int chunkSize); - ~cObjectPoolBase(); - // NOTE -- dtor is not virtual; therefore it is potentially dangerous to delete a pointer to - // this class unless you know for sure the dynamic class type has nothing to clean up. - - void* Alloc (); - void Free (void* pObj); - void Clear (); - //TODO -- add IsPointerValid() -private: - void AllocNewChunk(); // get another chunk to use... - - struct cLink - { - cLink* mpNext; - }; - - cBlockList mBlockList; - const int mObjectSize; // how big are the objects? - const int mChunkSize; // how big are the chunks we are allocating? - cLink* mpNextFree; // the next free object - //int mInstanceCount; // number of objects that are currently allocated but not freed. -}; - -//----------------------------------------------------------------------------- -// cObjectPool -// Note -- this template only works for classes that are constructed with their -// default ctor; I don't know how to extend this model to work for non-default -// ctors... -//----------------------------------------------------------------------------- -template -class cObjectPool : public cObjectPoolBase -{ -public: - cObjectPool(int chunkSize) : cObjectPoolBase(sizeof(T), chunkSize) {} - - T* New () { return new(cObjectPoolBase::Alloc()) T(); } - void Delete (T* pObj) { pObj->~T(); Free(pObj); } -}; - -//############################################################################# -// inline implementation -//############################################################################# -/////////////////////////////////////////////////////////////////////////////// -// Alloc -/////////////////////////////////////////////////////////////////////////////// -inline void* cObjectPoolBase::Alloc() -{ - if(! mpNextFree) - AllocNewChunk(); - - cLink* pRtn = mpNextFree; - mpNextFree = mpNextFree->mpNext; - return pRtn; -} - -/////////////////////////////////////////////////////////////////////////////// -// Free -/////////////////////////////////////////////////////////////////////////////// -inline void cObjectPoolBase::Free(void* pObj) -{ - cLink* pNew = (cLink*)pObj; - pNew->mpNext = mpNextFree; - mpNextFree = pNew; -} - -/////////////////////////////////////////////////////////////////////////////// -// Clear -/////////////////////////////////////////////////////////////////////////////// -inline void cObjectPoolBase::Clear() -{ - mBlockList.Clear(); - mpNextFree = 0; -} - - -#endif //__OBJECTPOOL_H - diff --git a/src/core/utf8.cpp b/src/core/utf8.cpp deleted file mode 100644 index 1070882..0000000 --- a/src/core/utf8.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// -// The developer of the original code and/or files is Tripwire, Inc. -// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire, -// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights -// reserved. -// -// This program is free software. The contents of this file are subject -// to the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2 of the License, or (at your -// option) any later version. You may redistribute it and/or modify it -// only in compliance with the GNU General Public License. -// -// This program is distributed in the hope that it will be useful. -// However, this program is distributed AS-IS WITHOUT ANY -// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS -// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// Nothing in the GNU General Public License or any other license to use -// the code or files shall permit you to use Tripwire's trademarks, -// service marks, or other intellectual property without Tripwire's -// prior written consent. -// -// If you have any questions, please contact Tripwire, Inc. at either -// info@tripwire.org or www.tripwire.org. -// -/////////////////////////////////////////////////////////////////////////////// -// utf8.h -// -#include "stdcore.h" -#include "utf8.h" // Required Deps -#include "tchar.h" -//#include "integ/tss.integ.strings.h" -//#include "integ/tss.integ.strings.inl" - -#ifdef _UNICODE - - -//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// CLASS UTF8: Member Definitions -//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// NOTES: utf8 uses "lazy evaluation" so that members are only allocated -// if they are used. However, once they are evaluated, the evaluation results -// will be saved so that values may henceforth simply be returned. This -// scheme gives the best time vs. space performance possible as the complexity -// of each operation is at most, linear. - - -const char* cUTF8::str() const THROW(std::bad_alloc) // UTF8: Get as Narrow UTF8 -{ - if ( mUTF8Str == 0 ) // If mUTF8Str is NULL mUnicodeStr can't be - mUTF8Str = cUTF8::allocate( mUnicodeStr ); - - return mUTF8Str; -} - -const wchar_t* cUTF8::ustr() const THROW(std::bad_alloc) // UTF8: Get as UNICODE NTWCS -{ - if ( mUnicodeStr == 0 ) - mUnicodeStr = cUTF8::allocate( mUTF8Str ); // If mUnicodeStr is NULL mUTF8WideStr can't be - - return mUnicodeStr; -} - -const wchar_t* cUTF8::wstr() const THROW(std::bad_alloc) // UTF8: Get as Wide UTF8 -{ - if ( mUTF8WideStr == 0 ) - { - size_t N = ::strlen( str() ); // WARNING: Get strlen NOT mbcslen!!! - mUTF8WideStr = new wchar_t[ N + 1 ]; // This may throw bad_alloc to client - - for ( size_t n = 0; n < N; n++ ) // index ordinal, not pointer - mUTF8WideStr[n] = wchar_t( BYTE(mUTF8Str[n]) ); // WARNING: First convert to "unsigned char" - - mUTF8WideStr[N] = 0; // add a final NULL - } - - return mUTF8WideStr; -} - - -/// UTF8: UTF8-Unicode Round-trip Conversions - -wchar_t* cUTF8::allocate( const char* in ) THROW( std::bad_alloc ) -{ - ASSERT( in /* && TSS_IsValidString( in )*/ ); // Verify Input - - size_t N = ::MultiByteToWideChar( CP_UTF8, 0, in, -1, 0, 0 ); - wchar_t* out = new wchar_t[ N + 1 ]; // Allocate required size - - - //--Convert - - out[0] = 0x00; // NOTE: Just in case we fail - #ifdef _DEBUG - //size_t nWritten = - #endif - ::MultiByteToWideChar( CP_UTF8, 0, in, -1, out, N ); - out[N] = 0; - -#ifdef _INTEG2 // Verify Output - if ( nWritten == 0 ) - { - cDebug d( "cUTF8::allocate" ); - d.TraceError( "MultiByteToWideChar failed with %x\n", ::GetLastError() ); - } - - ASSERT( out && TSS_IsValidString( out, nWritten ) ); -#endif - - return out; -} - -char* cUTF8::allocate( const wchar_t* in ) THROW( std::bad_alloc ) -{ - ASSERT( in /*&& TSS_IsValidString( in ) */); // Verify Input - - // Allocate required size - size_t N = ::WideCharToMultiByte( CP_UTF8, 0, in, -1,0,0,0,0 ); - char* out = new char[ N + 1 ]; - - - //--Convert - - out[0] = 0x00; // NOTE: Just in case we fail - #ifdef _DEBUG - //size_t nWritten = - #endif - ::WideCharToMultiByte( CP_UTF8, 0, in, -1, out, N, 0, 0 ); - out[N] = 0; - -#ifdef _INTEG2 // Verify Output - if ( nWritten == 0 ) - { - cDebug d( "cUTF8::allocate" ); - d.TraceError( "WideCharToMultiByte failed with %x\n", ::GetLastError() ); - } - - ASSERT( out /*&& TSS_IsValidString( out, nWritten ) */); -#endif - - return out; -} - -#endif //_UNICODE - diff --git a/src/core/utf8.h b/src/core/utf8.h deleted file mode 100644 index da772d7..0000000 --- a/src/core/utf8.h +++ /dev/null @@ -1,187 +0,0 @@ -// -// The developer of the original code and/or files is Tripwire, Inc. -// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire, -// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights -// reserved. -// -// This program is free software. The contents of this file are subject -// to the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2 of the License, or (at your -// option) any later version. You may redistribute it and/or modify it -// only in compliance with the GNU General Public License. -// -// This program is distributed in the hope that it will be useful. -// However, this program is distributed AS-IS WITHOUT ANY -// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS -// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// Nothing in the GNU General Public License or any other license to use -// the code or files shall permit you to use Tripwire's trademarks, -// service marks, or other intellectual property without Tripwire's -// prior written consent. -// -// If you have any questions, please contact Tripwire, Inc. at either -// info@tripwire.org or www.tripwire.org. -// -/////////////////////////////////////////////////////////////////////////////// -// utf8.h -// - -// UTF8 is used to map UNICODE characters to NTBS targets -// that would normally not be able to dealt with. UTF8 -// ensures symetrical round-trip conversions. In other -// words an unmapable UNICODE character converted to UTF8 -// will always convert back to the same UNICODE value. -// -// For more information, go to: -// mk:@MSITStore:\\SQUID\MSDN%20January%201999\MSDN\kbwindev.chm::/Source/win32sdk/q175392.htm - -#ifndef __UTF8_H -#define __UTF8_H - -#include // operator<< - -//#ifndef __TSS_INTEG_STRINGS_H -//#include "integ/tss.integ.strings.h" // IsValidAddress and IsValidString -//#endif -#ifndef __DEBUG_H -#include "debug.h" -#endif - -//----------------------------------------------------------------------------- -// convenience macros -// -// use these when printing a string ( TCHAR* ) to stdout, stderr, of printf-style -// function to safely convert the string to something printable -//----------------------------------------------------------------------------- -#ifdef _UNICODE -# define TSS_UTF8( x ) cUTF8( x ).wstr() -#else -# define TSS_UTF8( x ) x -#endif - -#ifdef _UNICODE // this class is only needed in unicode builds... - -//----------------------------------------------------------------------------- -// Entities Declared in this Module -//----------------------------------------------------------------------------- - -class cUTF8; - -std::ostream& operator<<( std::ostream&, const cUTF8& ); -std::wostream& operator<<( std::wostream&, const cUTF8& ); - - -/// Class Declaration - -#ifdef _THROW_SUPPORTED -#define THROW( x ) throw( x ) -#define THROW_0 throw() -#else -#define THROW( x ) -#define THROW_0 -#endif - -//============================================================================= -// class cUTF8: Encapsulate UTF8 Encoding -// -// SYNOPSIS: -// Allows unmappable UNICODE characters to be embedded into Narrow strings -// and displayable by narrow display streams. -// -// CONSTRAINTS: -// Cannot default or copy construct or assign UTF8 instances. Each UTF8 -// instance is an exclusive owner of its resources for its life-time. -// This cuts down on the amount of redundant allocation and copying that -// is required by the class. -//============================================================================= - -class cUTF8 -{ - /// Interface. - - public: - - cUTF8( const char* ) THROW( std::bad_alloc ); - cUTF8( const wchar_t* ) THROW( std::bad_alloc ); - ~cUTF8(); - - const char* str() const THROW( std::bad_alloc ); // Narrow UTF8 - const wchar_t* wstr() const THROW( std::bad_alloc ); // Wide UTF8 - const wchar_t* ustr() const THROW( std::bad_alloc ); // Unicode - - - /// Implementation. - - protected: - - static char* allocate( const wchar_t* ) THROW( std::bad_alloc ); - static wchar_t* allocate( const char* ) THROW( std::bad_alloc ); - - protected: - - cUTF8( const cUTF8& ); // Disallow - cUTF8& operator=( const cUTF8& ); // Disallow - - private: - - mutable wchar_t* mUnicodeStr; // UNICODE String - mutable char* mUTF8Str; // UTF8 Bytes String - mutable wchar_t* mUTF8WideStr; // UTF8 Wide Character String -}; - -//----------------------------------------------------------------------------- -// UTF8 Inlines: Members and Global Binary Non-Member Operators -//----------------------------------------------------------------------------- - -// Create from NTBS UTF8 -inline cUTF8::cUTF8( const char* psz ) THROW( std::bad_alloc ) -: mUnicodeStr( cUTF8::allocate( psz ) ), - mUTF8Str( 0 ), - mUTF8WideStr( 0 ) -{ - ASSERT( mUnicodeStr || mUTF8Str ); -} - -// Create from NTWCS UNICODE -inline cUTF8::cUTF8( const wchar_t* wsz ) THROW( std::bad_alloc ) -: mUnicodeStr( 0 ), - mUTF8Str( cUTF8::allocate( wsz ) ), - mUTF8WideStr( 0 ) -{ - ASSERT( mUnicodeStr || mUTF8Str ); -} - -inline cUTF8::~cUTF8() -{ - delete [] mUnicodeStr; // Delete UNICODE (if exists) - delete [] mUTF8Str; // Delete UTF8 (NTBS) - delete [] mUTF8WideStr; // Delete UTF8 (NTWCS) -} - - -/// Operators - -inline std::ostream& operator<<( std::ostream& out, const cUTF8& str ) -{ - out << str.str(); - return out; -} - -inline std::wostream& operator<<( std::wostream& wout, const cUTF8& str ) -{ - wout << str.wstr(); // CAUTION: Don't send UNICODE string, it won't display! - return wout; -} - - -#endif //_UNICODE - -#endif/*_TSS_UTF8_H*/ - diff --git a/src/fco/fconametbl.cpp b/src/fco/fconametbl.cpp index 9eaa605..c4e2ba8 100644 --- a/src/fco/fconametbl.cpp +++ b/src/fco/fconametbl.cpp @@ -39,8 +39,6 @@ //############################################################################# // cFCONameTblNode //############################################################################# -// uncomment this to allocate fconametblnodes from a pool. -//cObjectPoolBase cFCONameTblNode::msAllocator(sizeof(cFCONameTblNode), 1000); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/src/fco/fconametbl.h b/src/fco/fconametbl.h index 9e7d71a..a1bbfff 100644 --- a/src/fco/fconametbl.h +++ b/src/fco/fconametbl.h @@ -46,15 +46,6 @@ #include "core/hashtable.h" #endif -// uncomment this to allocate fconametblnodes from a pool. -/* -#ifndef __OBJECTPOOL_H -#include "objectpool.h" -#endif -*/ -// end TODO - - class cFCONameTbl_i; /////////////////////////////////////////////////////////////////////////////// diff --git a/src/fs/fsobject.cpp b/src/fs/fsobject.cpp index 2d2dabb..c811d77 100644 --- a/src/fs/fsobject.cpp +++ b/src/fs/fsobject.cpp @@ -41,9 +41,6 @@ #include "core/error.h" #include "core/errorutil.h" -//uncomment to allocate fsobjects from a pool -//cObjectPoolBase cFSObject::msAllocator(sizeof(cFSObject), 1000); - // FCO Type information... IMPLEMENT_SERREFCOUNT(cFSObject, _T("FSObject"), 0, 1) diff --git a/src/twtest/Makefile.am b/src/twtest/Makefile.am index b0d9824..4361ccb 100644 --- a/src/twtest/Makefile.am +++ b/src/twtest/Makefile.am @@ -55,7 +55,6 @@ growheap_t.cpp \ hashtable_t.cpp \ hierdatabase_t.cpp \ keyfile_t.cpp \ -objectpool_t.cpp \ platform_t.cpp \ policyparser_t.cpp \ refcountobj_t.cpp \ diff --git a/src/twtest/Makefile.in b/src/twtest/Makefile.in index 69befaf..cea3ef0 100644 --- a/src/twtest/Makefile.in +++ b/src/twtest/Makefile.in @@ -126,14 +126,14 @@ am_twtest_OBJECTS = archive_t.$(OBJEXT) blockfile_t.$(OBJEXT) \ genrespeclist_t.$(OBJEXT) genreswitcher_t.$(OBJEXT) \ growheap_t.$(OBJEXT) hashtable_t.$(OBJEXT) \ hierdatabase_t.$(OBJEXT) keyfile_t.$(OBJEXT) \ - objectpool_t.$(OBJEXT) platform_t.$(OBJEXT) \ - policyparser_t.$(OBJEXT) refcountobj_t.$(OBJEXT) \ - resources_t.$(OBJEXT) serializer_t.$(OBJEXT) \ - serializerimpl_t.$(OBJEXT) signature_t.$(OBJEXT) \ - srefcountobj_t.$(OBJEXT) stdtest.$(OBJEXT) \ - stringencoder_t.$(OBJEXT) tasktimer_t.$(OBJEXT) \ - tchar_t.$(OBJEXT) test.$(OBJEXT) textreportviewer_t.$(OBJEXT) \ - twlocale_t.$(OBJEXT) twutil_t.$(OBJEXT) types_t.$(OBJEXT) \ + platform_t.$(OBJEXT) policyparser_t.$(OBJEXT) \ + refcountobj_t.$(OBJEXT) resources_t.$(OBJEXT) \ + serializer_t.$(OBJEXT) serializerimpl_t.$(OBJEXT) \ + signature_t.$(OBJEXT) srefcountobj_t.$(OBJEXT) \ + stdtest.$(OBJEXT) stringencoder_t.$(OBJEXT) \ + tasktimer_t.$(OBJEXT) tchar_t.$(OBJEXT) test.$(OBJEXT) \ + textreportviewer_t.$(OBJEXT) twlocale_t.$(OBJEXT) \ + twutil_t.$(OBJEXT) types_t.$(OBJEXT) \ unixfsservices_t.$(OBJEXT) usernotifystdout_t.$(OBJEXT) \ wchar16_t.$(OBJEXT) twtest_OBJECTS = $(am_twtest_OBJECTS) @@ -397,7 +397,6 @@ growheap_t.cpp \ hashtable_t.cpp \ hierdatabase_t.cpp \ keyfile_t.cpp \ -objectpool_t.cpp \ platform_t.cpp \ policyparser_t.cpp \ refcountobj_t.cpp \ diff --git a/src/twtest/objectpool_t.cpp b/src/twtest/objectpool_t.cpp deleted file mode 100644 index b29225e..0000000 --- a/src/twtest/objectpool_t.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// -// The developer of the original code and/or files is Tripwire, Inc. -// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire, -// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights -// reserved. -// -// This program is free software. The contents of this file are subject -// to the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2 of the License, or (at your -// option) any later version. You may redistribute it and/or modify it -// only in compliance with the GNU General Public License. -// -// This program is distributed in the hope that it will be useful. -// However, this program is distributed AS-IS WITHOUT ANY -// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS -// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// Nothing in the GNU General Public License or any other license to use -// the code or files shall permit you to use Tripwire's trademarks, -// service marks, or other intellectual property without Tripwire's -// prior written consent. -// -// If you have any questions, please contact Tripwire, Inc. at either -// info@tripwire.org or www.tripwire.org. -// -/////////////////////////////////////////////////////////////////////////////// -// objectpool_t - -#include "core/stdcore.h" -#include "core/objectpool.h" -#include "core/debug.h" -#include "twtest/test.h" - - -// this is the struct we will use for testing purposes -struct cDog -{ - int i; - char c; - double d; - cDog() : i(53), c('f'), d(3.14) { cDebug d("cDog::cDog"); d.TraceDebug("Dog ctor...\n"); } - ~cDog() { cDebug d("cDog::~cDog"); d.TraceDebug("Dog dtor...\n"); } -}; - - -void TestObjectPool() -{ - int k, j; - cDebug d("TestObjectPool"); - - // first, just try the growing properties of the pool - cObjectPoolBase pool(10, 5); - d.TraceDebug("object size = 10, chunk size = 5\n"); - for(k=0; k < 12; k++) - { - d.TraceDebug("Allocating...\n"); - pool.Alloc(); - } - d.TraceDebug("Removing everything...\n"); - pool.Clear(); - - // test the template class - cObjectPool dogPool(3); - std::list lDog; - for(j=0; j < 7; j++) - { - lDog.push_back(dogPool.New()); - } - - std::list::iterator i; - for( i = lDog.begin(); i != lDog.end(); i++) - { - d.TraceDebug("dog contents: %d %c %lf\n", (*i)->i, (*i)->c, (*i)->d); - dogPool.Delete(*i); - } - lDog.clear(); - - // now, do some random insertions and deletions... - std::vector vAlloced; - for(k=0; k < 1000; k++) - { - if(rand() % 3 > 0 ) - { - // alloc - void* pNew = pool.Alloc(); - d.TraceDebug("Allocating %p\n", pNew); - vAlloced.push_back(pNew); - } - else - { - // free - int randval = rand(); - int vsize = vAlloced.size(); - if (vsize) - { - int idx = randval % vsize; - std::vector::iterator vi = vAlloced.begin() + idx; - void* pGone = *vi; - d.TraceDebug("Removing %p\n", pGone); - pool.Free(pGone); - vAlloced.erase(vi); - } - } - } - - d.TraceDebug("Leaving...\n"); -} - diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index 88db4f0..7cec46e 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -114,7 +114,7 @@ void TestCryptoArchive(); void TestFCOSpecAttr(); void TestCmdLineParser(); void TestTaskTimer(); -void TestObjectPool(); +//void TestObjectPool(); void TestKeyFile(); void TestFCOSetCached(); void TestTWUtil(); @@ -188,7 +188,7 @@ static void Test(int testID) //case 27: TestFSPropCalc(); break; case 28: TestFCOSpecImpl(); break; case 29: TestHashTable(); break; - case 30: TestObjectPool(); break; +// case 30: TestObjectPool(); break; case 31: TestRefCountObj(); break; case 32: TestSerializerImpl(); break; case 33: TestSerRefCountObj(); break; From b1147d65cf1a19697cace0828182d927c8239b04 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 15 Mar 2017 21:44:54 -0700 Subject: [PATCH 12/43] Add sanity check in cFCODataSourceIterImpl::SeekToFCO() to fix a unit test that fails on some platforms --- src/fco/fcodatasourceiterimpl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fco/fcodatasourceiterimpl.cpp b/src/fco/fcodatasourceiterimpl.cpp index 709c881..9f7cb88 100644 --- a/src/fco/fcodatasourceiterimpl.cpp +++ b/src/fco/fcodatasourceiterimpl.cpp @@ -265,7 +265,8 @@ void cFCODataSourceIterImpl::SeekToFCO(const cFCOName& name, bool bCreatePeers) GeneratePeers(); } - SeekToPeerByName( (*mCurPos)->GetName().GetShortName() ); + if(mCurPos != mPeers.end() && *mCurPos) + SeekToPeerByName( (*mCurPos)->GetName().GetShortName() ); } /////////////////////////////////////////////////////////////////////////////// From 8bd86fe60da2e0b6a2f77217a878d99f19e78512 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 15 Mar 2017 23:41:23 -0700 Subject: [PATCH 13/43] Address more cppcheck warnings, mostly around assignment operators & explicit constructors --- .gitignore | 1 + src/db/hierdatabase.cpp | 2 +- src/db/hierdatabase.h | 2 +- src/db/hierdbnode.h | 2 +- src/fco/fcocompare.h | 2 +- src/fco/fcodatasourceiterimpl.cpp | 2 +- src/fco/fconame.cpp | 10 +++++++--- src/fco/fconame.h | 10 +++++----- src/fco/fconametbl.h | 2 +- src/fco/fcopropvector.cpp | 6 ++---- src/fco/fcopropvector.h | 2 +- src/fco/fcosetimpl.cpp | 4 +++- src/fco/fcosetimpl.h | 11 ++++++----- src/fco/fcospecattr.h | 2 +- src/fco/fcospechelper.h | 2 +- src/fco/fcospecimpl.cpp | 4 +++- src/fco/fcospecimpl.h | 2 +- src/fco/fcospeclist.h | 4 ++-- src/fco/iterproxy.h | 1 + src/fs/fsobject.h | 2 +- src/tripwire/mailmessage.h | 2 +- src/tripwire/pipedmailmessage.cpp | 2 +- src/tw/configfile.h | 2 +- src/tw/dbdebug.h | 2 +- src/tw/fcodatabasefile.h | 4 ++-- src/tw/fcoreport.cpp | 12 +++++++++--- src/tw/fcoreport.h | 10 +++++----- src/tw/filemanipulator.h | 2 +- src/tw/textreportviewer.h | 4 +++- src/tw/twutil.cpp | 4 ++-- src/tw/twutil.h | 4 ++-- src/twcrypto/bytequeue.cpp | 2 +- src/twcrypto/bytequeue.h | 2 +- src/twcrypto/crypto.h | 28 ++++++++++++++-------------- src/twparser/parserobjects.h | 2 +- src/twparser/policyparser.h | 4 ++-- 36 files changed, 88 insertions(+), 71 deletions(-) diff --git a/.gitignore b/.gitignore index 4854d05..9e8c92b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ src/tripwire/tripwire src/twadmin/twadmin src/twprint/twprint src/twtest/twtest +src/test-harness/twtest **/Makefile **/*.o **/*.dylib diff --git a/src/db/hierdatabase.cpp b/src/db/hierdatabase.cpp index 2a88614..b4fd831 100644 --- a/src/db/hierdatabase.cpp +++ b/src/db/hierdatabase.cpp @@ -751,7 +751,7 @@ bool cHierDatabaseIter::CompareForUpperBound( const cHierEntry& he, const TCHAR* class cHierDatabaseIterCallCompare { public: - cHierDatabaseIterCallCompare( const cHierDatabaseIter* pcls ) + explicit cHierDatabaseIterCallCompare( const cHierDatabaseIter* pcls ) : pc( pcls ) {}; bool operator()( const cHierEntry& a1, const TCHAR* a2 ) diff --git a/src/db/hierdatabase.h b/src/db/hierdatabase.h index 54d335f..1e3c173 100644 --- a/src/db/hierdatabase.h +++ b/src/db/hierdatabase.h @@ -114,7 +114,7 @@ private: class cHierDatabaseIter { public: - cHierDatabaseIter( cHierDatabase* pDb ); //throw (eArchive) + explicit cHierDatabaseIter( cHierDatabase* pDb ); //throw (eArchive) ~cHierDatabaseIter(); // diff --git a/src/db/hierdbnode.h b/src/db/hierdbnode.h index 560344e..148df88 100644 --- a/src/db/hierdbnode.h +++ b/src/db/hierdbnode.h @@ -68,7 +68,7 @@ public: }; - cHierNode( Type type = TYPE_INVALID ) : mType( type ) {} + explicit cHierNode( Type type = TYPE_INVALID ) : mType( type ) {} virtual ~cHierNode() {} int32 mType; diff --git a/src/fco/fcocompare.h b/src/fco/fcocompare.h index b7a6175..2343286 100644 --- a/src/fco/fcocompare.h +++ b/src/fco/fcocompare.h @@ -53,7 +53,7 @@ public: }; cFCOCompare(); - cFCOCompare( const cFCOPropVector& propsToCompare); + explicit cFCOCompare( const cFCOPropVector& propsToCompare); virtual ~cFCOCompare(); void SetPropsToCmp(const cFCOPropVector& pv); diff --git a/src/fco/fcodatasourceiterimpl.cpp b/src/fco/fcodatasourceiterimpl.cpp index 9f7cb88..c906188 100644 --- a/src/fco/fcodatasourceiterimpl.cpp +++ b/src/fco/fcodatasourceiterimpl.cpp @@ -440,7 +440,7 @@ bool cFCODataSourceIterImpl::CompareForUpperBound( const iFCO* pFCO, const TCHAR class cFCODataSourceIterImplCallCompare { public: - cFCODataSourceIterImplCallCompare( const cFCODataSourceIterImpl* pcls ) + explicit cFCODataSourceIterImplCallCompare( const cFCODataSourceIterImpl* pcls ) : pc( pcls ) {}; bool operator()( const iFCO* a1, const TCHAR* a2 ) diff --git a/src/fco/fconame.cpp b/src/fco/fconame.cpp index bc5ecaa..b3428d5 100644 --- a/src/fco/fconame.cpp +++ b/src/fco/fconame.cpp @@ -177,7 +177,7 @@ void cFCOName::SetNameInfo(iFCONameInfo* pNI) /////////////////////////////////////////////////////////////////////////////// // operator= /////////////////////////////////////////////////////////////////////////////// -void cFCOName::operator = (const cFCOName& rhs) +cFCOName& cFCOName::operator = (const cFCOName& rhs) { mpPathName->Release(); // TODO -- I am sure this won't work (const-ness) @@ -188,16 +188,19 @@ void cFCOName::operator = (const cFCOName& rhs) #ifdef _DEBUG mDebugStrName = AsString(); #endif + return *this; } -void cFCOName::operator = (const TSTRING& rhs) + +cFCOName& cFCOName::operator = (const TSTRING& rhs) { *this = rhs.c_str(); #ifdef _DEBUG mDebugStrName = AsString(); #endif + return *this; } -void cFCOName::operator = (const TCHAR* rhs) +cFCOName& cFCOName::operator = (const TCHAR* rhs) { // if I have the only handle on this vector, I can reuse it // otherwise, I have to release it. @@ -210,6 +213,7 @@ void cFCOName::operator = (const TCHAR* rhs) #ifdef _DEBUG mDebugStrName = AsString(); #endif + return *this; } void cFCOName::ParseString( const TCHAR* pszin ) diff --git a/src/fco/fconame.h b/src/fco/fconame.h index 0c6f05c..daccab0 100644 --- a/src/fco/fconame.h +++ b/src/fco/fconame.h @@ -58,7 +58,7 @@ class cFCOName : public iTypedSerializable public: typedef cFCONameIter iterator; - cFCOName(iFCONameInfo* iNI = NULL); + explicit cFCOName(iFCONameInfo* iNI = NULL); cFCOName(const cFCOName& rhs); explicit cFCOName(const TSTRING& rhs, iFCONameInfo* iNI = NULL); @@ -67,9 +67,9 @@ public: // do it unexpectedly virtual ~cFCOName(); - void operator = (const cFCOName& rhs); - void operator = (const TSTRING& rhs); - void operator = (const TCHAR* rhs); + cFCOName& operator = (const cFCOName& rhs); + cFCOName& operator = (const TSTRING& rhs); + cFCOName& operator = (const TCHAR* rhs); bool operator < (const cFCOName& rhs) const; // defines an arbitrary order for cFCONames. This is so that names can @@ -165,7 +165,7 @@ class cFCONameIter_i; class cFCONameIter { public: - cFCONameIter(const cFCOName& name); + explicit cFCONameIter(const cFCOName& name); ~cFCONameIter(); int GetSize() const; // returns the number of entries in the fco name diff --git a/src/fco/fconametbl.h b/src/fco/fconametbl.h index a1bbfff..16e2301 100644 --- a/src/fco/fconametbl.h +++ b/src/fco/fconametbl.h @@ -110,7 +110,7 @@ private: class cFCONameTbl { public: - cFCONameTbl(int defSize = HASH_VERY_LARGE); + explicit cFCONameTbl(int defSize = HASH_VERY_LARGE); // defSize is the initial hash table size ~cFCONameTbl(); diff --git a/src/fco/fcopropvector.cpp b/src/fco/fcopropvector.cpp index 449aaff..54c1bde 100644 --- a/src/fco/fcopropvector.cpp +++ b/src/fco/fcopropvector.cpp @@ -394,7 +394,6 @@ void cFCOPropVector::Read(iSerializer* pSerializer, int32 version) if (version > 0) ThrowAndAssert(eSerializerVersionMismatch(_T("Property Vector Read"))); - int i; int32 newSize; pSerializer->ReadInt32(newSize); ASSERT(newSize > 0); @@ -409,7 +408,7 @@ void cFCOPropVector::Read(iSerializer* pSerializer, int32 version) } else { - for (i=0; i <= mSize / msBitlength; ++i) + for (int i=0; i <= mSize / msBitlength; ++i) { int32 mask; pSerializer->ReadInt32(mask); @@ -421,7 +420,6 @@ void cFCOPropVector::Read(iSerializer* pSerializer, int32 version) void cFCOPropVector::Write(iSerializer* pSerializer) const { - int i; pSerializer->WriteInt32(mSize); if (mpBuf == NULL) @@ -430,7 +428,7 @@ void cFCOPropVector::Write(iSerializer* pSerializer) const } else { - for (i=0; i <= mSize / msBitlength; ++i) + for (int i=0; i <= mSize / msBitlength; ++i) pSerializer->WriteInt32((*mpBuf)[i]); } diff --git a/src/fco/fcopropvector.h b/src/fco/fcopropvector.h index 13378e4..7e2dc51 100644 --- a/src/fco/fcopropvector.h +++ b/src/fco/fcopropvector.h @@ -49,7 +49,7 @@ class cFCOPropVector : public iSerializable // note: this is not iTypedSerializable { public: - cFCOPropVector (int size = 32); + explicit cFCOPropVector (int size = 32); cFCOPropVector (const cFCOPropVector& rhs); virtual ~cFCOPropVector (void); bool operator== (const cFCOPropVector& rhs) const; diff --git a/src/fco/fcosetimpl.cpp b/src/fco/fcosetimpl.cpp index 2324ee0..a8f27d4 100644 --- a/src/fco/fcosetimpl.cpp +++ b/src/fco/fcosetimpl.cpp @@ -80,7 +80,7 @@ cFCOSetImpl::cFCOSetImpl(const cFCOSetImpl& rhs) : iFCOSet() /////////////////////////////////////////////////////////////////////////////// // operator= /////////////////////////////////////////////////////////////////////////////// -void cFCOSetImpl::operator=(const cFCOSetImpl& rhs) +cFCOSetImpl& cFCOSetImpl::operator=(const cFCOSetImpl& rhs) { std::set::const_iterator i; for(i = rhs.mFCOSet.begin(); i != rhs.mFCOSet.end(); ++i) @@ -88,6 +88,8 @@ void cFCOSetImpl::operator=(const cFCOSetImpl& rhs) i->mpFCO->AddRef(); mFCOSet.insert(cFCONode(i->mpFCO)); } + + return *this; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/fco/fcosetimpl.h b/src/fco/fcosetimpl.h index 942ba8c..b7d3bef 100644 --- a/src/fco/fcosetimpl.h +++ b/src/fco/fcosetimpl.h @@ -56,7 +56,7 @@ public: cFCOSetImpl(); cFCOSetImpl(const cFCOSetImpl& rhs); virtual ~cFCOSetImpl(); - void operator=(const cFCOSetImpl& rhs); + cFCOSetImpl& operator=(const cFCOSetImpl& rhs); virtual const iFCOIter* Lookup(const cFCOName& name) const; virtual iFCOIter* Lookup(const cFCOName& name); @@ -85,8 +85,9 @@ private: const cFCOName* mpFCOName; cFCONode() : mpFCO(0), mpFCOName(0) {} - cFCONode(iFCO* pFCO) : mpFCO(pFCO), mpFCOName(&pFCO->GetName()) {} - cFCONode(const cFCOName& name) : mpFCO(0), mpFCOName(&name) {} + //TODO: make the iFCO* constructor explicit + cFCONode(iFCO* pFCO) : mpFCO(pFCO), mpFCOName(&pFCO->GetName()) {} + explicit cFCONode(const cFCOName& name) : mpFCO(0), mpFCOName(&name) {} cFCONode(const cFCONode& rhs) : mpFCO(rhs.mpFCO), mpFCOName(rhs.mpFCOName) {} bool operator < (const cFCONode& rhs) const { if(mpFCOName) return (*mpFCOName < *rhs.mpFCOName); else return false; } bool operator ==(const cFCONode& rhs) const { if(mpFCOName) return (*mpFCOName == *rhs.mpFCOName); else return false; } @@ -101,8 +102,8 @@ class cFCOIterImpl : public iFCOIter friend class cFCOSetImpl; public: - cFCOIterImpl(cFCOSetImpl* pSet); - cFCOIterImpl(const cFCOSetImpl* pSet); + explicit cFCOIterImpl(cFCOSetImpl* pSet); + explicit cFCOIterImpl(const cFCOSetImpl* pSet); virtual void SeekBegin() const; virtual bool Done() const; diff --git a/src/fco/fcospecattr.h b/src/fco/fcospecattr.h index 9e0cba7..b369758 100644 --- a/src/fco/fcospecattr.h +++ b/src/fco/fcospecattr.h @@ -94,7 +94,7 @@ private: class cFCOSpecAttrEmailIter { public: - cFCOSpecAttrEmailIter(const cFCOSpecAttr& attr); + explicit cFCOSpecAttrEmailIter(const cFCOSpecAttr& attr); ~cFCOSpecAttrEmailIter(); void SeekBegin() const; diff --git a/src/fco/fcospechelper.h b/src/fco/fcospechelper.h index c9f13e8..af4ef29 100644 --- a/src/fco/fcospechelper.h +++ b/src/fco/fcospechelper.h @@ -159,7 +159,7 @@ protected: class cFCOSpecStopPointIter { public: - cFCOSpecStopPointIter(cFCOSpecStopPointSet& set); + explicit cFCOSpecStopPointIter(cFCOSpecStopPointSet& set); void SeekBegin() const; // seeks to the beginning of the stop point list diff --git a/src/fco/fcospecimpl.cpp b/src/fco/fcospecimpl.cpp index 2e664e7..839e282 100644 --- a/src/fco/fcospecimpl.cpp +++ b/src/fco/fcospecimpl.cpp @@ -100,11 +100,13 @@ IMPLEMENT_SERREFCOUNT(cFCOSpecImpl, _T("cFCOSpecImpl"), 0, 1); /////////////////////////////////////////////////////////////////////////////// // operator= /////////////////////////////////////////////////////////////////////////////// -void cFCOSpecImpl::operator=(const cFCOSpecImpl& rhs) +cFCOSpecImpl& cFCOSpecImpl::operator=(const cFCOSpecImpl& rhs) { mName = rhs.mName; mPropVector = rhs.mPropVector; mpHelper = rhs.mpHelper ? rhs.mpHelper->Clone() : 0; + + return *this; } /////////////////////////////////////////////////////////////////////////////// // Clone -- make a copy of this spec diff --git a/src/fco/fcospecimpl.h b/src/fco/fcospecimpl.h index 17cd308..0bfa028 100644 --- a/src/fco/fcospecimpl.h +++ b/src/fco/fcospecimpl.h @@ -70,7 +70,7 @@ public: // the spec will delete whatever helper it contains when it is destroyed cFCOSpecImpl(const cFCOSpecImpl& rhs); cFCOSpecImpl(); - void operator=(const cFCOSpecImpl& rhs); + cFCOSpecImpl& operator=(const cFCOSpecImpl& rhs); // from iFCOSpec virtual bool SpecContainsFCO (const cFCOName& name) const; diff --git a/src/fco/fcospeclist.h b/src/fco/fcospeclist.h index a7beff2..d149c13 100644 --- a/src/fco/fcospeclist.h +++ b/src/fco/fcospeclist.h @@ -103,7 +103,7 @@ protected: class cFCOSpecListAddedIter { public: - cFCOSpecListAddedIter(const cFCOSpecList& list); + explicit cFCOSpecListAddedIter(const cFCOSpecList& list); ~cFCOSpecListAddedIter(); void SeekBegin() const; @@ -129,7 +129,7 @@ protected: class cFCOSpecListCanonicalIter { public: - cFCOSpecListCanonicalIter(const cFCOSpecList& list); + explicit cFCOSpecListCanonicalIter(const cFCOSpecList& list); ~cFCOSpecListCanonicalIter(); void SeekBegin() const; diff --git a/src/fco/iterproxy.h b/src/fco/iterproxy.h index 7743392..21fdfca 100644 --- a/src/fco/iterproxy.h +++ b/src/fco/iterproxy.h @@ -50,6 +50,7 @@ template class cIterProxy { public: + //TODO: Can these 2 constructors be made explicit? cIterProxy(TYPE* pIter = NULL) : mpIter(pIter) {}; cIterProxy(const TYPE* pIter) : mpIter((TYPE*)pIter) {}; ~cIterProxy() { if (mpIter) mpIter->DestroyIter(); } diff --git a/src/fs/fsobject.h b/src/fs/fsobject.h index eb3a09e..9121137 100644 --- a/src/fs/fsobject.h +++ b/src/fs/fsobject.h @@ -60,7 +60,7 @@ class cFSObject : public iFCO DECLARE_SERREFCOUNT() public: - cFSObject(const cFCOName& name); + explicit cFSObject(const cFCOName& name); virtual void SetName(const cFCOName& name) ; virtual const cFCOName& GetName() const ; diff --git a/src/tripwire/mailmessage.h b/src/tripwire/mailmessage.h index dfec57c..19b0617 100644 --- a/src/tripwire/mailmessage.h +++ b/src/tripwire/mailmessage.h @@ -255,7 +255,7 @@ private: class cPipedMailMessage : public cMailMessage { public: - cPipedMailMessage(TSTRING strSendMailExePath); + explicit cPipedMailMessage(const TSTRING& strSendMailExePath); virtual ~cPipedMailMessage(); virtual bool Send(); //throw(eMailMessageError) diff --git a/src/tripwire/pipedmailmessage.cpp b/src/tripwire/pipedmailmessage.cpp index 15cd432..ea81f9f 100644 --- a/src/tripwire/pipedmailmessage.cpp +++ b/src/tripwire/pipedmailmessage.cpp @@ -49,7 +49,7 @@ // // Constructor. Not much to do beside initialize the handle to the DLL // -cPipedMailMessage::cPipedMailMessage(TSTRING strSendMailExePath) +cPipedMailMessage::cPipedMailMessage(const TSTRING& strSendMailExePath) { mstrSendMailExePath = strSendMailExePath; mpFile = NULL; diff --git a/src/tw/configfile.h b/src/tw/configfile.h index b7100a4..2546a97 100644 --- a/src/tw/configfile.h +++ b/src/tw/configfile.h @@ -140,7 +140,7 @@ private: class cConfigFileIter { public: - cConfigFileIter( cConfigFile& cf); + explicit cConfigFileIter( cConfigFile& cf); virtual ~cConfigFileIter(); void SeekBegin() const; diff --git a/src/tw/dbdebug.h b/src/tw/dbdebug.h index 857630d..d90a0b6 100644 --- a/src/tw/dbdebug.h +++ b/src/tw/dbdebug.h @@ -98,7 +98,7 @@ public: // Ctor, Dtor: ~cDebugHierDbIter () {} - cDebugHierDbIter ( cHierDatabase* pDb ) : cHierDatabaseIter( pDb ) {} + explicit cDebugHierDbIter ( cHierDatabase* pDb ) : cHierDatabaseIter( pDb ) {} // // Methods for obtaining protected members of cHierDatabaseIter: diff --git a/src/tw/fcodatabasefile.h b/src/tw/fcodatabasefile.h index 907596d..875ed4b 100644 --- a/src/tw/fcodatabasefile.h +++ b/src/tw/fcodatabasefile.h @@ -112,7 +112,7 @@ public: //------------------------------------------------------------------------- struct tEntry { - tEntry( cGenre::Genre genre ); + explicit tEntry( cGenre::Genre genre ); // the ctor will get the appropriate database construction parameters // based on the genre number. ~tEntry( ) @@ -146,7 +146,7 @@ private: class cFCODatabaseFileIter { public: - cFCODatabaseFileIter( cFCODatabaseFile& dbFile ); + explicit cFCODatabaseFileIter( cFCODatabaseFile& dbFile ); void SeekBegin(); void Next(); diff --git a/src/tw/fcoreport.cpp b/src/tw/fcoreport.cpp index 79af470..4bc800d 100644 --- a/src/tw/fcoreport.cpp +++ b/src/tw/fcoreport.cpp @@ -239,10 +239,12 @@ cFCOReportGenreIter::~cFCOReportGenreIter() delete mpData; } -void cFCOReportGenreIter::operator=(const cFCOReportGenreIter& rhs) +cFCOReportGenreIter& cFCOReportGenreIter::operator=(const cFCOReportGenreIter& rhs) { mpData->mpList = rhs.mpData->mpList; mpData->mIter = rhs.mpData->mIter; + + return *this; } // iteration methods @@ -380,13 +382,15 @@ cFCOReportSpecIter::cFCOReportSpecIter(const cFCOReportSpecIter& rhs) *this = rhs; } -void cFCOReportSpecIter::operator=(const cFCOReportSpecIter& rhs) +cFCOReportSpecIter& cFCOReportSpecIter::operator=(const cFCOReportSpecIter& rhs) { if (mpData == 0) mpData = new cFCOReportSpecIter_i(); mpData->mpList = rhs.mpData->mpList; mpData->mIter = rhs.mpData->mIter; + + return *this; } int cFCOReportSpecIter::GetNumChanged() const @@ -525,10 +529,12 @@ cFCOReportChangeIter::~cFCOReportChangeIter() delete mpData; } -void cFCOReportChangeIter::operator=(const cFCOReportChangeIter& rhs) +cFCOReportChangeIter& cFCOReportChangeIter::operator=(const cFCOReportChangeIter& rhs) { mpData->mpList = rhs.mpData->mpList; mpData->mIter = rhs.mpData->mIter; + + return *this; } void cFCOReportChangeIter::SetSpecIter(const cFCOReportSpecIter& specIter) diff --git a/src/tw/fcoreport.h b/src/tw/fcoreport.h index 7da27d1..7010edf 100644 --- a/src/tw/fcoreport.h +++ b/src/tw/fcoreport.h @@ -147,7 +147,7 @@ public: cFCOReportGenreIter(const cFCOReportGenreIter& rhs); ~cFCOReportGenreIter(); - void operator=(const cFCOReportGenreIter& rhs); + cFCOReportGenreIter& operator=(const cFCOReportGenreIter& rhs); // iteration methods void SeekBegin() const; @@ -179,13 +179,13 @@ public: cFCOReportSpecIter(cFCOReport& report, cGenre::Genre genre); // if genre does not exist in the report, it will be added to the report with // and empty spec list. - cFCOReportSpecIter(const cFCOReportGenreIter& genreIter); + explicit cFCOReportSpecIter(const cFCOReportGenreIter& genreIter); // thorws eInternal if genreIter is not at a valid genre or is Done() cFCOReportSpecIter(const cFCOReportSpecIter& rhs); ~cFCOReportSpecIter(); - void operator=(const cFCOReportSpecIter& rhs); + cFCOReportSpecIter& operator=(const cFCOReportSpecIter& rhs); // iteration methods void SeekBegin() const; @@ -226,11 +226,11 @@ private: class cFCOReportChangeIter { public: - cFCOReportChangeIter(const cFCOReportSpecIter& specIter); + explicit cFCOReportChangeIter(const cFCOReportSpecIter& specIter); cFCOReportChangeIter(const cFCOReportChangeIter& rhs); ~cFCOReportChangeIter(); - void operator=(const cFCOReportChangeIter& rhs); + cFCOReportChangeIter& operator=(const cFCOReportChangeIter& rhs); void SetSpecIter(const cFCOReportSpecIter& specIter); // assocaite this iterator with a different spec. We will assert // that specIter.Done() is not true. diff --git a/src/tw/filemanipulator.h b/src/tw/filemanipulator.h index 59f53a9..bb5c893 100644 --- a/src/tw/filemanipulator.h +++ b/src/tw/filemanipulator.h @@ -91,7 +91,7 @@ TSS_FILE_EXCEPTION( eFileManipUnrecognizedFileType, eFileManip ) class cFileManipulator { public: - cFileManipulator(const TCHAR* filename); + explicit cFileManipulator(const TCHAR* filename); // throws eArchive if file does not exist cFileManipulator(const cFileManipulator& rhs); ~cFileManipulator(); diff --git a/src/tw/textreportviewer.h b/src/tw/textreportviewer.h index 6a2762d..32ad6a1 100644 --- a/src/tw/textreportviewer.h +++ b/src/tw/textreportviewer.h @@ -155,7 +155,7 @@ protected: RuleSummaryLine() : mSeverity(0), mAddedObjects(0), mRemovedObjects(0), mChangedObjects(0) {} RuleSummaryLine(const RuleSummaryLine& rhs) { *this = rhs; } - void operator = (const RuleSummaryLine& rhs) + RuleSummaryLine& operator = (const RuleSummaryLine& rhs) { mSpecName = rhs.mSpecName; mSeverity = rhs.mSeverity; @@ -163,6 +163,8 @@ protected: mRemovedObjects = rhs.mRemovedObjects; mChangedObjects = rhs.mChangedObjects; mStartPoint = rhs.mStartPoint; + + return *this; } }; diff --git a/src/tw/twutil.cpp b/src/tw/twutil.cpp index 46b9ab8..956d4d5 100644 --- a/src/tw/twutil.cpp +++ b/src/tw/twutil.cpp @@ -855,7 +855,7 @@ void cTWUtil::ReadConfigText(cArchive &arch, TSTRING& configText, cArchive* pBag // of the policy file text to disk. // Will throw eError on failure. -void cTWUtil::WritePolicyText(const TCHAR* filename, const std::string polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) +void cTWUtil::WritePolicyText(const TCHAR* filename, const std::string& polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) { cSerializableNString nstring; @@ -874,7 +874,7 @@ void cTWUtil::WritePolicyText(const TCHAR* filename, const std::string polText, cDisplayEncoder::EncodeInline( filename ).c_str() ); } -void cTWUtil::WritePolicyText(cArchive &archive, const std::string polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) +void cTWUtil::WritePolicyText(cArchive &archive, const std::string& polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) { cSerializableNString nstring; diff --git a/src/tw/twutil.h b/src/tw/twutil.h index 451f834..9c51978 100644 --- a/src/tw/twutil.h +++ b/src/tw/twutil.h @@ -122,8 +122,8 @@ public: // eSerializer is thrown if reading or writing fails // eConfigFile is thrown if config file does not parse correctly during reading - static void WritePolicyText(const TCHAR* filename, const std::string policyText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey); - static void WritePolicyText(cArchive &archive, const std::string policyText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey); + static void WritePolicyText(const TCHAR* filename, const std::string& policyText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey); + static void WritePolicyText(cArchive &archive, const std::string& policyText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey); static void ReadPolicyText(const TCHAR* filename, std::string& policyText, const cElGamalSigPublicKey* pPublicKey); static void ReadPolicyText(cArchive &archive, std::string& policyText, const cElGamalSigPublicKey* pPublicKey); // read and write policy file to and from disk diff --git a/src/twcrypto/bytequeue.cpp b/src/twcrypto/bytequeue.cpp index 9d7ade5..118f464 100644 --- a/src/twcrypto/bytequeue.cpp +++ b/src/twcrypto/bytequeue.cpp @@ -46,7 +46,7 @@ class cByteQueueNode { public: - cByteQueueNode(unsigned int maxSize); + explicit cByteQueueNode(unsigned int maxSize); unsigned int CurrentSize() const {return tail-head;} diff --git a/src/twcrypto/bytequeue.h b/src/twcrypto/bytequeue.h index e64484e..9d1511f 100644 --- a/src/twcrypto/bytequeue.h +++ b/src/twcrypto/bytequeue.h @@ -45,7 +45,7 @@ class cByteQueueNode; class cByteQueue : public BufferedTransformation { public: - cByteQueue(int nodeSize=1024); + explicit cByteQueue(int nodeSize=1024); cByteQueue(const cByteQueue ©); ~cByteQueue(); diff --git a/src/twcrypto/crypto.h b/src/twcrypto/crypto.h index 6dd5d08..ddd5d13 100644 --- a/src/twcrypto/crypto.h +++ b/src/twcrypto/crypto.h @@ -147,9 +147,9 @@ public: KEY2048 = 2048 }; - cRSA(KeySize keysize); - cRSA(const cRSAPublicKey& publicKey); // read keysize from key - cRSA(const cRSAPrivateKey& privateKey); // ditto + explicit cRSA(KeySize keysize); + explicit cRSA(const cRSAPublicKey& publicKey); // read keysize from key + explicit cRSA(const cRSAPrivateKey& privateKey); // ditto virtual ~cRSA(); void SetEncrypting(const cRSAPublicKey* pKey); @@ -183,7 +183,7 @@ class cRSAPrivateKey friend class cRSA; friend class cRSAPublicKey; public: - cRSAPrivateKey(void* pDataStream); + explicit cRSAPrivateKey(void* pDataStream); ~cRSAPrivateKey(); int GetWriteLen() const; @@ -202,8 +202,8 @@ class cRSAPublicKey { friend class cRSA; public: - cRSAPublicKey(void* pDataStream); - cRSAPublicKey(const cRSAPrivateKey& privateKey); + explicit cRSAPublicKey(void* pDataStream); + explicit cRSAPublicKey(const cRSAPrivateKey& privateKey); ~cRSAPublicKey(); int GetWriteLen() const; @@ -249,9 +249,9 @@ public: KEY2048 = 2048 }; - cElGamalSig(KeySize keysize); - cElGamalSig(const cElGamalSigPublicKey& publicKey); // read keysize from key - cElGamalSig(const cElGamalSigPrivateKey& privateKey); // ditto + explicit cElGamalSig(KeySize keysize); + explicit cElGamalSig(const cElGamalSigPublicKey& publicKey); // read keysize from key + explicit cElGamalSig(const cElGamalSigPrivateKey& privateKey); // ditto virtual ~cElGamalSig(); void SetSigning(const cElGamalSigPrivateKey* pKey); @@ -285,7 +285,7 @@ class cElGamalSigPrivateKey friend class cElGamalSig; friend class cElGamalSigPublicKey; public: - cElGamalSigPrivateKey(void* pDataStream); + explicit cElGamalSigPrivateKey(void* pDataStream); ~cElGamalSigPrivateKey(); int GetWriteLen() const; @@ -304,8 +304,8 @@ class cElGamalSigPublicKey { friend class cElGamalSig; public: - cElGamalSigPublicKey(void* pDataStream); - cElGamalSigPublicKey(const cElGamalSigPrivateKey& privateKey); + explicit cElGamalSigPublicKey(void* pDataStream); + explicit cElGamalSigPublicKey(const cElGamalSigPrivateKey& privateKey); ~cElGamalSigPublicKey(); int GetWriteLen() const; @@ -332,7 +332,7 @@ private: class cHashedKey128 { public: - cHashedKey128(const TSTRING& data); + explicit cHashedKey128(const TSTRING& data); cHashedKey128(void* pData, int dataLen); ~cHashedKey128(); @@ -368,7 +368,7 @@ inline void cHashedKey128::Write(void* pDataStream) class cHashedKey192 { public: - cHashedKey192(const TSTRING& data); + explicit cHashedKey192(const TSTRING& data); cHashedKey192(void* pData, int dataLen); ~cHashedKey192(); diff --git a/src/twparser/parserobjects.h b/src/twparser/parserobjects.h index 969beb3..3100be9 100644 --- a/src/twparser/parserobjects.h +++ b/src/twparser/parserobjects.h @@ -238,7 +238,7 @@ public: // // ctors and dtor // - cParseRule( const cParseSpecMask& defSpecMask ) :mDefSpecMask( defSpecMask ), mpAttrList(0), mpSpecMaskList(0), mName(_T("")) {} + explicit cParseRule( const cParseSpecMask& defSpecMask ) :mDefSpecMask( defSpecMask ), mpAttrList(0), mpSpecMaskList(0), mName(_T("")) {} ~cParseRule(); // diff --git a/src/twparser/policyparser.h b/src/twparser/policyparser.h index 9ef6de0..85139d1 100644 --- a/src/twparser/policyparser.h +++ b/src/twparser/policyparser.h @@ -76,7 +76,7 @@ class tw_yy_scan : public yy_scan { enum { MAX_TOKEN_LENGTH = 1024 }; public: - tw_yy_scan( std::istream& i ) : yy_scan( MAX_TOKEN_LENGTH ), mIn(i) {}; // need to increase token length over mks default + explicit tw_yy_scan( std::istream& i ) : yy_scan( MAX_TOKEN_LENGTH ), mIn(i) {}; // need to increase token length over mks default virtual int yygetc() { return mIn.get(); }; @@ -123,7 +123,7 @@ private: class cPolicyParser { public: - cPolicyParser( std::istream& in ); // input source + explicit cPolicyParser( std::istream& in ); // input source void Execute( cGenreSpecListVector& policy, cErrorBucket* pError ); //throw(eError); void Check( cErrorBucket* pError ); //throw(eError); From aaee78c061802f9b6fae92c9ceb816fd29348ed2 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 16 Mar 2017 20:51:12 -0700 Subject: [PATCH 14/43] Tweaks for 'make check': Don't assume location of perl, or existence of /etc/hosts --- Makefile.am | 2 +- Makefile.in | 2 +- src/twtest/fileutil_t.cpp | 20 +++++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Makefile.am b/Makefile.am index e72b1ee..bfcd93a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,5 +14,5 @@ uninstall-hook: check: rm -Rf $(top_srcdir)/src/test-harness/twtest - cd $(top_srcdir)/src/test-harness && ./twtest.pl + cd $(top_srcdir)/src/test-harness && perl ./twtest.pl $(top_srcdir)/bin/twtest all diff --git a/Makefile.in b/Makefile.in index 5586cce..3bb6176 100644 --- a/Makefile.in +++ b/Makefile.in @@ -810,7 +810,7 @@ uninstall-hook: check: rm -Rf $(top_srcdir)/src/test-harness/twtest - cd $(top_srcdir)/src/test-harness && ./twtest.pl + cd $(top_srcdir)/src/test-harness && perl ./twtest.pl $(top_srcdir)/bin/twtest all # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/src/twtest/fileutil_t.cpp b/src/twtest/fileutil_t.cpp index e478fc0..50a98c5 100644 --- a/src/twtest/fileutil_t.cpp +++ b/src/twtest/fileutil_t.cpp @@ -47,17 +47,15 @@ using namespace std; void TestFileUtil() { + if(cFileUtil::FileExists("/etc/hosts")) + { + TSTRING source, dest; - TSTRING source, dest; - - source = _T("/etc/hosts"); - dest = _T("/tmp/dest"); - bool blah = cFileUtil::Copy(source, dest); - (void)blah; - - -// TCOUT << _T("<") << wstr3 << _T(">") << std::endl; - - + source = _T("/etc/hosts"); + dest = _T("/tmp/dest"); + bool blah = cFileUtil::Copy(source, dest); + (void)blah; + // TCOUT << _T("<") << wstr3 << _T(">") << std::endl; + } } From 2b067176ad9ba0817e4775ef253e2188b9dd78af Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 17 Mar 2017 00:04:21 -0700 Subject: [PATCH 15/43] Fix some clang extended warnings: non-virtual-dtor, shadow, unneeded-internal-declaration --- src/core/displayencoder.cpp | 14 ++++++++++++-- src/fco/fcodatasource.h | 2 ++ src/tw/textreportviewer.cpp | 6 +++--- src/twadmin/twadmincl.cpp | 12 ++++++------ src/twcrypto/bytequeue.cpp | 4 ++-- src/twprint/twprintcmdline.cpp | 4 +--- src/twtest/hierdatabase_t.cpp | 4 ++-- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/core/displayencoder.cpp b/src/core/displayencoder.cpp index e0e1102..3b3536d 100644 --- a/src/core/displayencoder.cpp +++ b/src/core/displayencoder.cpp @@ -81,6 +81,8 @@ inline bool IsSingleTCHAR( TSTRING::const_iterator first, class iCharEncoder { public: + virtual ~iCharEncoder() {}; + virtual bool NeedsEncoding( TSTRING::const_iterator first, TSTRING::const_iterator last ) const = 0; // Determines if character identified by [first,last) needs encoding. @@ -107,7 +109,7 @@ class iCharEncoder static TCHAR EscapeChar() { return char_escape; } - protected: + protected: static TCHAR char_escape; }; @@ -116,6 +118,8 @@ class iCharEncoder class cNonNarrowableCharEncoder : public iCharEncoder { public: + virtual ~cNonNarrowableCharEncoder() {} + virtual bool NeedsEncoding( TSTRING::const_iterator first, TSTRING::const_iterator last ) const; @@ -141,7 +145,9 @@ class cNonPrintableCharEncoder : public iCharEncoder cNonPrintableCharEncoder( bool f_allowWS ) : m_allowWS( f_allowWS ) {}; - virtual bool NeedsEncoding( TSTRING::const_iterator first, + virtual ~cNonPrintableCharEncoder() {} + + virtual bool NeedsEncoding( TSTRING::const_iterator first, TSTRING::const_iterator last ) const; virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, @@ -164,6 +170,8 @@ class cNonPrintableCharEncoder : public iCharEncoder class cQuoteCharEncoder : public iCharEncoder { public: + virtual ~cQuoteCharEncoder() {} + virtual bool NeedsEncoding( TSTRING::const_iterator first, TSTRING::const_iterator last ) const; @@ -187,6 +195,8 @@ class cQuoteCharEncoder : public iCharEncoder class cBackslashCharEncoder : public iCharEncoder { public: + virtual ~cBackslashCharEncoder() {} + virtual bool NeedsEncoding( TSTRING::const_iterator first, TSTRING::const_iterator last ) const; diff --git a/src/fco/fcodatasource.h b/src/fco/fcodatasource.h index 1cbebb1..f103189 100644 --- a/src/fco/fcodatasource.h +++ b/src/fco/fcodatasource.h @@ -46,6 +46,8 @@ public: enum { CHILDREN_NONE = 0, CHILDREN_ALL = -1 }; + virtual ~iFCODataSource() = 0; + // NOTE -- in the act of creating fcos, there are certain properties that we can obtain "for free" just // by the act of querying the system we are generating fcos for (for example, a stat() call is required // to create file system fcos, which also gives us many of the fsfco's property values). Therefore, diff --git a/src/tw/textreportviewer.cpp b/src/tw/textreportviewer.cpp index 2d6986d..2824536 100644 --- a/src/tw/textreportviewer.cpp +++ b/src/tw/textreportviewer.cpp @@ -436,8 +436,8 @@ void cTextReportViewer::PrintErrors() cFCOReportSpecIter rsi( genreIter ); for( rsi.SeekBegin(); !rsi.Done(); rsi.Next() ) { - cErrorQueueIter eqIter( *( rsi.GetErrorQueue() ) ); - for( eqIter.SeekBegin(); !eqIter.Done(); eqIter.Next() ) + cErrorQueueIter eqIter2( *( rsi.GetErrorQueue() ) ); + for( eqIter2.SeekBegin(); !eqIter2.Done(); eqIter2.Next() ) { if( fFirstErrorInGenre ) { @@ -445,7 +445,7 @@ void cTextReportViewer::PrintErrors() fFirstErrorInGenre = false; } - ReportError( eqIter ); + ReportError( eqIter2 ); } } diff --git a/src/twadmin/twadmincl.cpp b/src/twadmin/twadmincl.cpp index 17db7e2..b4d1ddb 100644 --- a/src/twadmin/twadmincl.cpp +++ b/src/twadmin/twadmincl.cpp @@ -325,18 +325,18 @@ bool cTWAModeCreateCfg::Init(const cConfigFile* cf, const cCmdLineParser& parser } // get full path to files - TSTRING strFullPath; - if( iFSServices::GetInstance()->FullPath( strFullPath, mPlaintextConfig ) ) - mPlaintextConfig = strFullPath; + TSTRING strPlaintextConfigPath; + if( iFSServices::GetInstance()->FullPath( strPlaintextConfigPath, mPlaintextConfig ) ) + mPlaintextConfig = strPlaintextConfigPath; // OK, now we need to figure out where to put the new config file. // If the location was specified on the command line, get the full path to it. // otherwise, the location is the dir that this exe is in. if( fConfigOnCmdLine ) { - TSTRING strFullPath; - if( iFSServices::GetInstance()->FullPath( strFullPath, mEncryptedConfig ) ) - mEncryptedConfig = strFullPath; + TSTRING strEncryptedConfigPath; + if( iFSServices::GetInstance()->FullPath( strEncryptedConfigPath, mEncryptedConfig ) ) + mEncryptedConfig = strEncryptedConfigPath; } else { diff --git a/src/twcrypto/bytequeue.cpp b/src/twcrypto/bytequeue.cpp index 118f464..accc70b 100644 --- a/src/twcrypto/bytequeue.cpp +++ b/src/twcrypto/bytequeue.cpp @@ -133,9 +133,9 @@ unsigned int cByteQueueNode::Peek(byte &outByte) const // cByteQueue //----------------------------------------------------------------------------- -cByteQueue::cByteQueue(int mNodeSize) +cByteQueue::cByteQueue(int nodeSize) : BufferedTransformation(), - mNodeSize(mNodeSize), + mNodeSize(nodeSize), mCurrentSize(0) { head = tail = new cByteQueueNode(mNodeSize); diff --git a/src/twprint/twprintcmdline.cpp b/src/twprint/twprintcmdline.cpp index 7e10372..9e3fe8e 100644 --- a/src/twprint/twprintcmdline.cpp +++ b/src/twprint/twprintcmdline.cpp @@ -498,9 +498,6 @@ bool cTWPrintReportMode::Init(const cConfigFile& cf, const cCmdLineParser& cmdLi /////////////////////////////////////////////////////////////////////////////// int cTWPrintReportMode::Execute(cErrorQueue* pQueue) { - cFCOReport report; - cFCOReportHeader reportHeader; - try { ASSERT( ! mpData->mReportFile.empty() ); @@ -510,6 +507,7 @@ int cTWPrintReportMode::Execute(cErrorQueue* pQueue) cKeyFile localKeyfile; const cElGamalSigPublicKey* pKey; cFCOReport report; + cFCOReportHeader reportHeader; cTWUtil::OpenKeyFile( localKeyfile, mpData->mLocalKeyFile ); pKey = localKeyfile.GetPublicKey(); diff --git a/src/twtest/hierdatabase_t.cpp b/src/twtest/hierdatabase_t.cpp index 62d517c..e3a7545 100644 --- a/src/twtest/hierdatabase_t.cpp +++ b/src/twtest/hierdatabase_t.cpp @@ -35,7 +35,7 @@ #include "test.h" #include "core/error.h" -static void PrintDb( cHierDatabase::iterator iter, cDebug d, bool bFirst = true ) +/*static void PrintDb( cHierDatabase::iterator iter, cDebug d, bool bFirst = true ) { if( ! bFirst ) { @@ -54,7 +54,7 @@ static void PrintDb( cHierDatabase::iterator iter, cDebug d, bool bFirst = true } d.TraceDebug( "-- Done Processing directory %s\n", iter.GetCwd().c_str() ); -} +}*/ static void GetNoun( TSTRING& noun ) { From 6ea9c0b92e79880c3865eba388da0115955cb5f6 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 17 Mar 2017 18:38:56 -0700 Subject: [PATCH 16/43] fix debug builds in debug.cpp --- src/core/debug.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/debug.cpp b/src/core/debug.cpp index 6870b7d..7c285bb 100644 --- a/src/core/debug.cpp +++ b/src/core/debug.cpp @@ -63,7 +63,7 @@ cDebug::cDebug(const char* label) cDebug::cDebug(const cDebug &rhs) { - strcpy(mLabel, rhs.mLabel, MAX_LABEL); + strncpy(mLabel, rhs.mLabel, MAX_LABEL); } cDebug::~cDebug() From 2c57dd824a15465f0211b28ca3c01de71e9082d9 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 17 Mar 2017 23:37:05 -0700 Subject: [PATCH 17/43] Update test policy files in src/parser/testfiles to (largely) match current policy language --- src/parser/testfiles/directives.txt | 26 +++++----- src/parser/testfiles/pol.txt | 77 ++++++++++++++-------------- src/parser/testfiles/poleasy.txt | 2 +- src/parser/testfiles/polhard.txt | 77 ++++++++++++++-------------- src/parser/testfiles/polruleattr.txt | 4 +- 5 files changed, 92 insertions(+), 94 deletions(-) diff --git a/src/parser/testfiles/directives.txt b/src/parser/testfiles/directives.txt index 4374975..f9d9f85 100644 --- a/src/parser/testfiles/directives.txt +++ b/src/parser/testfiles/directives.txt @@ -2,16 +2,16 @@ # parser will echo YES1 through YES9 # there's a problem with the parser if it echoes NO -@@ifhost turd +@@ifhost foo @@error NO1 @@else @@echo +YES1; @@endif -@@ifhost crap || your_host||poo +@@ifhost bar || your_host||baz - @@ifhost turd + @@ifhost foo @@ifhost your_host @@error +NO2; @@ -23,7 +23,7 @@ @@else - @@ifhost turd + @@ifhost foo @@error +NO5; @@else @@echo +YES2; @@ -63,29 +63,29 @@ @@error +NO10; @@endif - @@ifhost turd + @@ifhost foo @@error +NO11; @@else @@echo +YES7; @@endif - @@ifhost your_host || poo + @@ifhost your_host || baz @@echo +YES8; @@endif - @@ifhost poo || your_host + @@ifhost baz || your_host @@echo +YES9; @@endif - @@ifhost poo + @@ifhost baz @@error +NO12; @@endif @@else - @@ifhost turd + @@ifhost foo @@ifhost your_host @@error +NO13; @@ -97,7 +97,7 @@ @@else - @@ifhost turd + @@ifhost foo @@error +NO16; @@else @@error +NO17; @@ -107,7 +107,7 @@ @@endif - @@ifhost turd + @@ifhost foo @@error +NO19; @@else @@error +NO20; @@ -120,13 +120,13 @@ @@endif - @@ifhost turd + @@ifhost foo @@error +NO23; @@else @@error +NO24; @@endif - @@ifhost poo + @@ifhost baz @@error +NO25; @@endif diff --git a/src/parser/testfiles/pol.txt b/src/parser/testfiles/pol.txt index 2b0accc..d83eadf 100644 --- a/src/parser/testfiles/pol.txt +++ b/src/parser/testfiles/pol.txt @@ -14,34 +14,32 @@ /simple -> +ppp; # variable -$(poo) = pinug; -/simplevar -> $(poo) ; +FOO = pinug; +/simplevar -> $(FOO) ; -$(turd) = /test6; -$(turd) -> $(poo); +BAR = /test6; +$(BAR) -> $(FOO); # named attributes -/namedattr -> +pinug (name /namedattr ) ; +#/namedattr -> +pinug (name /namedattr ) ; # multiple attributes -/namedattr2 -> +pinug (emailreport on, emailsendto genek, name /namedattr2, name4 val4, name5 val5 ); +#/namedattr2 -> +pinug (emailreport on, emailsendto genek, name /namedattr2, name4 val4, name5 val5 ); # test line continuations -/turd \ +/bar \ ->\ +p ; -@@EnD +#@@EnD -/test -> +p; -"/te\x73t2" -> +p-p ; -"/te\163t3" -> +pinugs-am ; -"c:\\te\163t3\\" -> +pinugs-am ; -"c:\\te\"as\163t3\\" -> +pinugs-am ; -"/te\163t3" -> +pinugs-am ; -"/te\163t3" -> +pinugs-am ; -/test4 -> +pinugs---am ; -/test5 -> $(ReadOnly)s-+-am ; +/test7 -> +p; +"/te\x73t8" -> +p-p ; +"/te\163t9" -> +pinugs-am ; +"/te\163t12" -> +pinugs-am ; +"/te\163t13" -> +pinugs-am ; +/test14 -> +pinugs---am ; +/test15 -> $(ReadOnly)s-+-am ; # test weird file names /lost+found -> +p ; @@ -51,50 +49,51 @@ $(turd) -> $(poo); ; # simple default policy -/simple -> +ppp; +/simple2 -> +ppp; # variable -$(poo) = pinug; -/simplevar -> $(poo) ; -$(turd) = /test6; -$(turd) -> $(poo); +FOO = pinug; +/simplevar2 -> $(FOO) ; +BAR = /test16; +$(BAR) -> $(FOO); # omit with space seperation ! /omit ; # omit with no space separation - !/omit ; + !/omit2 ; # named attributes -/namedattr -> +pinug (name1 value1) ; +#/namedattr -> +pinug (name1 value1) ; # multiple attributes -/namedattr2 -> +pinug (emailreport on; emailsendto genek; name3 val3; name4 val4; name5 val5 ) ; +#/namedattr2 -> +pinug (emailreport on; emailsendto genek; name3 val3; name4 val4; name5 val5 ) ; # test line continuations -/turd \ +/bar2 \ ->\ +p ; -@@END +#@@END # the following isn't implemented yet #########################################3 # attributes on specifers -/conditions { - xxx: +pinug (inside1 name1 ;) ; - yyy: +pinug ; - zzz: +pinug ; - default: +pinug ; - }; +#/conditions2 { +# xxx: +pinug (inside1 name1 ;) ; +# yyy: +pinug ; +# zzz: +pinug ; +# default: +pinug ; +# }; # multiple specmasks -/conditions { - xxx: +pinug ; - yyy: +pinug ; - zzz: +pinug ; - default: +pinug ; - }; \ No newline at end of file +#/conditions3 { +# xxx: +pinug ; +# yyy: +pinug ; +# zzz: +pinug ; +# default: +pinug ; +# }; +# diff --git a/src/parser/testfiles/poleasy.txt b/src/parser/testfiles/poleasy.txt index f88a1f6..d9a11da 100644 --- a/src/parser/testfiles/poleasy.txt +++ b/src/parser/testfiles/poleasy.txt @@ -1 +1 @@ -/etc jj ; +/etc -> $(IgnoreNone); diff --git a/src/parser/testfiles/polhard.txt b/src/parser/testfiles/polhard.txt index 1586dc2..fad96b8 100644 --- a/src/parser/testfiles/polhard.txt +++ b/src/parser/testfiles/polhard.txt @@ -1,17 +1,16 @@ # test weird file names /lost+found -> +p ; -/l-o_st+fo/und -> +ping (l-o_st+fo/und2 l-o_st+fo/und3) ; +/l-o_st+fo/und -> +ping; # test variables -$(ReadOnly) = ping; -/simplevar -> $(ReadOnly) ; -/var -> $(ReadOnly)-p ; +FOO = ping; +/simplevar -> $(FOO) ; +/var -> $(FOO)-p ; # test line continuations -c:/test -> +p ; -/turd \ +/bar \ ->\ +p ; @@ -19,26 +18,25 @@ c:/test -> +p ; # test quoted strings "/qfoo" -> +p ; "/Program Files" -> +p ; -" /lots o' spaces " -> +p ; -" colon: semicolon; quote' " -> +p ; +#" /lots o' spaces " -> +p ; +#" colon: semicolon; quote' " -> +p ; # test attributes -/namedattr2 -> +p ( name1 value1; name2 value2; ) ; -/namedattr -> +p (name1 value1; ) ; +#/namedattr2 -> +p ( name1 value1; name2 value2; ) ; +#/namedattr -> +p (name1 value1; ) ; # test propvector -c:/test -> +p ; -/test -> +p ; -/test -> +p-p ; -/test -> +pinugs-am ; -/test -> +pinugs---am ; -/test -> +pinugs-+-am ; +/test1 -> +p ; +/test2 -> +p-p ; +/test3 -> +pinugs-am ; +/test4 -> +pinugs---am ; +/test5 -> +pinugs-+-am ; # attributes and props -/namedattr3 -> +pinug ( name1 value1; name2 value2; ) ; -/namedattr4 -> +pinug (name1 value1; ) ; +#/namedattr3 -> +pinug ( name1 value1; name2 value2; ) ; +#/namedattr4 -> +pinug (name1 value1; ) ; # simple default policy /simple -> +ppp; @@ -48,38 +46,39 @@ c:/test -> +p ; ! /omit ; # omit with no space separation - !/omit ; + !/omit2 ; # multiple attributes -/namedattr -> +pinug (emailreport on; emailsendto genek; name3 val3; name4 val4; name5 val5; ) ; +#/namedattr -> +pinug (emailreport on; emailsendto genek; name3 val3; name4 val4; name5 val5; ) ; -@@END +#@@END # the following isn't implemented yet #########################################3 # multiple specmasks -/conditions -> { - xxx -> +pinug ; - yyy -> +pinug ; - zzz -> +pinug ; - default -> +pinug ; - }; +#/conditions -> { +# xxx -> +pinug ; +# yyy -> +pinug ; +# zzz -> +pinug ; +# default -> +pinug ; +# }; # attributes on specifers -/conditions -> { - xxx -> +pinug (inside1 name1 ;) ; - yyy -> +pinug ; - zzz -> +pinug ; - default -> +pinug ; - }; +#/conditions -> { +# xxx -> +pinug (inside1 name1 ;) ; +# yyy -> +pinug ; +# zzz -> +pinug ; +# default -> +pinug ; +# }; # hard ones -/conditions -> { - xxx -> +pinug (inside1 name1 ;) ; - yyy -> $(poo)+pinug ; - zzz -> +pinug ( inside1 name1 ; outside name2); - default -> $(turd)-p ; - }; \ No newline at end of file +#/conditions -> { +# xxx -> +pinug (inside1 name1 ;) ; +# yyy -> $(baz)+pinug ; +# zzz -> +pinug ( inside1 name1 ; outside name2); +# default -> $(bar)-p ; +# }; + diff --git a/src/parser/testfiles/polruleattr.txt b/src/parser/testfiles/polruleattr.txt index 468fa36..3f5febc 100644 --- a/src/parser/testfiles/polruleattr.txt +++ b/src/parser/testfiles/polruleattr.txt @@ -1,4 +1,4 @@ -( emailreport on ; ) +(emailto=root@localhost) { /foo -> +pinugs ; -} \ No newline at end of file +} From a2e82147ebee26ebda1c214201e7c20d63be5ef7 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 19 Mar 2017 10:40:29 -0700 Subject: [PATCH 18/43] update old 'directives.txt' policy test file for current syntax --- src/parser/testfiles/directives.txt | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/parser/testfiles/directives.txt b/src/parser/testfiles/directives.txt index f9d9f85..47255b0 100644 --- a/src/parser/testfiles/directives.txt +++ b/src/parser/testfiles/directives.txt @@ -5,7 +5,7 @@ @@ifhost foo @@error NO1 @@else - @@echo +YES1; + @@print +YES1 @@endif @@ifhost bar || your_host||baz @@ -26,10 +26,10 @@ @@ifhost foo @@error +NO5; @@else - @@echo +YES2; + @@print +YES2; @@endif - @@echo +YES3; + @@print +YES3; @@endif @@ -38,12 +38,12 @@ @@ifhost your_host @@ifhost your_host - @@echo +YES4; + @@print +YES4; @@else @@error +NO6; @@endif - @@echo +YES5; + @@print +YES5; @@else @@ -58,7 +58,7 @@ @@endif @@ifhost your_host - @@echo +YES6; + @@print +YES6; @@else @@error +NO10; @@endif @@ -66,16 +66,16 @@ @@ifhost foo @@error +NO11; @@else - @@echo +YES7; + @@print +YES7; @@endif @@ifhost your_host || baz - @@echo +YES8; + @@print +YES8; @@endif @@ifhost baz || your_host - @@echo +YES9; + @@print +YES9; @@endif @@ifhost baz @@ -132,4 +132,6 @@ @@endif +#A token rule at the end to avoid 'no rules in policy file' errors +/asdf -> +a; From 5275975d86b6de8fa7714df7535e9012948eedd2 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 19 Mar 2017 23:09:05 -0700 Subject: [PATCH 19/43] Correctly handle rule w/ leading whitespace within a quoted path. Uncomment test case that validates correct behavior. --- src/fs/fsparserutil.cpp | 11 +++++++++++ src/parser/testfiles/polhard.txt | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/fs/fsparserutil.cpp b/src/fs/fsparserutil.cpp index c20ed44..c711234 100644 --- a/src/fs/fsparserutil.cpp +++ b/src/fs/fsparserutil.cpp @@ -131,6 +131,11 @@ void cFSParserUtil::AddSubTypeProps( cFCOPropVector& v ) const v.AddItemAndGrow( cFSPropSet::PROP_FILETYPE ); } +static inline void trim_leading_whitespace(std::string &str) +{ + str.erase(str.begin(), std::find_if(str.begin(), str.end(), std::not1(std::ptr_fun(std::isspace)))); +} + void cFSParserUtil::InterpretFCOName( const std::list& l, cFCOName& nameOut ) const { TSTRING strT; @@ -141,6 +146,12 @@ void cFSParserUtil::InterpretFCOName( const std::list& l, cFCOName& nam strT = cDevicePath::AsPosix(strT); #endif + //Trim any remaining whitespace before actual path, for cases like " /foo", + // otherwise it'll be flagged as a relative path. + //Don't trim trailing whitespace, since that could potentially be a valid path. + if(strT[0] != '/') + trim_leading_whitespace(strT); + // let cFCOName handle interpretation nameOut = strT; } diff --git a/src/parser/testfiles/polhard.txt b/src/parser/testfiles/polhard.txt index fad96b8..6d3f7cd 100644 --- a/src/parser/testfiles/polhard.txt +++ b/src/parser/testfiles/polhard.txt @@ -18,7 +18,7 @@ FOO = ping; # test quoted strings "/qfoo" -> +p ; "/Program Files" -> +p ; -#" /lots o' spaces " -> +p ; +" /lots o' spaces " -> +p ; #" colon: semicolon; quote' " -> +p ; # test attributes From ea2170fd2076a7b693eaf50340a8d0a9087dfda1 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Tue, 21 Mar 2017 23:36:26 -0700 Subject: [PATCH 20/43] Tweak a memory alignment unit test that doesn't (and should not be expected to) work on HP-UX. --- src/twtest/platform_t.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/twtest/platform_t.cpp b/src/twtest/platform_t.cpp index bf8cf2d..742fb24 100644 --- a/src/twtest/platform_t.cpp +++ b/src/twtest/platform_t.cpp @@ -85,6 +85,13 @@ void TestPlatform() template AlignMe::AlignMe() { +// HP-UX does not play your silly alignment games, at least unless you +// first invoke something called "allow_unaligned_data_access()", which +// apparently incurs a substantial perf penalty. Luckily we don't appear +// to have any need for that behavior, which begs the question of why +// this test exists in the first place. +// -bcox +#if (!IS_HPUX) TCOUT << _T("Testing alignment of size ") << ALIGN_SIZE << std::endl; // access a double in the byte array to see if it is aligned. if it isn't and the CPU @@ -101,6 +108,7 @@ AlignMe::AlignMe() *pi = i; // access memory for write TCOUT << _T("Write succeeded.") << std::endl; + // this should choke if the CPU can't // handle misaligned memory access int64* pb = (int64*)&a[ALIGN_SIZE]; @@ -111,6 +119,7 @@ AlignMe::AlignMe() TCOUT << _T("Writing...") << std::endl; *pb = I; // access memory for write TCOUT << _T("Write succeeded.") << std::endl; +#endif TCOUT << _T("Alignment of ") << ALIGN_SIZE << _T(" ") << ( ALIGN_SIZE == 1 ? _T("byte") : _T("bytes") ) << _T(" is OK") << std::endl << _T("=========================================\n"); From 4cb15a741a46d65e3eb2b03b8ad784f7845d3f38 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 22 Mar 2017 00:11:20 -0700 Subject: [PATCH 21/43] Remove 'util_EatAllSpaces' method, which did shady things with iterators and didn't even eat all whitespace --- src/twparser/parserhelper.cpp | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/twparser/parserhelper.cpp b/src/twparser/parserhelper.cpp index 5f1fc57..62a600b 100644 --- a/src/twparser/parserhelper.cpp +++ b/src/twparser/parserhelper.cpp @@ -63,7 +63,6 @@ static int util_ConvertOctal( const char* psz, int* const pnCharsRead ); static bool util_IsOctal( const char ch ); static int util_GetEscapeValueOfChar( char ch ); static int util_GetRecurseDepth( const cParseNamedAttrList* pList ); //throw( eParserHelper ) -static void util_EatAllSpaces( TSTRING& str ); static void util_LoseSurroundingWS( TSTRING& str ); #ifdef _DEBUG static bool util_AsciiCharsActLikeTheyShould(); @@ -671,7 +670,7 @@ void cParserUtil::CreatePropVector( const TSTRING& strPropListC, class cFCOPropV // clear out all spaces in the string TSTRING strPropList = strPropListC; - util_EatAllSpaces( strPropList ); + strPropList.erase(std::remove_if(strPropList.begin(), strPropList.end(), std::ptr_fun(std::isspace)), strPropList.end()); // zero it out v.Clear(); @@ -741,17 +740,6 @@ void cParserUtil::CreatePropVector( const TSTRING& strPropListC, class cFCOPropV v.RemoveItem( propIndex ); } - /* for 1.5, allow no properties (just track file existence) - // if v is empty, error - cFCOPropVector emptyPropVector; - emptyPropVector.Clear(); - if( v == emptyPropVector ) - { - d.TraceError("CreatePropVector failed!!\n"); - throw eError( ERR_BAD_PROP_STRING, strPropV.c_str() ); - } - */ - return; } @@ -1079,18 +1067,6 @@ TSTRING::size_type util_FindNextDelim( const TSTRING& str, TSTRING::size_type i return min; } -// deletes each space in the string -void util_EatAllSpaces( TSTRING& str ) -{ - for( TSTRING::iterator i = str.begin(); i != str.end(); i++ ) - { - if( *i == _T(' ') ) - { - str.erase( i ); - } - } -} - void util_LoseSurroundingWS( TSTRING& str ) { TSTRING::size_type nonWSStart = str.find_first_not_of( _T(" \t"), 0 ); From 5c1cfe47028cf63a3434028c4f83c7b945f9ee84 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 22 Mar 2017 20:00:08 -0700 Subject: [PATCH 22/43] Use unique_ptr instead of auto_ptr where available (and define a macro to pick which one to use); fix a few other remaining warnings. --- src/core/codeconvert.cpp | 4 ++-- src/core/msystem.cpp | 3 ++- src/core/refcountobj.cpp | 3 --- src/core/types.h | 11 +++++++++++ src/cryptlib/filters.cpp | 8 +++++++- src/cryptlib/forkjoin.cpp | 8 +++++++- src/tripwire/generatedb.cpp | 8 ++++---- src/tripwire/integritycheck.cpp | 8 ++++---- src/tripwire/tripwiremain.cpp | 4 ++-- src/tripwire/twcmdline.cpp | 2 +- src/tripwire/twcmdlineutil.cpp | 12 ++++++------ src/tw/twutil.cpp | 4 ++-- src/twadmin/twadminmain.cpp | 2 +- src/twprint/twprintmain.cpp | 2 +- src/twtest/codeconvert_t.cpp | 3 ++- src/twtest/refcountobj_t.cpp | 4 ++-- src/twtest/unixfsservices_t.cpp | 2 +- 17 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/core/codeconvert.cpp b/src/core/codeconvert.cpp index 3d926d5..9142da1 100644 --- a/src/core/codeconvert.cpp +++ b/src/core/codeconvert.cpp @@ -1016,7 +1016,7 @@ cDoubleIconvConverter::Convert( // size_t nBufBytes = nChars * MB_LEN_MAX; ntmbs_t pszBuffer = (ntmbs_t)::operator new( nBufBytes + 1 ); - std::auto_ptr pBuf( pszBuffer ); + TW_UNIQUE_PTR pBuf( pszBuffer ); // // do first conversion @@ -1074,7 +1074,7 @@ cDoubleIconvConverter::Convert( // size_t nBufBytes = nBytes * MB_LEN_MAX; ntmbs_t pszBuffer = (ntmbs_t)::operator new( nBufBytes + 1 ); - std::auto_ptr pBuf( pszBuffer ); + TW_UNIQUE_PTR pBuf( pszBuffer ); // // do first conversion diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index 5c3a4d4..c551aee 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -207,6 +207,7 @@ char *getenv(); /* get variable from environment */ * on some systems, this is a library function, so define STRDUP * if it is on yours */ +#if 0 #ifdef STRDUP # ifndef __STDC__ char *strdup(); @@ -230,7 +231,7 @@ char *getenv(); /* get variable from environment */ return(p); } #endif - +#endif //0 /* * allocate space for an array of pointers, OR diff --git a/src/core/refcountobj.cpp b/src/core/refcountobj.cpp index 209f03d..f8df324 100644 --- a/src/core/refcountobj.cpp +++ b/src/core/refcountobj.cpp @@ -135,9 +135,6 @@ void cRefCountObj::AddRef() const void cRefCountObj::Release() const { - if (this == 0) - return; - if (--mRefCount == 0) { Delete(); diff --git a/src/core/types.h b/src/core/types.h index 5744e02..170681a 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -187,5 +187,16 @@ inline int64 SWAPBYTES64(int64 i) #endif //WORDS_BIGENDIAN +//////////////////////////////////////////// + +#if __cplusplus >= 201103L +# define TW_UNIQUE_PTR std::unique_ptr +#else +# define TW_UNIQUE_PTR std::auto_ptr +#endif + + + + #endif // __TYPES_H diff --git a/src/cryptlib/filters.cpp b/src/cryptlib/filters.cpp index b3dbfee..ef47f2a 100644 --- a/src/cryptlib/filters.cpp +++ b/src/cryptlib/filters.cpp @@ -5,6 +5,12 @@ #include "queue.h" #include +#if __cplusplus >= 201103L +# define TW_UNIQUE_PTR std::unique_ptr +#else +# define TW_UNIQUE_PTR std::auto_ptr +#endif + Filter::Filter(BufferedTransformation *outQ) : outQueue(outQ ? outQ : new ByteQueue) { @@ -17,7 +23,7 @@ Filter::Filter(const Filter &source) void Filter::Detach(BufferedTransformation *newOut) { - std::auto_ptr out(newOut ? newOut : new ByteQueue); + TW_UNIQUE_PTR out(newOut ? newOut : new ByteQueue); outQueue->Close(); outQueue->TransferTo(*out); outQueue.reset(out.release()); diff --git a/src/cryptlib/forkjoin.cpp b/src/cryptlib/forkjoin.cpp index 054cc47..899ec85 100644 --- a/src/cryptlib/forkjoin.cpp +++ b/src/cryptlib/forkjoin.cpp @@ -5,6 +5,12 @@ #include "queue.h" #include +#if __cplusplus >= 201103L +# define TW_UNIQUE_PTR std::unique_ptr +#else +# define TW_UNIQUE_PTR std::auto_ptr +#endif + Fork::Fork(int n, BufferedTransformation *const *givenOutPorts) : numberOfPorts(n), outPorts(n) { @@ -21,7 +27,7 @@ void Fork::SelectOutPort(int portNumber) void Fork::Detach(BufferedTransformation *newOut) { - std::auto_ptr out(newOut ? newOut : new ByteQueue); + TW_UNIQUE_PTR out(newOut ? newOut : new ByteQueue); outPorts[currentPort]->Close(); outPorts[currentPort]->TransferTo(*out); outPorts[currentPort].reset(out.release()); diff --git a/src/tripwire/generatedb.cpp b/src/tripwire/generatedb.cpp index 244a051..7bf59b2 100644 --- a/src/tripwire/generatedb.cpp +++ b/src/tripwire/generatedb.cpp @@ -100,7 +100,7 @@ static void util_ProcessDir( cDbDataSourceIter dbIter, iFCODataSourceIter* pIter { dbIter.AddChildArray(); } - std::auto_ptr pCopy( pIter->CreateCopy() ); + TW_UNIQUE_PTR pCopy( pIter->CreateCopy() ); util_ProcessDir( dbIter, pCopy.get(), pSpec, pPC, pPD ); // // if no files were added, remove the child array... @@ -122,7 +122,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO { // TODO -- assert the db is empty or clear it out myself! - std::auto_ptr pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); + TW_UNIQUE_PTR pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); // // set up the database's iterator... @@ -139,7 +139,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO // // this is the object that will calculate all of the properties of the fcos. // - std::auto_ptr pPC(iTWFactory::GetInstance()->CreatePropCalc()); + TW_UNIQUE_PTR pPC(iTWFactory::GetInstance()->CreatePropCalc()); pPC->SetErrorBucket( pBucket ); if( flags & FLAG_ERASE_FOOTPRINTS_GD ) { @@ -193,7 +193,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO { dbIter.AddChildArray(); } - std::auto_ptr pCopy( pDSIter->CreateCopy() ); + TW_UNIQUE_PTR pCopy( pDSIter->CreateCopy() ); util_ProcessDir( dbIter, pCopy.get(), specIter.Spec(), pPC.get(), pPD ); // // if no files were added, remove the child array... diff --git a/src/tripwire/integritycheck.cpp b/src/tripwire/integritycheck.cpp index 8dc7147..ef599d6 100644 --- a/src/tripwire/integritycheck.cpp +++ b/src/tripwire/integritycheck.cpp @@ -90,7 +90,7 @@ void cIntegrityCheck::ProcessAddedFCO( cDbDataSourceIter dbIter, iFCODataSourceI // to done... // while( ! dbIter.Done() ) dbIter.Next(); - std::auto_ptr pCopy( pIter->CreateCopy() ); + TW_UNIQUE_PTR pCopy( pIter->CreateCopy() ); ProcessDir( dbIter, pCopy.get() ); } } @@ -231,7 +231,7 @@ void cIntegrityCheck::ProcessChangedFCO( cDbDataSourceIter dbIter, iFCODataSourc { if( pIter->CanDescend() || dbIter.CanDescend() ) { - std::auto_ptr pCopy( pIter->CreateCopy() ); + TW_UNIQUE_PTR pCopy( pIter->CreateCopy() ); ProcessDir( dbIter, pCopy.get() ); } } @@ -453,7 +453,7 @@ void cIntegrityCheck::Execute( uint32 flags ) mFlags = flags; // create the data source iterator // - std::auto_ptr pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); + TW_UNIQUE_PTR pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); // // set up the database's iterator... // I assume the current genre is correct... @@ -560,7 +560,7 @@ void cIntegrityCheck::ExecuteOnObjectList( const std::list& fcoNames, // // create the data source iterator // - std::auto_ptr pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); + TW_UNIQUE_PTR pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); // // set up the database's iterator... // I assume the current genre is correct... diff --git a/src/tripwire/tripwiremain.cpp b/src/tripwire/tripwiremain.cpp index 67a81f2..266199d 100644 --- a/src/tripwire/tripwiremain.cpp +++ b/src/tripwire/tripwiremain.cpp @@ -44,7 +44,7 @@ #include "core/errorbucketimpl.h" #include "core/usernotifystdout.h" #include "core/timebomb.h" -#include // for auto_ptr +#include // for auto_ptr / unique_ptr #include #include @@ -133,7 +133,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) // first, get the right mode... - std::auto_ptr pMode(cTWCmdLine::GetMode(argc, argv)); + TW_UNIQUE_PTR pMode(cTWCmdLine::GetMode(argc, argv)); if(! pMode.get()) { // no valid mode passed; GetMode will display an appropriate string (include usage statement) diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index e6de6a4..6c51144 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -1129,7 +1129,7 @@ int cTWModeIC::Execute(cErrorQueue* pQueue) if( ! dbIter.Done() ) { cGenreSwitcher::GetInstance()->SelectGenre( (cGenre::Genre)dbIter.GetGenre() ); - std::auto_ptr pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); + TW_UNIQUE_PTR pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); // // I have to turn this into a list of cFCONames // diff --git a/src/tripwire/twcmdlineutil.cpp b/src/tripwire/twcmdlineutil.cpp index 244a75d..67e5893 100644 --- a/src/tripwire/twcmdlineutil.cpp +++ b/src/tripwire/twcmdlineutil.cpp @@ -531,7 +531,7 @@ static bool EmailReportTo(const TSTRING &toAddress, const cFCOReportHeader& head const cTWModeCommon *modeCommon, const bool bForceFullReport) { - std::auto_ptr reportMail; + TW_UNIQUE_PTR reportMail; // allocate the right kind of emailer object based on what came out of the config file. switch (modeCommon->mMailMethod) @@ -540,10 +540,10 @@ static bool EmailReportTo(const TSTRING &toAddress, const cFCOReportHeader& head ASSERT(false); return false; case cMailMessage::MAIL_BY_SMTP: - reportMail = std::auto_ptr(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); + reportMail = TW_UNIQUE_PTR(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); break; case cMailMessage::MAIL_BY_PIPE: - reportMail = std::auto_ptr(new cPipedMailMessage(modeCommon->mMailProgram)); + reportMail = TW_UNIQUE_PTR(new cPipedMailMessage(modeCommon->mMailProgram)); break; } @@ -685,7 +685,7 @@ bool cTWCmdLineUtil::EmailReport(const cFCOReportHeader& header, const cFCORepor bool cTWCmdLineUtil::SendEmailTestMessage(const TSTRING &mAddress, const cTWModeCommon *modeCommon) { - std::auto_ptr reportMail; + TW_UNIQUE_PTR reportMail; // allocate the right kind of emailer object based on what came out of the config file. switch (modeCommon->mMailMethod) @@ -694,10 +694,10 @@ bool cTWCmdLineUtil::SendEmailTestMessage(const TSTRING &mAddress, const cTWMode ASSERT(false); return false; case cMailMessage::MAIL_BY_SMTP: - reportMail = std::auto_ptr(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); + reportMail = TW_UNIQUE_PTR(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); break; case cMailMessage::MAIL_BY_PIPE: - reportMail = std::auto_ptr(new cPipedMailMessage(modeCommon->mMailProgram)); + reportMail = TW_UNIQUE_PTR(new cPipedMailMessage(modeCommon->mMailProgram)); break; } diff --git a/src/tw/twutil.cpp b/src/tw/twutil.cpp index 956d4d5..38656e8 100644 --- a/src/tw/twutil.cpp +++ b/src/tw/twutil.cpp @@ -1247,7 +1247,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob // if( g == cGenre::GENRE_INVALID ) { - std::auto_ptr pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); + TW_UNIQUE_PTR pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); if( ! pParseUtil->IsAbsolutePath( *i ) ) throw eTWUnknownSectionName( *i ); } @@ -1310,7 +1310,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob /////////////////////////////////////////////////////////////////////////////// cFCOName cTWUtil::ParseObjectName( const TSTRING& fcoName ) { - std::auto_ptr pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); + TW_UNIQUE_PTR pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); cFCOName name( iTWFactory::GetInstance()->GetNameInfo() ); // // make sure the fco name is a full path... diff --git a/src/twadmin/twadminmain.cpp b/src/twadmin/twadminmain.cpp index b24fe6d..696032c 100644 --- a/src/twadmin/twadminmain.cpp +++ b/src/twadmin/twadminmain.cpp @@ -94,7 +94,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) // first, get the right mode... - std::auto_ptr pMode(cTWAdminCmdLine::GetMode(argc, argv)); + TW_UNIQUE_PTR pMode(cTWAdminCmdLine::GetMode(argc, argv)); if(! pMode.get()) { // no valid mode passed; GetMode will display an appropriate string (include usage statement) diff --git a/src/twprint/twprintmain.cpp b/src/twprint/twprintmain.cpp index c55631e..dc04b56 100644 --- a/src/twprint/twprintmain.cpp +++ b/src/twprint/twprintmain.cpp @@ -128,7 +128,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ] ) } // Next, set the mode... exit with error if now valid mode specified. - std::auto_ptr pMode(cTWPrintCmdLine::GetMode(argc, argv)); + TW_UNIQUE_PTR pMode(cTWPrintCmdLine::GetMode(argc, argv)); if(! pMode.get()) { // no valid mode passed; GetMode will display an appropriate string (include usage statement) diff --git a/src/twtest/codeconvert_t.cpp b/src/twtest/codeconvert_t.cpp index d31a8ba..85eb874 100644 --- a/src/twtest/codeconvert_t.cpp +++ b/src/twtest/codeconvert_t.cpp @@ -182,9 +182,10 @@ char NonZeroChar( char ch ) } // mbchar_t to dbchar_t +//TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd" void TestMbToDb() { - TCERR << "TODO: TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd" << std::endl; + TCERR << "\nTODO: TestMbToDb in codeconvert_t.cpp is flaky & needs to be fixed/replaced; currently disabled." << std::endl; #if 0 std::string s; s.resize( 0x10000 * 2 ); // two bytes for each combination diff --git a/src/twtest/refcountobj_t.cpp b/src/twtest/refcountobj_t.cpp index ea9ec18..dc04d1d 100644 --- a/src/twtest/refcountobj_t.cpp +++ b/src/twtest/refcountobj_t.cpp @@ -39,7 +39,7 @@ class cRefCountTestObj : public cRefCountObj public: cRefCountTestObj(); - virtual void Release(); + virtual void Release() const; void AddChild(cRefCountTestObj* pChild); @@ -74,7 +74,7 @@ void cRefCountTestObj::AddChild(cRefCountTestObj* pChild) mChildren.push_back(pChild); } -void cRefCountTestObj::Release() +void cRefCountTestObj::Release() const { cRefCountObj::Release(); } diff --git a/src/twtest/unixfsservices_t.cpp b/src/twtest/unixfsservices_t.cpp index 5f46f32..c7e852c 100644 --- a/src/twtest/unixfsservices_t.cpp +++ b/src/twtest/unixfsservices_t.cpp @@ -68,7 +68,7 @@ void TestUnixFSServices() d.TraceDebug("name: %d entries\n", v.size()); std::vector ::iterator p; - int n = 0; + size_t n = 0; for (p = v.begin(); p != v.end(); p++) { d.TraceDetail(" %s\n", p->c_str()); n++; From 9c38b49839790dce7068e451d35d8d5f85866ab2 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 23 Mar 2017 19:30:52 -0700 Subject: [PATCH 23/43] Prefer prefix ++/-- operators where possible, for performance reasons (per CppCheck) --- src/db/blockfile.cpp | 10 +++++----- src/db/blockrecordfile.cpp | 6 +++--- src/db/hierdatabase.cpp | 10 +++++----- src/fco/fcodatasourceiterimpl.cpp | 10 +++++----- src/fco/fconame.cpp | 10 +++++----- src/fco/fcosetimpl.cpp | 4 ++-- src/fco/fcospecattr.h | 2 +- src/fco/fcospechelper.cpp | 4 ++-- src/fco/fcospechelper.h | 2 +- src/fco/fcospeclist.cpp | 4 ++-- src/fco/genreswitcher.cpp | 4 ++-- src/fs/fsparserutil.cpp | 2 +- src/fs/fspropdisplayer.cpp | 8 ++++---- src/tripwire/generatedb_t.cpp | 2 +- src/tripwire/integritycheck.cpp | 2 +- src/tripwire/integritycheck_t.cpp | 2 +- src/tripwire/mailmessage.cpp | 6 +++--- src/tripwire/twcmdline.cpp | 4 ++-- src/tw/dbexplore.cpp | 4 ++-- src/tw/fcodatabasefile.cpp | 8 ++++---- src/tw/fcoreport.cpp | 8 ++++---- src/tw/textreportviewer.cpp | 10 +++++----- src/tw/twutil.cpp | 6 +++--- src/twparser/genreparseinfo.cpp | 4 ++-- src/twparser/parserhelper.cpp | 14 +++++++------- src/twparser/parserobjects.cpp | 12 ++++++------ src/twparser/parserobjects.h | 2 +- src/twprint/twprintcmdline.cpp | 4 ++-- src/twtest/displayencoder_t.cpp | 2 +- src/twtest/textreportviewer_t.cpp | 2 +- src/twtest/unixfsservices_t.cpp | 2 +- src/util/stringencoder.cpp | 4 ++-- 32 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/db/blockfile.cpp b/src/db/blockfile.cpp index b936bb4..d87f3d4 100644 --- a/src/db/blockfile.cpp +++ b/src/db/blockfile.cpp @@ -140,7 +140,7 @@ void cBlockFile::Close() void cBlockFile::Flush() { ASSERT( mpArchive ); - for( BlockVector::iterator i = mvPagedBlocks.begin(); i != mvPagedBlocks.end(); i++ ) + for( BlockVector::iterator i = mvPagedBlocks.begin(); i != mvPagedBlocks.end(); ++i ) { FlushBlock( &(*i) ); } @@ -171,7 +171,7 @@ cBlockFile::Block* cBlockFile::GetBlock( int blockNum ) //throw (eArchive) mTimer++; if( mTimer == 0 ) { - for( BlockVector::iterator i = mvPagedBlocks.begin(); i != mvPagedBlocks.end(); i++ ) + for( BlockVector::iterator i = mvPagedBlocks.begin(); i != mvPagedBlocks.end(); ++i ) { i->SetTimestamp( 0 ); } @@ -179,7 +179,7 @@ cBlockFile::Block* cBlockFile::GetBlock( int blockNum ) //throw (eArchive) // // now, see if the desired block is in memory... // - for( BlockVector::iterator i = mvPagedBlocks.begin(); i != mvPagedBlocks.end(); i++ ) + for( BlockVector::iterator i = mvPagedBlocks.begin(); i != mvPagedBlocks.end(); ++i ) { if( i->GetBlockNum() == blockNum ) { @@ -201,9 +201,9 @@ cBlockFile::Block* cBlockFile::GetBlock( int blockNum ) //throw (eArchive) uint32 earliestTime = mvPagedBlocks[0].GetTimestamp(); BlockVector::iterator it = mvPagedBlocks.begin(); BlockVector::iterator earliestIter = it; - it++; // since we don't want to check the first one + ++it; // since we don't want to check the first one ASSERT(it != mvPagedBlocks.end()); - for( ; it != mvPagedBlocks.end(); it++ ) + for( ; it != mvPagedBlocks.end(); ++it ) { if( it->GetTimestamp() < earliestTime ) { diff --git a/src/db/blockrecordfile.cpp b/src/db/blockrecordfile.cpp index e049181..194a5db 100644 --- a/src/db/blockrecordfile.cpp +++ b/src/db/blockrecordfile.cpp @@ -277,7 +277,7 @@ int cBlockRecordFile::FindRoomForData( int32 dataSize ) //throw (eArchive) // BlockArray::iterator it; int cnt = 0; - for( it = mvBlocks.begin(); it != mvBlocks.end(); it++, cnt++ ) + for( it = mvBlocks.begin(); it != mvBlocks.end(); ++it, ++cnt ) { util_InitBlockArray( *it ); if( it->GetAvailableSpace() >= dataSize ) @@ -310,7 +310,7 @@ void cBlockRecordFile::TraceContents(int dl) const { // TODO -- this is probably not what I want to do, but it helps me right now... // - for( BlockArray::const_iterator i = mvBlocks.begin(); i != mvBlocks.end(); i++ ) + for( BlockArray::const_iterator i = mvBlocks.begin(); i != mvBlocks.end(); ++i ) { i->TraceContents( dl ); } @@ -330,7 +330,7 @@ void cBlockRecordFile::AssertValid() const /////////////////////////////////////////////////////////////////////////////// void cBlockRecordFile::AssertAllBlocksValid() { - for( BlockArray::iterator i = mvBlocks.begin(); i != mvBlocks.end(); i++ ) + for( BlockArray::iterator i = mvBlocks.begin(); i != mvBlocks.end(); ++i ) { i->AssertValid(); } diff --git a/src/db/hierdatabase.cpp b/src/db/hierdatabase.cpp index b4fd831..e90e28a 100644 --- a/src/db/hierdatabase.cpp +++ b/src/db/hierdatabase.cpp @@ -405,7 +405,7 @@ bool cHierDatabaseIter::Done() const /////////////////////////////////////////////////////////////////////////////// void cHierDatabaseIter::Next() { - mIter++; + ++mIter; } /////////////////////////////////////////////////////////////////////////////// @@ -552,10 +552,10 @@ void cHierDatabaseIter::CreateEntry( const TSTRING& name ) //throw (eArchive, eH { // altering the previous node... // - mIter--; + --mIter; mIter->mNext = newAddr; util_RewriteObject( mpDb, &(*mIter), GetCurrentAddr() ); - mIter++; + ++mIter; } } @@ -672,10 +672,10 @@ void cHierDatabaseIter::DeleteEntry() //throw (eArchive, eHierDatabase) { // altering the previous node... // - mIter--; + --mIter; mIter->mNext = (mIter+1)->mNext; util_RewriteObject( mpDb, &(*mIter), GetCurrentAddr() ); - mIter++; + ++mIter; } // // now, delete the node from the file and from our array... diff --git a/src/fco/fcodatasourceiterimpl.cpp b/src/fco/fcodatasourceiterimpl.cpp index c906188..b0cb892 100644 --- a/src/fco/fcodatasourceiterimpl.cpp +++ b/src/fco/fcodatasourceiterimpl.cpp @@ -75,7 +75,7 @@ cFCODataSourceIterImpl& cFCODataSourceIterImpl::operator=( const cFCODataSourceI // // we need to addref all of the fcos we just got... // - for( FCOList::const_iterator i = mPeers.begin(); i != mPeers.end(); i++ ) + for( FCOList::const_iterator i = mPeers.begin(); i != mPeers.end(); ++i ) { (*i)->AddRef(); } @@ -191,7 +191,7 @@ bool cFCODataSourceIterImpl::Done() const /////////////////////////////////////////////////////////////////////////////// void cFCODataSourceIterImpl::Next() { - mCurPos++; + ++mCurPos; } /////////////////////////////////////////////////////////////////////////////// @@ -282,7 +282,7 @@ bool cFCODataSourceIterImpl::IsCaseSensitive() const /////////////////////////////////////////////////////////////////////////////// void cFCODataSourceIterImpl::ClearList() { - for( mCurPos = mPeers.begin(); mCurPos != mPeers.end(); mCurPos++ ) + for( mCurPos = mPeers.begin(); mCurPos != mPeers.end(); ++mCurPos ) { (*mCurPos)->Release(); } @@ -316,7 +316,7 @@ void cFCODataSourceIterImpl::GeneratePeers() // std::vector::iterator i; cFCOName curName = mParentName; - for( i = vChildrenNames.begin(); i != vChildrenNames.end(); i++) + for( i = vChildrenNames.begin(); i != vChildrenNames.end(); ++i) { curName.Push( *i ); @@ -369,7 +369,7 @@ void cFCODataSourceIterImpl::TraceContents(int dl) const d.Trace( dl, "FCO Iterator; parent = %s\n", mParentName.AsString().c_str() ); d.Trace( dl, "---- Peers ---- (current has a * by it)\n" ); int cnt = 0; - for( FCOList::const_iterator iter = mPeers.begin(); iter != mPeers.end(); iter++, cnt++ ) + for( FCOList::const_iterator iter = mPeers.begin(); iter != mPeers.end(); ++iter, ++cnt ) { d.Trace( dl, "[%d]%c\t:%s\n", cnt, iter == mCurPos ? _T('*') : _T(' '), (*iter)->GetName().AsString().c_str() ); } diff --git a/src/fco/fconame.cpp b/src/fco/fconame.cpp index b3428d5..e73e8ac 100644 --- a/src/fco/fconame.cpp +++ b/src/fco/fconame.cpp @@ -288,7 +288,7 @@ TSTRING cFCOName::AsString() const TSTRING current = (*i)->GetString(); // the loop is constructed in this odd fashion because I don't want a trailing mDelimiter str += current; - i++; + ++i; if(i != mpPathName->mNames.end() && current != "/") str += mDelimiter; @@ -343,7 +343,7 @@ cFCOName::Relationship cFCOName::GetRelationship(const cFCOName& rhs) const for(myIter = mpPathName->mNames.begin(), rhsIter = rhs.mpPathName->mNames.begin(); (myIter != mpPathName->mNames.end() && rhsIter != rhs.mpPathName->mNames.end()); - myIter++, rhsIter++) + ++myIter, ++rhsIter) { if(bCaseSensitive) bEqual = (*myIter == *rhsIter); @@ -522,7 +522,7 @@ bool cFCOName::operator<(const cFCOName& rhs) const for(myIter = mpPathName->mNames.begin(), rhsIter = rhs.mpPathName->mNames.begin(); (myIter != mpPathName->mNames.end() && rhsIter != rhs.mpPathName->mNames.end()); - myIter++, rhsIter++) + ++myIter, ++rhsIter) { if(bCaseSensitive) { @@ -593,7 +593,7 @@ void cFCONameIter::SeekBegin() /////////////////////////////////////////////////////////////////////////////// void cFCONameIter::Next() { - mIter++; + ++mIter; } /////////////////////////////////////////////////////////////////////////////// @@ -619,7 +619,7 @@ const TCHAR* cFCONameIter::GetName() const /////////////////////////////////////////////////////////////////////////////// void cFCONameIter::Prev() { - mIter--; + --mIter; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/fco/fcosetimpl.cpp b/src/fco/fcosetimpl.cpp index a8f27d4..2f271e4 100644 --- a/src/fco/fcosetimpl.cpp +++ b/src/fco/fcosetimpl.cpp @@ -204,7 +204,7 @@ void cFCOSetImpl::Write(iSerializer* pSerializer) const pSerializer->WriteInt32(mFCOSet.size()); std::set::const_iterator itr; - for( itr = mFCOSet.begin(); itr != mFCOSet.end(); itr++) + for( itr = mFCOSet.begin(); itr != mFCOSet.end(); ++itr) { pSerializer->WriteObjectDynCreate(itr->mpFCO); } @@ -286,7 +286,7 @@ bool cFCOIterImpl::IsEmpty() const void cFCOIterImpl::Next() const { ASSERT(mpSet != 0); - mIter++; + ++mIter; } diff --git a/src/fco/fcospecattr.h b/src/fco/fcospecattr.h index b369758..c212673 100644 --- a/src/fco/fcospecattr.h +++ b/src/fco/fcospecattr.h @@ -171,7 +171,7 @@ inline bool cFCOSpecAttrEmailIter::IsEmpty() const } inline void cFCOSpecAttrEmailIter::Next() const { - mIter++; + ++mIter; } inline const TSTRING& cFCOSpecAttrEmailIter::EmailAddress() const { diff --git a/src/fco/fcospechelper.cpp b/src/fco/fcospechelper.cpp index d701b70..24909ee 100644 --- a/src/fco/fcospechelper.cpp +++ b/src/fco/fcospechelper.cpp @@ -221,7 +221,7 @@ void cFCOSpecStopPointSet::Add(const cFCOName& name) break; default: - i++; + ++i; } } @@ -306,7 +306,7 @@ iFCOSpecHelper::CompareResult cFCOSpecStopPointSet::Compare(const iFCOSpecHelper std::set::const_iterator myIter = mStopPoints.begin(), rhsIter = pStopPtSet->mStopPoints.begin(); - for(; myIter != mStopPoints.end(); myIter++, rhsIter++) + for(; myIter != mStopPoints.end(); ++myIter, ++rhsIter) { if(*myIter != *rhsIter) return ((*myIter < *rhsIter) ? CMP_LT : CMP_GT); diff --git a/src/fco/fcospechelper.h b/src/fco/fcospechelper.h index af4ef29..f0ae60f 100644 --- a/src/fco/fcospechelper.h +++ b/src/fco/fcospechelper.h @@ -257,7 +257,7 @@ inline bool cFCOSpecStopPointIter::IsEmpty() const inline void cFCOSpecStopPointIter::Next() const { - mIter++; + ++mIter; } inline void cFCOSpecStopPointIter::Remove() diff --git a/src/fco/fcospeclist.cpp b/src/fco/fcospeclist.cpp index 1c1d971..735d73b 100644 --- a/src/fco/fcospeclist.cpp +++ b/src/fco/fcospeclist.cpp @@ -61,7 +61,7 @@ void cFCOSpecList::Clear() { std::list::iterator itr; - for (itr = mAddedList.begin(); itr != mAddedList.end(); itr++) + for (itr = mAddedList.begin(); itr != mAddedList.end(); ++itr) { itr->first->Release(); itr->second->Release(); @@ -227,7 +227,7 @@ void cFCOSpecListAddedIter::Remove() // the tricky part is finding the spec in the other list... std::list::iterator i; - for(i = mpSpecList->mCanonicalList.begin(); i != mpSpecList->mCanonicalList.end(); i++) + for(i = mpSpecList->mCanonicalList.begin(); i != mpSpecList->mCanonicalList.end(); ++i) { if(i->first == mIter->first) break; diff --git a/src/fco/genreswitcher.cpp b/src/fco/genreswitcher.cpp index 1702f98..98f04a5 100644 --- a/src/fco/genreswitcher.cpp +++ b/src/fco/genreswitcher.cpp @@ -223,7 +223,7 @@ cGenre::Genre cGenreSwitcher::StringToGenre( const wchar_t* wsz ) cGenreInfoVec::const_iterator cGenreInfoVec::find( cGenre::Genre g ) const { const_iterator i; - for( i = begin(); i != end(); i++ ) + for( i = begin(); i != end(); ++i ) { ASSERT( (*i)->m_ID != cGenre::GENRE_INVALID ); @@ -244,7 +244,7 @@ cGenreInfoVec::const_iterator cGenreInfoVec::find( const cGenreInfo* pGI ) const cGenreInfoVec::const_iterator cGenreInfoVec::find( const TSTRING& sGenre ) const { const_iterator i; - for( i = begin(); i != end(); i++ ) + for( i = begin(); i != end(); ++i ) { ASSERT( (*i)->m_ID != cGenre::GENRE_INVALID ); diff --git a/src/fs/fsparserutil.cpp b/src/fs/fsparserutil.cpp index c711234..7de1b0a 100644 --- a/src/fs/fsparserutil.cpp +++ b/src/fs/fsparserutil.cpp @@ -139,7 +139,7 @@ static inline void trim_leading_whitespace(std::string &str) void cFSParserUtil::InterpretFCOName( const std::list& l, cFCOName& nameOut ) const { TSTRING strT; - for( std::list::const_iterator i = l.begin(); i != l.end(); i++ ) + for( std::list::const_iterator i = l.begin(); i != l.end(); ++i ) strT += *i; #if USES_DEVICE_PATH diff --git a/src/fs/fspropdisplayer.cpp b/src/fs/fspropdisplayer.cpp index 312f403..6e465f3 100644 --- a/src/fs/fspropdisplayer.cpp +++ b/src/fs/fspropdisplayer.cpp @@ -151,7 +151,7 @@ void cFSPropDisplayer::Merge( const iFCOPropDisplayer* const ppd ) // merge mapping info for( INT64_TO_STRING_MAP::const_iterator iterUID = pfspd->uidToUsername.begin(); iterUID != pfspd->uidToUsername.end(); - iterUID++ + ++iterUID ) { AddUsernameMapping( iterUID->first, iterUID->second ); @@ -159,7 +159,7 @@ void cFSPropDisplayer::Merge( const iFCOPropDisplayer* const ppd ) for( INT64_TO_STRING_MAP::const_iterator iterGID = pfspd->gidToGroupname.begin(); iterGID != pfspd->gidToGroupname.end(); - iterGID++ + ++iterGID ) { AddGroupnameMapping( iterGID->first, iterGID->second ); @@ -401,7 +401,7 @@ void cFSPropDisplayer::Write( iSerializer* pSerializer ) const { // write UID mapping pSerializer->WriteInt32( uidToUsername.size() ); - for( INT64_TO_STRING_MAP::const_iterator iterUid = uidToUsername.begin(); iterUid != uidToUsername.end(); iterUid++ ) + for( INT64_TO_STRING_MAP::const_iterator iterUid = uidToUsername.begin(); iterUid != uidToUsername.end(); ++iterUid ) { pSerializer->WriteInt64( iterUid->first ); pSerializer->WriteString( iterUid->second ); @@ -409,7 +409,7 @@ void cFSPropDisplayer::Write( iSerializer* pSerializer ) const // write GID mapping pSerializer->WriteInt32( gidToGroupname.size() ); - for( INT64_TO_STRING_MAP::const_iterator iterGid = gidToGroupname.begin(); iterGid != gidToGroupname.end(); iterGid++ ) + for( INT64_TO_STRING_MAP::const_iterator iterGid = gidToGroupname.begin(); iterGid != gidToGroupname.end(); ++iterGid ) { pSerializer->WriteInt64( iterGid->first ); pSerializer->WriteString( iterGid->second ); diff --git a/src/tripwire/generatedb_t.cpp b/src/tripwire/generatedb_t.cpp index bfc31c4..7de5c82 100644 --- a/src/tripwire/generatedb_t.cpp +++ b/src/tripwire/generatedb_t.cpp @@ -78,7 +78,7 @@ void TestGenerateDb() // ok, time to integrity check! // cGenreSpecListVector::iterator at; - for( at = slv.begin(); at != slv.end(); at++ ) + for( at = slv.begin(); at != slv.end(); ++at ) { cGenerateDb::Execute( at->GetSpecList(), diff --git a/src/tripwire/integritycheck.cpp b/src/tripwire/integritycheck.cpp index ef599d6..224c14c 100644 --- a/src/tripwire/integritycheck.cpp +++ b/src/tripwire/integritycheck.cpp @@ -593,7 +593,7 @@ void cIntegrityCheck::ExecuteOnObjectList( const std::list& fcoNames, // iterate over all the objects to integrity check.. // std::list::const_iterator it; - for( it = fcoNames.begin(); it != fcoNames.end(); it++ ) + for( it = fcoNames.begin(); it != fcoNames.end(); ++it ) { TW_NOTIFY_VERBOSE( _T("%s%s\n"), TSS_GetString( cTripwire, tripwire::STR_NOTIFY_CHECKING ).c_str(), diff --git a/src/tripwire/integritycheck_t.cpp b/src/tripwire/integritycheck_t.cpp index a28f519..ed133b4 100644 --- a/src/tripwire/integritycheck_t.cpp +++ b/src/tripwire/integritycheck_t.cpp @@ -80,7 +80,7 @@ void TestIntegrityCheck() // ok, time to integrity check! // cGenreSpecListVector::iterator at; - for( at = slv.begin(); at != slv.end(); at++ ) + for( at = slv.begin(); at != slv.end(); ++at ) { cIntegrityCheck ic( at->GetGenre(), at->GetSpecList(), db, report, &et ); ic.Execute(); diff --git a/src/tripwire/mailmessage.cpp b/src/tripwire/mailmessage.cpp index 94b59f6..2830c4e 100644 --- a/src/tripwire/mailmessage.cpp +++ b/src/tripwire/mailmessage.cpp @@ -130,7 +130,7 @@ bool cMailMessage::GetAttachmentsAsString( std::string& s ) bool allOK = true; for( std::vector::const_iterator at = mvstrAttachments.begin(); at != mvstrAttachments.end(); - at++ ) + ++at ) { s += "\r\n"; @@ -349,7 +349,7 @@ cQuotedPrintableEncoding::Encode( const std::string& sIn, std::string::size_type lineLen = 0; for( at = sIn.begin(); at != sIn.end(); - at++, lineLen += _ENCODED_CHAR_LEN ) + ++at, lineLen += _ENCODED_CHAR_LEN ) { if( NeedsEncoding( *at ) ) { @@ -481,7 +481,7 @@ cMailMessageUtil::HasNonAsciiChars( const std::string& s ) { for( std::string::const_iterator at = s.begin(); at != s.end(); - at ++ ) + ++at ) { if( (unsigned char)*at > (unsigned char)0x7F ) return true; diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index 6c51144..5666533 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -1123,7 +1123,7 @@ int cTWModeIC::Execute(cErrorQueue* pQueue) // // now, we will iterate over the list, performing an integrity check for each genre // - for( cTWUtil::GenreObjList::iterator genreIter = listOut.begin(); genreIter != listOut.end(); genreIter++ ) + for( cTWUtil::GenreObjList::iterator genreIter = listOut.begin(); genreIter != listOut.end(); ++genreIter ) { dbIter.SeekToGenre( genreIter->first ); if( ! dbIter.Done() ) @@ -1134,7 +1134,7 @@ int cTWModeIC::Execute(cErrorQueue* pQueue) // I have to turn this into a list of cFCONames // std::list fcoNames; - for(cTWUtil::ObjList::iterator it = genreIter->second.begin(); it != genreIter->second.end(); it++) + for(cTWUtil::ObjList::iterator it = genreIter->second.begin(); it != genreIter->second.end(); ++it) { // if this is not an absolute path, warn and continue... // diff --git a/src/tw/dbexplore.cpp b/src/tw/dbexplore.cpp index 8897708..4d4692f 100644 --- a/src/tw/dbexplore.cpp +++ b/src/tw/dbexplore.cpp @@ -179,7 +179,7 @@ static void SplitString( const TSTRING& str, TCHAR c, std::vector& vStr vStrings.clear(); TSTRING::const_iterator i, prev; - for( prev = i = str.begin(); i != str.end(); i++ ) + for( prev = i = str.begin(); i != str.end(); ++i ) { if( *i == c ) { @@ -284,7 +284,7 @@ void cDbExplore::Execute( cFCODatabaseFileIter& dbIter ) GetNoun(noun); std::vector vDirs; SplitString( noun, pIter->GetParentName().GetDelimiter(), vDirs ); - for( std::vector::iterator i = vDirs.begin(); i != vDirs.end(); i++ ) + for( std::vector::iterator i = vDirs.begin(); i != vDirs.end(); ++i ) { if( i->compare( _T("..") ) == 0 ) diff --git a/src/tw/fcodatabasefile.cpp b/src/tw/fcodatabasefile.cpp index 1332f5c..d36a5c2 100644 --- a/src/tw/fcodatabasefile.cpp +++ b/src/tw/fcodatabasefile.cpp @@ -72,7 +72,7 @@ cFCODatabaseFile::cFCODatabaseFile() cFCODatabaseFile::~cFCODatabaseFile() { - for( DbList::iterator i = mDbList.begin(); i != mDbList.end(); i++ ) + for( DbList::iterator i = mDbList.begin(); i != mDbList.end(); ++i ) { delete *i; } @@ -152,7 +152,7 @@ void cFCODatabaseFile::Write(iSerializer* pSerializer) const //throw( eFCODbFile // // TODO -- the database is not really const-correct; therefore I have the sick casts below... // - for( DbList::iterator i = const_cast(&mDbList)->begin(); i != const_cast(&mDbList)->end(); i++ ) + for( DbList::iterator i = const_cast(&mDbList)->begin(); i != const_cast(&mDbList)->end(); ++i ) { pSerializer->WriteInt32 ( (*i)->mGenre ); pSerializer->WriteObject ( &(*i)->mGenreHeader ); @@ -193,7 +193,7 @@ void cFCODatabaseFile::AddGenre( cGenre::Genre genreId, cFCODatabaseFileIter* pI // // first, lets make sure this genre doesn't exist... // - for( DbList::iterator i = mDbList.begin(); i != mDbList.end(); i++ ) + for( DbList::iterator i = mDbList.begin(); i != mDbList.end(); ++i ) { if( (*i)->mGenre == genreId ) { @@ -254,7 +254,7 @@ void cFCODatabaseFileIter::SeekBegin() void cFCODatabaseFileIter::Next() { - mIter++; + ++mIter; } bool cFCODatabaseFileIter::Done() const diff --git a/src/tw/fcoreport.cpp b/src/tw/fcoreport.cpp index 4bc800d..b66c231 100644 --- a/src/tw/fcoreport.cpp +++ b/src/tw/fcoreport.cpp @@ -433,7 +433,7 @@ void cFCOReportSpecIter::SeekBegin() const void cFCOReportSpecIter::Next() const { ASSERT(mpData != 0); - mpData->mIter++; + ++(mpData->mIter); } bool cFCOReportSpecIter::Done() const @@ -450,7 +450,7 @@ const iFCOSpec* cFCOReportSpecIter::GetSpec() const bool cFCOReportSpecIter::SeekToSpec(const iFCOSpec* pSpec) { if (mpData) - for(mpData->mIter = mpData->mpList->begin(); mpData->mIter != mpData->mpList->end(); mpData->mIter++) + for(mpData->mIter = mpData->mpList->begin(); mpData->mIter != mpData->mpList->end(); ++(mpData->mIter)) { if(iFCOSpecUtil::FCOSpecEqual(*mpData->mIter->mpSpec, *pSpec)) return true; @@ -563,7 +563,7 @@ void cFCOReportChangeIter::SeekBegin() const void cFCOReportChangeIter::Next() const { ASSERT(mpData->mpList != 0); - mpData->mIter++; + ++(mpData->mIter); } bool cFCOReportChangeIter::Done() const @@ -707,7 +707,7 @@ void cFCOReport::AddSpec(cGenre::Genre genre, const iFCOSpec* pSpec, const cFCOS if (pIter && pIter->mpData && pIter->mpData->mpList == &genreIter->mSpecList) { pIter->mpData->mIter = genreIter->mSpecList.end(); - pIter->mpData->mIter--; + --(pIter->mpData->mIter); ASSERT(pIter->GetSpec() == node.mpSpec); } } diff --git a/src/tw/textreportviewer.cpp b/src/tw/textreportviewer.cpp index 2824536..d1e8b61 100644 --- a/src/tw/textreportviewer.cpp +++ b/src/tw/textreportviewer.cpp @@ -162,7 +162,7 @@ cTextReportViewer::~cTextReportViewer() { if( mfUpdate ) { - for( GenreList::iterator i = mFCOsRemoveFromReport.begin(); i != mFCOsRemoveFromReport.end(); i++ ) + for( GenreList::iterator i = mFCOsRemoveFromReport.begin(); i != mFCOsRemoveFromReport.end(); ++i ) { ASSERT( i->second != 0 ); i->second->clear(); @@ -1051,7 +1051,7 @@ void cTextReportViewer::RemoveFCOsFromReport() //throw (eTextReportViewer) // // see if any FCOs to remove are in this set // - for( iter = pFCOList->begin(); iter != pFCOList->end(); iter++ ) + for( iter = pFCOList->begin(); iter != pFCOList->end(); ++iter ) { fcoIter = pAddedSet->Lookup( *iter ); if( fcoIter ) @@ -1071,7 +1071,7 @@ void cTextReportViewer::RemoveFCOsFromReport() //throw (eTextReportViewer) // // see if any FCOs to remove are in this set // - for( iter = pFCOList->begin(); iter != pFCOList->end(); iter++ ) + for( iter = pFCOList->begin(); iter != pFCOList->end(); ++iter ) { fcoIter = pRemovedSet->Lookup( *iter ); if( fcoIter ) @@ -1084,7 +1084,7 @@ void cTextReportViewer::RemoveFCOsFromReport() //throw (eTextReportViewer) } - for( iter = pFCOList->begin(); iter != pFCOList->end(); iter++ ) + for( iter = pFCOList->begin(); iter != pFCOList->end(); ++iter ) { // search changed // get changed set iterator @@ -1110,7 +1110,7 @@ void cTextReportViewer::RemoveFCOsFromReport() //throw (eTextReportViewer) // int nFCOsToRemove = 0; cTextReportViewer::GenreList::const_iterator iter = mFCOsRemoveFromReport.begin(); - for( ; iter != mFCOsRemoveFromReport.end(); iter++ ) + for( ; iter != mFCOsRemoveFromReport.end(); ++iter ) nFCOsToRemove += iter->second->size(); if( nFCOsToRemove != nFCOsRemoved ) diff --git a/src/tw/twutil.cpp b/src/tw/twutil.cpp index 38656e8..62a25f3 100644 --- a/src/tw/twutil.cpp +++ b/src/tw/twutil.cpp @@ -1228,7 +1228,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob // iterate over all of the input... // - for( ObjList::const_iterator i = listIn.begin(); i != listIn.end(); i++ ) + for( ObjList::const_iterator i = listIn.begin(); i != listIn.end(); ++i ) { // first, try to interperate the current string as a genre name... // 17 Mar 99 mdb -- we now only do this if the string ends in a ':' @@ -1261,7 +1261,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob { // seek to right list; create it if it is not there... // - for( curIter = listOut.begin(); curIter != listOut.end(); curIter++ ) + for( curIter = listOut.begin(); curIter != listOut.end(); ++curIter ) { if( curIter->first == curGenre ) break; @@ -1282,7 +1282,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob // add this to the list; assert that it has not been added yet. // ObjList::iterator oi; - for( oi = curIter->second.begin(); oi != curIter->second.end(); oi++ ) + for( oi = curIter->second.begin(); oi != curIter->second.end(); ++oi ) { if( *oi == *i ) { diff --git a/src/twparser/genreparseinfo.cpp b/src/twparser/genreparseinfo.cpp index fa1fa51..ad64f43 100644 --- a/src/twparser/genreparseinfo.cpp +++ b/src/twparser/genreparseinfo.cpp @@ -108,7 +108,7 @@ bool cGenreParseInfo::RulePointAlreadyDefined( const cFCOName& fcoName ) bool fFound = false; // check start points - for( RuleListType::iterator i = mRuleList.begin(); i != mRuleList.end(); i++ ) + for( RuleListType::iterator i = mRuleList.begin(); i != mRuleList.end(); ++i ) { if( (*i)->GetName() == fcoName ) fFound = true; @@ -117,7 +117,7 @@ bool cGenreParseInfo::RulePointAlreadyDefined( const cFCOName& fcoName ) // check stop points if( ! fFound ) { - for( StopListType::iterator j = mStopList.begin(); j != mStopList.end(); j++ ) + for( StopListType::iterator j = mStopList.begin(); j != mStopList.end(); ++j ) { if( *j == fcoName ) fFound = true; diff --git a/src/twparser/parserhelper.cpp b/src/twparser/parserhelper.cpp index 62a600b..3415907 100644 --- a/src/twparser/parserhelper.cpp +++ b/src/twparser/parserhelper.cpp @@ -144,7 +144,7 @@ void cParserHelper::Finit( cGenreSpecListVector* pPolicy ) int nRulesInPolicy = 0; GenreContainer::iterator i; - for( i = mAph.begin(); i != mAph.end(); i++ ) + for( i = mAph.begin(); i != mAph.end(); ++i ) { cGenreSpecListPair slp; cGenre::Genre g = i->first; @@ -193,7 +193,7 @@ void cParserHelper::Finit( cGenreSpecListVector* pPolicy ) void cParserHelper::CleanUp() { GenreContainer::iterator i; - for( i = mAph.begin(); i != mAph.end(); i++ ) + for( i = mAph.begin(); i != mAph.end(); ++i ) delete i->second; while( ! cPreprocessor::Empty() ) cPreprocessor::PopState(); @@ -390,7 +390,7 @@ bool cParserUtil::AnyOfTheseHostsExists( cParseStringList* pList ) std::transform( strHostName.begin(), strHostName.end(), strHostName.begin(), _totlower ); // if the host name matches any in the list, return true - for( std::list::iterator iter = pList->begin(); iter != pList->end(); iter++ ) + for( std::list::iterator iter = pList->begin(); iter != pList->end(); ++iter ) { // want to do case-insensitive compare std::transform( (*iter).begin(), (*iter).end(), (*iter).begin(), _totlower ); @@ -531,7 +531,7 @@ void cParserUtil::CreateFCOSpecs( cGenre::Genre g, cGenreParseInfo* pgpi, cFCOSp // foreach rule std::list::iterator rule; - for (rule = pgpi->GetRules()->begin(); rule != pgpi->GetRules()->end(); rule++) + for (rule = pgpi->GetRules()->begin(); rule != pgpi->GetRules()->end(); ++rule) { // // create the spec with its the last element of its start point as its name. @@ -557,7 +557,7 @@ void cParserUtil::CreateFCOSpecs( cGenre::Genre g, cGenreParseInfo* pgpi, cFCOSp // set stop points cGenreParseInfo::StopListType::iterator stop; - for (stop = pgpi->GetStopList()->begin(); stop != pgpi->GetStopList()->end(); stop++) + for (stop = pgpi->GetStopList()->begin(); stop != pgpi->GetStopList()->end(); ++stop) { // add stop point if below start point cFCOName::Relationship relate = startpoint.GetRelationship(*stop); @@ -677,7 +677,7 @@ void cParserUtil::CreatePropVector( const TSTRING& strPropListC, class cFCOPropV TSTRING::const_iterator iter; TSTRING::size_type i; // index into string - for ( iter = strPropList.begin(), i = 0; iter != strPropList.end(); iter++, i++ ) + for ( iter = strPropList.begin(), i = 0; iter != strPropList.end(); ++iter, ++i ) { int propIndex = -1; // index into propvector @@ -825,7 +825,7 @@ cParseNamedAttrList* cParserHelper::GetGlobalAttrList() void cParserHelper::IncrementScopeStatementCount() { // must add count to ALL previous scopes. - for( ScopedAttrContainer::iterator i = mScopedAttrs.begin(); i != mScopedAttrs.end(); i++ ) + for( ScopedAttrContainer::iterator i = mScopedAttrs.begin(); i != mScopedAttrs.end(); ++i ) (*i)->IncrementStatementCount(); } diff --git a/src/twparser/parserobjects.cpp b/src/twparser/parserobjects.cpp index 909c56b..e29b086 100644 --- a/src/twparser/parserobjects.cpp +++ b/src/twparser/parserobjects.cpp @@ -211,7 +211,7 @@ void cParseSpecMaskList::Dump(cDebug &d) const { std::list::const_iterator ispec; - for (ispec = mList.begin(); ispec != mList.end(); ispec++) { + for (ispec = mList.begin(); ispec != mList.end(); ++ispec) { (*ispec)->Dump(d); } } @@ -295,7 +295,7 @@ cParseNamedAttrList::~cParseNamedAttrList() void cParseNamedAttrList::Clear() { - for( std::list::iterator iter = mList.begin(); iter != mList.end(); iter++ ) + for( std::list::iterator iter = mList.begin(); iter != mList.end(); ++iter ) { delete *iter; } @@ -307,7 +307,7 @@ cParseNamedAttrList::Dump(cDebug &d) const { // dump out each named attribute std::list::const_iterator iattr; - for (iattr = mList.begin(); iattr != mList.end(); iattr++) { + for (iattr = mList.begin(); iattr != mList.end(); ++iattr) { (*iattr)->Dump(d); } } @@ -339,7 +339,7 @@ cParseNamedAttrList::constListIter cParseNamedAttrList::Find( const cParseNamedA for( std::list< cParseNamedAttr * >::const_iterator iter = mList.begin(); iter != mList.end(); - iter++ + ++iter ) { if( (*iter)->GetName() == pa->GetName() ) @@ -356,7 +356,7 @@ void cParseNamedAttrList::MergeNoOverwrite( const cParseNamedAttrList* const pal if( pal ) { // foreach attribute in pal - for( constListIter newIter = pal->mList.begin(); newIter != pal->mList.end(); newIter++ ) + for( constListIter newIter = pal->mList.begin(); newIter != pal->mList.end(); ++newIter ) { // look for this attribute in this list constListIter thisIter = Find( *newIter ); @@ -384,7 +384,7 @@ const cParseNamedAttr* cParseNamedAttrList::Lookup( const TSTRING& tstrAttrName { constListIter i; - for( i = mList.begin(); i != mList.end(); i++) + for( i = mList.begin(); i != mList.end(); ++i) { if( 0 == tstrAttrName.compare( (*i)->GetName() ) ) { diff --git a/src/twparser/parserobjects.h b/src/twparser/parserobjects.h index 3100be9..4b52409 100644 --- a/src/twparser/parserobjects.h +++ b/src/twparser/parserobjects.h @@ -64,7 +64,7 @@ class iParserGenreUtil; // INLINE FUNCTIONS //========================================================================= -#define KILL_LIST(type, name) do { for( std::list::iterator iter = mList.begin(); iter != mList.end(); iter++ ) { delete *iter; } } while(0) +#define KILL_LIST(type, name) do { for( std::list::iterator iter = mList.begin(); iter != mList.end(); ++iter ) { delete *iter; } } while(0) /////////////////////////////////////////////////////////////////////////////// diff --git a/src/twprint/twprintcmdline.cpp b/src/twprint/twprintcmdline.cpp index 9e3fe8e..f3a435e 100644 --- a/src/twprint/twprintcmdline.cpp +++ b/src/twprint/twprintcmdline.cpp @@ -719,7 +719,7 @@ int cTWPrintDBMode::Execute(cErrorQueue* pQueue) // now, iterate through the list of objects... // cFCODatabaseFile::iterator dbIter( db ); - for( cTWUtil::GenreObjList::iterator genreIter = listOut.begin(); genreIter != listOut.end(); genreIter++ ) + for( cTWUtil::GenreObjList::iterator genreIter = listOut.begin(); genreIter != listOut.end(); ++genreIter ) { dbIter.SeekToGenre( genreIter->first ); if( ! dbIter.Done() ) @@ -731,7 +731,7 @@ int cTWPrintDBMode::Execute(cErrorQueue* pQueue) // // iterate over all the objects in this genre.... // - for(cTWUtil::ObjList::iterator it = genreIter->second.begin(); it != genreIter->second.end(); it++) + for(cTWUtil::ObjList::iterator it = genreIter->second.begin(); it != genreIter->second.end(); ++it) { try { diff --git a/src/twtest/displayencoder_t.cpp b/src/twtest/displayencoder_t.cpp index 39935d2..b2595d4 100644 --- a/src/twtest/displayencoder_t.cpp +++ b/src/twtest/displayencoder_t.cpp @@ -57,7 +57,7 @@ template< class CharT > bool IsPrintable( const std::basic_string< CharT >& str ) { const std::ctype< CharT > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - for( std::basic_string< CharT >::const_iterator at = str.begin(); at != str.end(); at++ ) + for( std::basic_string< CharT >::const_iterator at = str.begin(); at != str.end(); ++at ) { if( ! ct.is( std::ctype_base::print, *at ) ) // if not printable return false; diff --git a/src/twtest/textreportviewer_t.cpp b/src/twtest/textreportviewer_t.cpp index c6287e0..1d970d1 100644 --- a/src/twtest/textreportviewer_t.cpp +++ b/src/twtest/textreportviewer_t.cpp @@ -416,7 +416,7 @@ void MakeFile( TSTRING& strNameMakeMe ) pFSServices->MakeTempFilename( strNameMakeMe ); std::string strA; - for( TSTRING::iterator i = strNameMakeMe.begin(); i != strNameMakeMe.end(); i++ ) + for( TSTRING::iterator i = strNameMakeMe.begin(); i != strNameMakeMe.end(); ++i ) { char ach[6]; ASSERT( MB_CUR_MAX <= 6 ); diff --git a/src/twtest/unixfsservices_t.cpp b/src/twtest/unixfsservices_t.cpp index c7e852c..1a9280c 100644 --- a/src/twtest/unixfsservices_t.cpp +++ b/src/twtest/unixfsservices_t.cpp @@ -69,7 +69,7 @@ void TestUnixFSServices() std::vector ::iterator p; size_t n = 0; - for (p = v.begin(); p != v.end(); p++) { + for (p = v.begin(); p != v.end(); ++p) { d.TraceDetail(" %s\n", p->c_str()); n++; } diff --git a/src/util/stringencoder.cpp b/src/util/stringencoder.cpp index 22d72a2..d2bcf4f 100644 --- a/src/util/stringencoder.cpp +++ b/src/util/stringencoder.cpp @@ -120,7 +120,7 @@ TSTRING& cStringEncoder::Encode( const TSTRING& in, TSTRING& out ) // out.reserve( in.length() ); - for( TSTRING::const_iterator i = in.begin(); i != in.end(); i++ ) + for( TSTRING::const_iterator i = in.begin(); i != in.end(); ++i ) ce.EncodeChar( i, out ); return out; @@ -143,7 +143,7 @@ TSTRING& cStringEncoder::Unencode( const TSTRING& in, TSTRING& out ) out.reserve( in.length() ); TSTRING::const_iterator end = in.end(); - for( TSTRING::const_iterator i = in.begin(); i != end; i++ ) + for( TSTRING::const_iterator i = in.begin(); i != end; ++i ) out += ce.DecodeChar( i, end ); return out; From 911e051091e30dc439a97f36f5272c39bbf3a547 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 23 Mar 2017 23:45:20 -0700 Subject: [PATCH 24/43] Fix more warnings, & make TestFCOSpec() do something useful in non-debug builds --- src/fco/fcodatasourceiterimpl.cpp | 2 +- src/siggen/siggencmdline.cpp | 1 - src/tripwire/mailmessage.cpp | 4 +--- src/twcrypto/cryptoarchive.cpp | 14 ++------------ src/twtest/fcospec_t.cpp | 5 +++-- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/fco/fcodatasourceiterimpl.cpp b/src/fco/fcodatasourceiterimpl.cpp index b0cb892..8ed612b 100644 --- a/src/fco/fcodatasourceiterimpl.cpp +++ b/src/fco/fcodatasourceiterimpl.cpp @@ -52,7 +52,7 @@ //========================================================================= cFCODataSourceIterImpl::cFCODataSourceIterImpl() - : mpErrorBucket(0), mFlags(0) + : mpErrorBucket(0), mParentName(), mFlags(0) { } diff --git a/src/siggen/siggencmdline.cpp b/src/siggen/siggencmdline.cpp index 370d965..514fcc5 100644 --- a/src/siggen/siggencmdline.cpp +++ b/src/siggen/siggencmdline.cpp @@ -279,7 +279,6 @@ int cSiggenCmdLine::Init(cCmdLineParser& parser) case HELP: { return 0; - break; } case CRC32: { diff --git a/src/tripwire/mailmessage.cpp b/src/tripwire/mailmessage.cpp index 2830c4e..975fe50 100644 --- a/src/tripwire/mailmessage.cpp +++ b/src/tripwire/mailmessage.cpp @@ -231,10 +231,8 @@ bool cMailMessageUtil::ReadDate( TSTRING& strDateBuf ) #if HAVE_STRFTIME TCHAR szDate[1024]; - struct tm *tm = NULL; - time_t current_time = time(NULL); - tm = localtime ( ¤t_time ); + struct tm* tm = localtime ( ¤t_time ); const TCHAR* szFormat = _T("%a, %d %b %Y %H:%M:%S %z"); diff --git a/src/twcrypto/cryptoarchive.cpp b/src/twcrypto/cryptoarchive.cpp index d484360..65ae849 100644 --- a/src/twcrypto/cryptoarchive.cpp +++ b/src/twcrypto/cryptoarchive.cpp @@ -474,14 +474,8 @@ int cNullCryptoArchive::Write(const void* pSrc, int count) cRSAPublicKey* mpPublicKey; cRSAPrivateKey* mpPrivateKey; -cRSAArchive::cRSAArchive() +cRSAArchive::cRSAArchive() : mAction(MA_UNSTARTED), mpArchive(0), mpPublicKey(0), mpPrivaeKey(0), mpIDEA(new cIDEA) { - mAction = MA_UNSTARTED; - mpArchive = 0; - mpPublicKey = 0; - mpPrivateKey = 0; - - mpIDEA = new cIDEA; } cRSAArchive::~cRSAArchive() @@ -662,12 +656,8 @@ bool cRSAArchive::EndOfFile() // class cElGamalSigArchive cElGamalSigArchive::cElGamalSigArchive() +: mAction(MA_UNSTARTED), mpArchive(0), mpElGamal(0), mpPublicKey(0), mpPrivateKey(0) { - mAction = MA_UNSTARTED; - mpArchive = 0; - mpPublicKey = 0; - mpPrivateKey = 0; - mpElGamal = 0; } cElGamalSigArchive::~cElGamalSigArchive() diff --git a/src/twtest/fcospec_t.cpp b/src/twtest/fcospec_t.cpp index 80d73aa..d773a6f 100644 --- a/src/twtest/fcospec_t.cpp +++ b/src/twtest/fcospec_t.cpp @@ -34,6 +34,7 @@ #include "fco/stdfco.h" #include "fco/fcospec.h" #include "core/debug.h" +#include "twtest/test.h" #include using namespace std; @@ -43,9 +44,9 @@ void TestFCOSpec() cout << "Begin\tTestFCOSpec" << endl; // all it seems I can test here is that the default mask works const iFCOSpecMask* pDefMask = iFCOSpecMask::GetDefaultMask(); - ASSERT(pDefMask->GetName().compare(TSTRING(_T("Default"))) == 0); + TEST(pDefMask->GetName().compare(TSTRING(_T("Default"))) == 0); iFCO* pf1 = (iFCO*)0xbad, *pf2 = (iFCO*)0xcab; - ASSERT( pDefMask->Accept(pf1) && pDefMask->Accept(pf2) ); + TEST( pDefMask->Accept(pf1) && pDefMask->Accept(pf2) ); cout << "End\tTestFCOSpec" << endl; return; From 8cdca39103425e95332bf2d1191612c04a299142 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 25 Mar 2017 15:06:22 -0700 Subject: [PATCH 25/43] Prefer strl* string functions over strn* ones --- src/core/debug.cpp | 2 +- src/core/msystem.cpp | 14 ++++++++------ src/core/unixfsservices.cpp | 6 +++--- src/fco/fconametbl.cpp | 4 ++-- src/fco/signature.cpp | 8 ++++---- src/tripwire/smtpmailmessage.cpp | 4 ++-- src/twparser/yyparse.cpp | 4 ++-- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/core/debug.cpp b/src/core/debug.cpp index 7c285bb..a8be328 100644 --- a/src/core/debug.cpp +++ b/src/core/debug.cpp @@ -63,7 +63,7 @@ cDebug::cDebug(const char* label) cDebug::cDebug(const cDebug &rhs) { - strncpy(mLabel, rhs.mLabel, MAX_LABEL); + strlcpy(mLabel, rhs.mLabel, MAX_LABEL); } cDebug::~cDebug() diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index c551aee..8aa12fa 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -225,9 +225,10 @@ char *getenv(); /* get variable from environment */ /* * allocate space for the string, and copy if successful */ - if ((p = (char*)malloc((unsigned)((strlen(str)+1)*sizeof(char)))) + size_t p_size = (strlen(str)+1)*sizeof(char); + if ((p = (char*)malloc((unsigned)(p_size))) != NULL) - (void) strcpy(p, str); + (void) strlcpy(p, str, p_size); return(p); } #endif @@ -402,21 +403,22 @@ char *env; * just include it from the current environment * (if not defined there, don't define it here) */ + size_t p_size=0; if (strchr(env, '=') == NULL){ /* is it defined locally? */ if ((q = getenv(env)) == NULL){ /* no -- don't define it here */ return(SE_NONE); } - else if ((p = (char*)malloc((unsigned) (strlen(env)+strlen(q)+2))) + else if ((p = (char*)malloc((unsigned) (p_size = (strlen(env)+strlen(q)+2)))) == NULL){ ERMSG("ran out of memory"); return(SE_NOMEM); } else{ - (void) strcpy(p, env); - (void) strcat(p, "="); - (void) strcat(p, q); + (void) strlcpy(p, env, p_size); + (void) strlcat(p, "=", p_size); + (void) strlcat(p, q, p_size); } } else if ((p = strdup(env)) == NULL){ diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index 6ebf4d1..ca6493f 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -264,7 +264,7 @@ TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const throw(eFSSe char szTemplate[iFSServices::TW_MAX_PATH]; int fd; - strncpy( szTemplate, strName.c_str(), iFSServices::TW_MAX_PATH ); + strlcpy( szTemplate, strName.c_str(), iFSServices::TW_MAX_PATH ); #ifdef HAVE_MKSTEMP // create temp filename and check to see if mkstemp failed @@ -605,7 +605,7 @@ bool cUnixFSServices::GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const void cUnixFSServices::ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) const { TCHAR szPerm[11]; //10 permission bits plus the NULL - strncpy( szPerm, _T("----------"), 11); + strlcpy( szPerm, _T("----------"), 11); ASSERT( sizeof(unsigned short) <= sizeof(uint32) ); // We do this in case an "unsigned short" is ever larger than the @@ -912,7 +912,7 @@ bool util_PathFind( TSTRING& strFullPath, const TSTRING& strFilename ) // // get the path environment variable // - TCHAR* pszPathVar = _tgetenv("PATH"); + TCHAR* pszPathVar = getenv("PATH"); if( pszPathVar != NULL ) { // diff --git a/src/fco/fconametbl.cpp b/src/fco/fconametbl.cpp index c4e2ba8..edc2c8f 100644 --- a/src/fco/fconametbl.cpp +++ b/src/fco/fconametbl.cpp @@ -112,7 +112,7 @@ void cFCONameTblNode::SetString(const TSTRING& newStr) size_t alloc_size = sizeof(TCHAR)*(newStr.length()+1); mpString = (TCHAR*)util_AllocMem(alloc_size); - strncpy( mpString, newStr.c_str(), alloc_size ); + strlcpy( mpString, newStr.c_str(), alloc_size ); // NOTE -- the lower case pointer is now invalid. } @@ -187,7 +187,7 @@ cFCONameTblNode* cFCONameTbl::CreateNode(const TSTRING& nodeName) // TODO:BAM -- does this have any meaning in mb? for(i = lowStr.begin(); i != lowStr.end(); ++i) { - *i = _totlower(*i); + *i = tolower(*i); } // see if this exists in the table (it could potentially look up itself!) if(mTable.Lookup(lowStr.c_str(), pLowerNode)) diff --git a/src/fco/signature.cpp b/src/fco/signature.cpp index 27e59f9..4f8dd1c 100644 --- a/src/fco/signature.cpp +++ b/src/fco/signature.cpp @@ -557,7 +557,7 @@ TSTRING cMD5Signature::AsStringHex() const for(int i = 0; i < SIG_BYTE_SIZE; ++i) { snprintf(stringBuffer, 128, _T("%02lx"), (unsigned long)dbuf[i]); - strncat(sigStringOut, stringBuffer, 128); + strlcat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -680,7 +680,7 @@ TSTRING cSHASignature::AsStringHex() const for (int i=0; i < SIG_UINT32_SIZE*(int)sizeof(uint32); ++i) { snprintf(stringBuffer, 128, _T("%02x"), dbuf[i]); - strncat(sigStringOut, stringBuffer, 128); + strlcat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -755,7 +755,7 @@ TSTRING cSHASignature::AsStringHex() const for (int i=0; i < SIG_UINT32_SIZE; ++i) { snprintf(stringBuffer, 128, _T("%08x"), mSHAInfo.digest[i]); - strncat(sigStringOut, stringBuffer, 128); + strlcat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -857,7 +857,7 @@ TSTRING cHAVALSignature::AsStringHex() const for (int i=0; i < SIG_BYTE_SIZE; ++i) { snprintf(stringBuffer, 128, _T("%02x"), mSignature[i]); - strncat(sigStringOut, stringBuffer, 128); + strlcat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); diff --git a/src/tripwire/smtpmailmessage.cpp b/src/tripwire/smtpmailmessage.cpp index 9e63bc7..655e11f 100644 --- a/src/tripwire/smtpmailmessage.cpp +++ b/src/tripwire/smtpmailmessage.cpp @@ -90,7 +90,7 @@ static int gethostname( char* name, int namelen ) if ( strlen( myname.nodename ) < (unsigned int)namelen ) { - strncpy( name, myname.nodename, namelen ); + strlcpy( name, myname.nodename, namelen ); return 0; } else @@ -100,7 +100,7 @@ static int gethostname( char* name, int namelen ) // equivalent of SOCKET_ERROR } #else - strncpy(name, "localhost", namelen); + strlcpy(name, "localhost", namelen); #endif } diff --git a/src/twparser/yyparse.cpp b/src/twparser/yyparse.cpp index 9deb903..806f7a7 100644 --- a/src/twparser/yyparse.cpp +++ b/src/twparser/yyparse.cpp @@ -1393,7 +1393,7 @@ yy_parse::yyExpandName(int num, int isrule, char * buf, int len) for (endp = buf + len - 8; *s; s++) { if (buf >= endp) { /* too large: return 0 */ - full: (void) strncpy(buf, " ...\n", len); + full: (void) strlcpy(buf, " ...\n", len); return 0; } else if (*s == '%') { /* nonterminal */ type = 0; @@ -1423,7 +1423,7 @@ yy_parse::yyExpandName(int num, int isrule, char * buf, int len) if ((i = strlen(cp)) + buf > endp) goto full; - (void) strncpy(buf, cp, len); + (void) strlcpy(buf, cp, len); buf += i; } else *buf++ = *s; From 7ce1df0a046ae758af27f78ae67f81da06ee36ce Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 25 Mar 2017 15:31:47 -0700 Subject: [PATCH 26/43] Remove the few remaining exception specifications, since they're deprecated in C++11 & cause warnings in GCC 7 --- src/core/fsservices.h | 12 ++++++------ src/core/unixfsservices.cpp | 18 +++++++++--------- src/core/unixfsservices.h | 12 ++++++------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/core/fsservices.h b/src/core/fsservices.h index 0aed4c1..f2f4249 100644 --- a/src/core/fsservices.h +++ b/src/core/fsservices.h @@ -241,14 +241,14 @@ class iFSServices //////////////////////////////////////// // major filesystem functions //////////////////////////////////////// - virtual void Stat( const TSTRING& strFileName, cFSStatArgs& pStat ) const throw( eFSServices ) = 0; + virtual void Stat( const TSTRING& strFileName, cFSStatArgs& pStat ) const = 0; // fills out the cFSStatArgs structure with the stat info for the named file - virtual void GetTempDirName( TSTRING& strName ) const throw( eFSServices ) = 0; + virtual void GetTempDirName( TSTRING& strName ) const = 0; // makes directory if it doesn't exist already. Dirname will end with a delimiter ( '/' ) virtual void SetTempDirName( TSTRING& tmpName ) = 0; - virtual TSTRING& MakeTempFilename( TSTRING& strName ) const throw( eFSServices ) = 0; + virtual TSTRING& MakeTempFilename( TSTRING& strName ) const = 0; // create temporary file // TSTRING must have the form ("baseXXXXXX"), where the X's are replaced with // characters to make it a unique file. There must be at least 6 Xs. @@ -259,7 +259,7 @@ class iFSServices //////////////////////////////////////// virtual void GetHostID( TSTRING& name ) const = 0; - virtual void GetMachineName( TSTRING& name ) const throw(eFSServices) = 0; + virtual void GetMachineName( TSTRING& name ) const = 0; virtual void GetMachineNameFullyQualified( TSTRING& name ) const = 0; @@ -271,11 +271,11 @@ class iFSServices //////////////////////////////////////// // directory specific functions //////////////////////////////////////// - virtual void ReadDir( const TSTRING& strName, std::vector &vDirContents, bool bFullPaths = true ) const throw( eFSServices ) = 0; + virtual void ReadDir( const TSTRING& strName, std::vector &vDirContents, bool bFullPaths = true ) const = 0; // puts the contents of the specified directory, except for . and .., into the supplied vector. // if bFullPaths is true, then the vector contains fully qualified path names; otherwise, it only contains the // short names. - virtual void GetCurrentDir( TSTRING& strCurDir ) const throw( eFSServices ) = 0; + virtual void GetCurrentDir( TSTRING& strCurDir ) const = 0; // returns the current working directory diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index ca6493f..d5b87c0 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -183,10 +183,10 @@ TCHAR cUnixFSServices::GetPathSeparator() const } #if !USES_DEVICE_PATH -void cUnixFSServices::ReadDir(const TSTRING& strFilename, std::vector &v, bool bFullPaths) const throw(eFSServices) +void cUnixFSServices::ReadDir(const TSTRING& strFilename, std::vector &v, bool bFullPaths) const { #else -void cUnixFSServices::ReadDir(const TSTRING& strFilenameC, std::vector& v, bool bFullPaths) const throw(eFSServices) +void cUnixFSServices::ReadDir(const TSTRING& strFilenameC, std::vector& v, bool bFullPaths) const { TSTRING strFilename = cDevicePath::AsNative(strFilenameC); #endif @@ -237,7 +237,7 @@ void cUnixFSServices::ReadDir(const TSTRING& strFilenameC, std::vector& } /* needs to and with S_IFMT, check EQUALITY with S_*, and return more types -cFSStatArgs::FileType cUnixFSServices::GetFileType(const cFCOName &filename) throw(eFSServices) +cFSStatArgs::FileType cUnixFSServices::GetFileType(const cFCOName &filename) { cFSStatArgs stat; Stat(filename, stat); @@ -245,7 +245,7 @@ cFSStatArgs::FileType cUnixFSServices::GetFileType(const cFCOName &filename) thr } */ -void cUnixFSServices::GetCurrentDir( TSTRING& strCurDir ) const throw(eFSServices) +void cUnixFSServices::GetCurrentDir( TSTRING& strCurDir ) const { TCHAR pathname[iFSServices::TW_MAX_PATH]; pathname[0] = '\0'; @@ -258,7 +258,7 @@ void cUnixFSServices::GetCurrentDir( TSTRING& strCurDir ) const throw(eFSService } -TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const throw(eFSServices) +TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const { char* pchTempFileName; char szTemplate[iFSServices::TW_MAX_PATH]; @@ -295,7 +295,7 @@ TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const throw(eFSSe return( strName ); } -void cUnixFSServices::GetTempDirName( TSTRING& strName ) const throw(eFSServices) +void cUnixFSServices::GetTempDirName( TSTRING& strName ) const { strName = mTempPath; } @@ -307,10 +307,10 @@ void cUnixFSServices::SetTempDirName(TSTRING& tmpPath) { #if !USES_DEVICE_PATH -void cUnixFSServices::Stat( const TSTRING& strName, cFSStatArgs &stat ) const throw(eFSServices) +void cUnixFSServices::Stat( const TSTRING& strName, cFSStatArgs &stat ) const { #else -void cUnixFSServices::Stat( const TSTRING& strNameC, cFSStatArgs& stat) const throw(eFSServices) +void cUnixFSServices::Stat( const TSTRING& strNameC, cFSStatArgs& stat) const { TSTRING strName = cDevicePath::AsNative(strNameC); #endif @@ -375,7 +375,7 @@ void cUnixFSServices::Stat( const TSTRING& strNameC, cFSStatArgs& stat) const th else stat.mFileType = cFSStatArgs::TY_INVALID; } -void cUnixFSServices::GetMachineName( TSTRING& strName ) const throw( eFSServices ) +void cUnixFSServices::GetMachineName( TSTRING& strName ) const { #if HAVE_SYS_UTSNAME_H struct utsname namebuf; diff --git a/src/core/unixfsservices.h b/src/core/unixfsservices.h index c0fd1bc..51e6c51 100644 --- a/src/core/unixfsservices.h +++ b/src/core/unixfsservices.h @@ -83,16 +83,16 @@ class cUnixFSServices : public iFSServices //////////////////////////////////////// // major filesystem functions //////////////////////////////////////// - virtual void Stat( const TSTRING& strFileName, cFSStatArgs& pStat ) const throw( eFSServices ); + virtual void Stat( const TSTRING& strFileName, cFSStatArgs& pStat ) const ; // fills out the cFSStatArgs structure with the stat info for the named file - virtual void GetTempDirName( TSTRING& strName ) const throw( eFSServices ); + virtual void GetTempDirName( TSTRING& strName ) const ; // makes directory if it doesn't exist already. Dirname will end with a delimiter ( '/' ) virtual void SetTempDirName(TSTRING& tmpName); // set the default dir name which GetTempDirName will use... - virtual TSTRING& MakeTempFilename( TSTRING& strName ) const throw( eFSServices ); + virtual TSTRING& MakeTempFilename( TSTRING& strName ) const ; // create temporary file // strName must have the form ("baseXXXXXX"), where the X's are replaced with // characters to make it a unique file. There must be at least 6 Xs. @@ -103,7 +103,7 @@ class cUnixFSServices : public iFSServices //////////////////////////////////////// virtual void GetHostID( TSTRING& name ) const; - virtual void GetMachineName( TSTRING& name) const throw(eFSServices); + virtual void GetMachineName( TSTRING& name) const; virtual void GetMachineNameFullyQualified( TSTRING& name ) const; @@ -115,9 +115,9 @@ class cUnixFSServices : public iFSServices //////////////////////////////////////// // directory specific functions //////////////////////////////////////// - virtual void ReadDir( const TSTRING& strName, std::vector &vDirContents, bool bFullPaths = true ) const throw( eFSServices ); + virtual void ReadDir( const TSTRING& strName, std::vector &vDirContents, bool bFullPaths = true ) const; // puts the contents of the specified directory, except for . and .., into the supplied vector. - virtual void GetCurrentDir( TSTRING& strCurDir ) const throw( eFSServices ); + virtual void GetCurrentDir( TSTRING& strCurDir ) const; // returns the current working directory From e04b97132bc5e9c6781eb942c4e1f7f44abaad1c Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 25 Mar 2017 16:02:51 -0700 Subject: [PATCH 27/43] Ok, actually don't use strl* string functions since they're a BSD-ism & Linux doesn't have them. --- src/core/debug.cpp | 2 +- src/core/msystem.cpp | 8 ++++---- src/core/unixfsservices.cpp | 4 ++-- src/fco/fconametbl.cpp | 2 +- src/fco/signature.cpp | 16 ++++++++-------- src/tripwire/smtpmailmessage.cpp | 4 ++-- src/twparser/yyparse.cpp | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/core/debug.cpp b/src/core/debug.cpp index a8be328..7c285bb 100644 --- a/src/core/debug.cpp +++ b/src/core/debug.cpp @@ -63,7 +63,7 @@ cDebug::cDebug(const char* label) cDebug::cDebug(const cDebug &rhs) { - strlcpy(mLabel, rhs.mLabel, MAX_LABEL); + strncpy(mLabel, rhs.mLabel, MAX_LABEL); } cDebug::~cDebug() diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index 8aa12fa..f3dfba3 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -228,7 +228,7 @@ char *getenv(); /* get variable from environment */ size_t p_size = (strlen(str)+1)*sizeof(char); if ((p = (char*)malloc((unsigned)(p_size))) != NULL) - (void) strlcpy(p, str, p_size); + (void) strncpy(p, str, p_size); return(p); } #endif @@ -416,9 +416,9 @@ char *env; return(SE_NOMEM); } else{ - (void) strlcpy(p, env, p_size); - (void) strlcat(p, "=", p_size); - (void) strlcat(p, q, p_size); + (void) strncpy(p, env, p_size); + (void) strncat(p, "=", p_size); + (void) strncat(p, q, p_size); } } else if ((p = strdup(env)) == NULL){ diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index d5b87c0..4843059 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -264,7 +264,7 @@ TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const char szTemplate[iFSServices::TW_MAX_PATH]; int fd; - strlcpy( szTemplate, strName.c_str(), iFSServices::TW_MAX_PATH ); + strncpy( szTemplate, strName.c_str(), iFSServices::TW_MAX_PATH ); #ifdef HAVE_MKSTEMP // create temp filename and check to see if mkstemp failed @@ -605,7 +605,7 @@ bool cUnixFSServices::GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const void cUnixFSServices::ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) const { TCHAR szPerm[11]; //10 permission bits plus the NULL - strlcpy( szPerm, _T("----------"), 11); + strncpy( szPerm, _T("----------"), 9); ASSERT( sizeof(unsigned short) <= sizeof(uint32) ); // We do this in case an "unsigned short" is ever larger than the diff --git a/src/fco/fconametbl.cpp b/src/fco/fconametbl.cpp index edc2c8f..a331533 100644 --- a/src/fco/fconametbl.cpp +++ b/src/fco/fconametbl.cpp @@ -112,7 +112,7 @@ void cFCONameTblNode::SetString(const TSTRING& newStr) size_t alloc_size = sizeof(TCHAR)*(newStr.length()+1); mpString = (TCHAR*)util_AllocMem(alloc_size); - strlcpy( mpString, newStr.c_str(), alloc_size ); + strncpy( mpString, newStr.c_str(), alloc_size ); // NOTE -- the lower case pointer is now invalid. } diff --git a/src/fco/signature.cpp b/src/fco/signature.cpp index 4f8dd1c..4278ed1 100644 --- a/src/fco/signature.cpp +++ b/src/fco/signature.cpp @@ -550,14 +550,14 @@ TSTRING cMD5Signature::AsStringHex() const TSTRING ret; TCHAR stringBuffer[128]; - TCHAR sigStringOut[128]; + TCHAR sigStringOut[129]; sigStringOut[0] = '\0'; uint8 *dbuf = (uint8 *)md5_digest; for(int i = 0; i < SIG_BYTE_SIZE; ++i) { snprintf(stringBuffer, 128, _T("%02lx"), (unsigned long)dbuf[i]); - strlcat(sigStringOut, stringBuffer, 128); + strncat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -673,14 +673,14 @@ TSTRING cSHASignature::AsStringHex() const TSTRING ret; TCHAR stringBuffer[128]; - TCHAR sigStringOut[128]; + TCHAR sigStringOut[129]; sigStringOut[0] = '\0'; uint8 *dbuf = (uint8 *)sha_digest; for (int i=0; i < SIG_UINT32_SIZE*(int)sizeof(uint32); ++i) { snprintf(stringBuffer, 128, _T("%02x"), dbuf[i]); - strlcat(sigStringOut, stringBuffer, 128); + strncat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -749,13 +749,13 @@ TSTRING cSHASignature::AsStringHex() const TSTRING ret; TCHAR stringBuffer[128]; - TCHAR sigStringOut[128]; + TCHAR sigStringOut[129]; sigStringOut[0] = '\0'; for (int i=0; i < SIG_UINT32_SIZE; ++i) { snprintf(stringBuffer, 128, _T("%08x"), mSHAInfo.digest[i]); - strlcat(sigStringOut, stringBuffer, 128); + strncat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); @@ -851,13 +851,13 @@ TSTRING cHAVALSignature::AsStringHex() const TSTRING ret; TCHAR stringBuffer[128]; - TCHAR sigStringOut[128]; + TCHAR sigStringOut[129]; sigStringOut[0] = _T('\0'); for (int i=0; i < SIG_BYTE_SIZE; ++i) { snprintf(stringBuffer, 128, _T("%02x"), mSignature[i]); - strlcat(sigStringOut, stringBuffer, 128); + strncat(sigStringOut, stringBuffer, 128); } ret.append(sigStringOut); diff --git a/src/tripwire/smtpmailmessage.cpp b/src/tripwire/smtpmailmessage.cpp index 655e11f..9e63bc7 100644 --- a/src/tripwire/smtpmailmessage.cpp +++ b/src/tripwire/smtpmailmessage.cpp @@ -90,7 +90,7 @@ static int gethostname( char* name, int namelen ) if ( strlen( myname.nodename ) < (unsigned int)namelen ) { - strlcpy( name, myname.nodename, namelen ); + strncpy( name, myname.nodename, namelen ); return 0; } else @@ -100,7 +100,7 @@ static int gethostname( char* name, int namelen ) // equivalent of SOCKET_ERROR } #else - strlcpy(name, "localhost", namelen); + strncpy(name, "localhost", namelen); #endif } diff --git a/src/twparser/yyparse.cpp b/src/twparser/yyparse.cpp index 806f7a7..9deb903 100644 --- a/src/twparser/yyparse.cpp +++ b/src/twparser/yyparse.cpp @@ -1393,7 +1393,7 @@ yy_parse::yyExpandName(int num, int isrule, char * buf, int len) for (endp = buf + len - 8; *s; s++) { if (buf >= endp) { /* too large: return 0 */ - full: (void) strlcpy(buf, " ...\n", len); + full: (void) strncpy(buf, " ...\n", len); return 0; } else if (*s == '%') { /* nonterminal */ type = 0; @@ -1423,7 +1423,7 @@ yy_parse::yyExpandName(int num, int isrule, char * buf, int len) if ((i = strlen(cp)) + buf > endp) goto full; - (void) strlcpy(buf, cp, len); + (void) strncpy(buf, cp, len); buf += i; } else *buf++ = *s; From 76868c5ccca1669f4497776e5adffae5c576bd5f Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 25 Mar 2017 19:40:54 -0700 Subject: [PATCH 28/43] Resolve assorted GCC 7 warnings --- src/core/displayencoder.cpp | 2 +- src/core/ntmbs.cpp | 2 +- src/tw/twstrings.cpp | 4 ++-- src/twadmin/keygeneration.cpp | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/displayencoder.cpp b/src/core/displayencoder.cpp index 3b3536d..0bca15c 100644 --- a/src/core/displayencoder.cpp +++ b/src/core/displayencoder.cpp @@ -568,7 +568,7 @@ TCHAR cCharEncoderUtil::hex_to_char( TSTRING::const_iterator first, if( ss.bad() || ss.fail() ) ThrowAndAssert( eBadHexConversion( TSTRING( first, last ) ) ); - if( (TCHAR)ch > max_char || (TCHAR)ch < min_char ) + if( ch > (unsigned long)max_char || ch < (unsigned long)min_char ) ThrowAndAssert( eBadHexConversion( TSTRING( first, last ) ) ); return (TCHAR)ch; diff --git a/src/core/ntmbs.cpp b/src/core/ntmbs.cpp index 97202cf..beaf31c 100644 --- a/src/core/ntmbs.cpp +++ b/src/core/ntmbs.cpp @@ -96,7 +96,7 @@ tss::mbsdec( const_ntmbs_t beg, const_ntmbs_t curr ) const_ntmbs_t prev = curr - 1; for ( ; prev > beg && ::mblen( (char*)prev, curr - prev ) == -1; --prev ); - if ( curr - prev > MB_CUR_MAX ) + if ( (size_t)(curr - prev) > MB_CUR_MAX ) { prev = (curr - 1); diff --git a/src/tw/twstrings.cpp b/src/tw/twstrings.cpp index 262576b..da4637b 100644 --- a/src/tw/twstrings.cpp +++ b/src/tw/twstrings.cpp @@ -243,8 +243,8 @@ TSS_BeginStringtable( cTW ) TSS_StringEntry( tw::STR_COPYRIGHT, TSS_COPYRIGHT_NOTICE ), TSS_StringEntry( tw::STR_TSS_PRODUCT_NAME, TSS_PRODUCT_NAME BUILD_NUM UNICODE_STR DEBUG_STR ), - TSS_StringEntry( tw::STR_VERSION, TSS_PRODUCT_NAME BUILD_NUM UNICODE_STR DEBUG_STR _T(" built for "TARGET_OS"\n\n") TSS_COPYRIGHT_NOTICE ), - TSS_StringEntry( tw::STR_VERSION_LONG, TSS_PRODUCT_NAME BUILD_NUM UNICODE_STR DEBUG_STR _T(" built for "TARGET_OS"\n\n") TSS_COPYRIGHT_NOTICE_LONG ), + TSS_StringEntry( tw::STR_VERSION, TSS_PRODUCT_NAME BUILD_NUM UNICODE_STR DEBUG_STR _T(" built for " TARGET_OS "\n\n") TSS_COPYRIGHT_NOTICE ), + TSS_StringEntry( tw::STR_VERSION_LONG, TSS_PRODUCT_NAME BUILD_NUM UNICODE_STR DEBUG_STR _T(" built for " TARGET_OS "\n\n") TSS_COPYRIGHT_NOTICE_LONG ), TSS_EndStringtable( cTW ) diff --git a/src/twadmin/keygeneration.cpp b/src/twadmin/keygeneration.cpp index 600f3a8..b858d4e 100644 --- a/src/twadmin/keygeneration.cpp +++ b/src/twadmin/keygeneration.cpp @@ -158,6 +158,8 @@ bool GenerateKey(const TCHAR* keyPath, wc16_string passphrase, const cElGamalSig { case tGK::FILE_WRITE_ERROR: TCERR << std::endl << TSS_GetString(cTWAdmin, twadmin::STR_ERR2_KEYGEN_FILEWRITE) << gk.keyPath << std::endl; + break; + default: TCERR << std::endl << TSS_GetString(cTWAdmin, twadmin::STR_ERR2_KEYGEN) << gk.keyPath << TSS_GetString(cTWAdmin, twadmin::STR_ERR2_KEYGEN2) << std::endl; From da8748b6f23eb334738ef55ba337d5b597faeac0 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 25 Mar 2017 23:41:37 -0700 Subject: [PATCH 29/43] fix file mode printing --- src/core/unixfsservices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index 4843059..54595e4 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -604,8 +604,8 @@ bool cUnixFSServices::GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const // void cUnixFSServices::ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) const { - TCHAR szPerm[11]; //10 permission bits plus the NULL - strncpy( szPerm, _T("----------"), 9); + TCHAR szPerm[12]; //10 permission bits plus the NULL + strncpy( szPerm, _T("----------"), 11); ASSERT( sizeof(unsigned short) <= sizeof(uint32) ); // We do this in case an "unsigned short" is ever larger than the From c931a13ecd544b76416e68829b6df25fb639f2ac Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 26 Mar 2017 00:06:09 -0700 Subject: [PATCH 30/43] Disable unused tss::mbsdec() --- src/core/ntmbs.cpp | 4 ++-- src/core/ntmbs.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/ntmbs.cpp b/src/core/ntmbs.cpp index beaf31c..94de08c 100644 --- a/src/core/ntmbs.cpp +++ b/src/core/ntmbs.cpp @@ -58,7 +58,7 @@ // NTMBS Utils -- Definition //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#if 0 /* * TSS::mbsdec * @@ -117,7 +117,7 @@ tss::mbsdec( const_ntmbs_t beg, const_ntmbs_t curr ) return (ntmbs_t)prev; } - +#endif /* * TSS::mbsinc diff --git a/src/core/ntmbs.h b/src/core/ntmbs.h index d3cc036..4b792f0 100644 --- a/src/core/ntmbs.h +++ b/src/core/ntmbs.h @@ -117,11 +117,12 @@ TSS_EXCEPTION( eCharacter, eError ); TSS_EXCEPTION( eCharacterEncoding, eCharacter ); + namespace tss { /// Specific Routines (Add as needed) - ntmbs_t mbsdec( const_ntmbs_t, const_ntmbs_t ); + //ntmbs_t mbsdec( const_ntmbs_t, const_ntmbs_t ); ntmbs_t mbsinc( const_ntmbs_t ); size_t mbsbytes( const_ntmbs_t, size_t ); From be0b374cada281be15565798c14fa5751c32747a Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 26 Mar 2017 00:28:04 -0700 Subject: [PATCH 31/43] Tweak le_set() for clarity in msystem.cpp --- src/core/msystem.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index f3dfba3..ae0179d 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -382,7 +382,7 @@ char *env; register int n; /* where a previous definition is */ /* - * seeif youneed to create the environment list + * see if you need to create the environment list */ if (sz_envp == 0){ if ((envp = c2alloc((const char**)envp, &sz_envp)) == NULL){ @@ -404,18 +404,23 @@ char *env; * (if not defined there, don't define it here) */ size_t p_size=0; - if (strchr(env, '=') == NULL){ + if (strchr(env, '=') == NULL) { + + q = getenv(env); + /* is it defined locally? */ - if ((q = getenv(env)) == NULL){ + if (NULL == q) { /* no -- don't define it here */ return(SE_NONE); } - else if ((p = (char*)malloc((unsigned) (p_size = (strlen(env)+strlen(q)+2)))) - == NULL){ + + size_t p_size = strlen(env) + strlen(q) + 2; + + if ((p = (char*)malloc((unsigned)(p_size))) == NULL) { ERMSG("ran out of memory"); return(SE_NOMEM); } - else{ + else { (void) strncpy(p, env, p_size); (void) strncat(p, "=", p_size); (void) strncat(p, q, p_size); From cdb7310daea04e0169f724d32d7798e330d1485d Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 26 Mar 2017 20:16:37 -0700 Subject: [PATCH 32/43] Enable & (at least partly) fix charutil, displayencoder, & policyparser tests, which weren't running until now. --- src/twtest/charutil_t.cpp | 85 +++--- src/twtest/displayencoder_t.cpp | 484 ++++++++++++++++---------------- src/twtest/policyparser_t.cpp | 53 +++- src/twtest/test.cpp | 47 ++-- 4 files changed, 338 insertions(+), 331 deletions(-) diff --git a/src/twtest/charutil_t.cpp b/src/twtest/charutil_t.cpp index 27db91c..4c04bf2 100644 --- a/src/twtest/charutil_t.cpp +++ b/src/twtest/charutil_t.cpp @@ -37,69 +37,56 @@ #include "core/stdcore.h" -#ifdef TSS_TEST - -#include "test/utx.h" -#include "charutil.h" -#include "debug.h" -#include "errorbucketimpl.h" +#include "core/charutil.h" +#include "core/debug.h" +#include "core/errorbucketimpl.h" -/////////////////////////////////////////////////////////////////////////////// -// cCharEncoderTest -/////////////////////////////////////////////////////////////////////////////// -class cCharEncoderTest +void PrintChars( const TSTRING& str ) { -public: - - void PrintChars( const TSTRING& str ) + TSTRING::const_iterator cur = str.begin(); + TSTRING::const_iterator end = str.end(); + TSTRING::const_iterator first, last; + + while( cCharUtil::PopNextChar( cur, end, first, last ) ) { - const TCHAR* cur = str.begin(); - const TCHAR* end = str.end(); - const TCHAR* first = NULL; - const TCHAR* last = NULL; + TCOUT << _T("char length: ") << (int)(last - first) << std::endl; - while( cCharUtil::PopNextChar( cur, end, first, last ) ) + TCOUT << _T("char: <"); + for( TSTRING::const_iterator at = first; at != last; at++ ) { - TCOUT << _T("char length: ") << (int)(last - first) << std::endl; - - TCOUT << _T("char: <"); - for( const TCHAR* at = first; at != last; at++ ) - { - if( at != first ) - TCOUT << _T(","); - TCOUT << (int)*at; - } - TCOUT << _T(">") << std::endl; + if( at != first ) + TCOUT << _T(","); + TCOUT << (int)*at; } - - TCOUT << _T("----------------------------") << std::endl; + TCOUT << _T(">") << std::endl; } + + TCOUT << _T("----------------------------") << std::endl; +} - /////////////////////////////////////////////////////////////////////////// - // Basic - /////////////////////////////////////////////////////////////////////////// - void Basic( tss::TestContext& ctx ) +/////////////////////////////////////////////////////////////////////////// +// Basic +/////////////////////////////////////////////////////////////////////////// +void TestCharUtilBasic() +{ + try { - try - { - PrintChars( _T("foo") ); - PrintChars( _T("fo\x2354") ); - } - catch( eError& e ) - { - cErrorReporter::PrintErrorMsg( e ); - ASSERT(false); - } + PrintChars( _T("foo") ); + PrintChars( _T("fo\x23 54") ); } -}; + catch( eError& e ) + { + cErrorReporter::PrintErrorMsg( e ); + ASSERT(false); + } +} + +/* TSS_BeginTestSuiteFrom( cCharEncoderTest ) TSS_AddTestCase( Basic ); TSS_EndTestSuite( cCharEncoderTest ) - -#endif // TSS_TEST - -// eof: charutil_t.cpp +*/ diff --git a/src/twtest/displayencoder_t.cpp b/src/twtest/displayencoder_t.cpp index b2595d4..88c4618 100644 --- a/src/twtest/displayencoder_t.cpp +++ b/src/twtest/displayencoder_t.cpp @@ -37,14 +37,12 @@ #include "core/stdcore.h" -#ifdef TSS_TEST - -#include "test/utx.h" -#include "displayencoder.h" -#include "debug.h" -#include "twlocale.h" -#include "errorbucketimpl.h" +#include "core/displayencoder.h" +#include "core/debug.h" +#include "core/twlocale.h" +#include "core/errorbucketimpl.h" +#include "twtest/test.h" /////////////////////////////////////////////////////////////////////////////// // UTIL @@ -53,7 +51,7 @@ #define TSS_TCHAR_MIN CHAR_MIN #define TSS_TCHAR_MAX CHAR_MAX - +/* template< class CharT > bool IsPrintable( const std::basic_string< CharT >& str ) { const std::ctype< CharT > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); @@ -65,6 +63,7 @@ template< class CharT > bool IsPrintable( const std::basic_string< CharT >& str return true; } +*/ static void util_TestUnprintable( const TSTRING& strCUnprintable ) { @@ -80,264 +79,253 @@ static void util_TestUnprintable( const TSTRING& strCUnprintable ) } -/////////////////////////////////////////////////////////////////////////////// -// cDisplayEncoderTest -/////////////////////////////////////////////////////////////////////////////// -class cDisplayEncoderTest + +/////////////////////////////////////////////////////////////////////////// +// TestCharToHex +/////////////////////////////////////////////////////////////////////////// +void test_char_to_hex(char ch, const TSTRING& expected) { -public: + TSTRING observed = cCharEncoderUtil::char_to_hex( ch ); + TEST(expected == observed); +} - /////////////////////////////////////////////////////////////////////////// - // TestCharToHex - /////////////////////////////////////////////////////////////////////////// - void TestCharToHex( tss::TestContext& ctx ) - { - TCHAR ch; - TSTRING str; - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - // only use lowercase strings with this define - #define TSS_CHAR_TO_HEX_TEST( s ) \ - ch = 0x ## s; \ - str = cCharEncoderUtil::char_to_hex( ch ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T( #s ) ); +void TestCharToHex() +{ + test_char_to_hex( 0xfe, "fe"); + test_char_to_hex( 0xff, "ff"); + test_char_to_hex( 0x00, "00"); + test_char_to_hex( 0x01, "01"); + test_char_to_hex( 0x7f, "7f"); + test_char_to_hex( 0x80, "80"); +} - TSS_CHAR_TO_HEX_TEST( fefe ); - TSS_CHAR_TO_HEX_TEST( 0000 ); - TSS_CHAR_TO_HEX_TEST( 1234 ); - TSS_CHAR_TO_HEX_TEST( ffff ); - TSS_CHAR_TO_HEX_TEST( 0001 ); - TSS_CHAR_TO_HEX_TEST( 543c ); - TSS_CHAR_TO_HEX_TEST( cccc ); - TSS_CHAR_TO_HEX_TEST( 9999 ); - TSS_CHAR_TO_HEX_TEST( abcd ); - } - /////////////////////////////////////////////////////////////////////////// - // TestHexToChar - /////////////////////////////////////////////////////////////////////////// - void TestHexToChar( tss::TestContext& ctx ) - { - TCHAR ch; - TSTRING str; +/////////////////////////////////////////////////////////////////////////// +// TestHexToChar +/////////////////////////////////////////////////////////////////////////// +void test_hex_to_char(const TSTRING& str, char expected) +{ + char observed = cCharEncoderUtil::hex_to_char( str.begin(), str.end() ); + TEST(expected == observed); +} - // only use lowercase strings with this define - #define TSS_HEX_TO_CHAR_TEST( s ) \ - str = _T( #s ); \ - ch = cCharEncoderUtil::hex_to_char( str.begin(), str.end() ); \ - ASSERT( ch == 0x ## s ); - TSS_HEX_TO_CHAR_TEST( fefe ); - TSS_HEX_TO_CHAR_TEST( 0000 ); - TSS_HEX_TO_CHAR_TEST( 1234 ); - TSS_HEX_TO_CHAR_TEST( ffff ); - TSS_HEX_TO_CHAR_TEST( 0001 ); - TSS_HEX_TO_CHAR_TEST( 543c ); - TSS_HEX_TO_CHAR_TEST( cccc ); - TSS_HEX_TO_CHAR_TEST( 9999 ); - TSS_HEX_TO_CHAR_TEST( abcd ); - } - - ////////////////////////////////////////////////////////////////////////// - // TestStringToHex -- locale specific test -- only works in ASCII - /////////////////////////////////////////////////////////////////////////// - void TestStringToHex( tss::TestContext& ctx ) - { - TSTRING str; - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - - // only use lowercase strings with this define - #define TSS_STRING_TO_HEX_TEST( s, n ) \ - str = cCharEncoderUtil::CharStringToHexValue( _T( #s ) ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T( #n ) ); - - TSS_STRING_TO_HEX_TEST( \n, 000a ); - TSS_STRING_TO_HEX_TEST( \r, 000d ); - TSS_STRING_TO_HEX_TEST( \r\n, 000d000a ); - TSS_STRING_TO_HEX_TEST( a\r\nb, 0061000d000a0062 ); - } - - ////////////////////////////////////////////////////////////////////////// - // TestHexToString -- locale specific test -- only works in Unicode - /////////////////////////////////////////////////////////////////////////// - void TestHexToString( tss::TestContext& ctx ) - { - TSTRING str; - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - - // only use lowercase strings with this define - #define TSS_HEX_TO_STRING_TEST( s, n ) \ - str = cCharEncoderUtil::HexValueToCharString( _T( #n ) ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T( #s ) ); - - TSS_HEX_TO_STRING_TEST( \n, 000a ); - TSS_HEX_TO_STRING_TEST( \r, 000d ); - TSS_HEX_TO_STRING_TEST( \r\n, 000d000a ); - TSS_HEX_TO_STRING_TEST( a\r\nb, 0061000d000a0062 ); - } +void TestHexToChar() +{ + TCERR << "\nTODO: TestHexToChar in displayencoder_t.cpp needs to be fixed; currently disabled." << std::endl; +#if 0 + test_hex_to_char( "fe", 0xfe ); + test_hex_to_char( "ff", 0xff ); + test_hex_to_char( "00", 0x00 ); + test_hex_to_char( "01", 0x01 ); + test_hex_to_char( "7f", 0x7f ); + test_hex_to_char( "80", 0x80 ); - ////////////////////////////////////////////////////////////////////////// - // TestUnconvertable -- locale specific test -- only works in Unicode - /////////////////////////////////////////////////////////////////////////// - void TestUnconvertable( tss::TestContext& ctx ) - { - cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - TSTRING str; - TCHAR ch; - - // only use lowercase strings with this define - #define TSS_UNCONVERTABLE_TEST( n ) \ - ch = 0x ## n; \ - str = ch; \ - e.Encode( str ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T("\\x") _T( #n ) _T("x") ); - - TSS_UNCONVERTABLE_TEST( fefe ); - TSS_UNCONVERTABLE_TEST( 1234 ); - TSS_UNCONVERTABLE_TEST( ffff ); - TSS_UNCONVERTABLE_TEST( 1000 ); - TSS_UNCONVERTABLE_TEST( 543c ); - TSS_UNCONVERTABLE_TEST( cccc ); - TSS_UNCONVERTABLE_TEST( 9999 ); - TSS_UNCONVERTABLE_TEST( 0123 ); - TSS_UNCONVERTABLE_TEST( 0100 ); - } - - ////////////////////////////////////////////////////////////////////////// - // TestUnprintable -- locale specific test -- only works in Unicode - /////////////////////////////////////////////////////////////////////////// - void TestUnprintable( tss::TestContext& ctx ) - { - cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - TSTRING str; - TCHAR ch; - - // only use lowercase strings with this define - #define TSS_UNPRINTABLE_TEST( n ) \ - ch = 0x ## n; \ - str = ch; \ - e.Encode( str ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T("\\x") _T( #n ) _T("x") ); - - TSS_UNPRINTABLE_TEST( 000a ); - TSS_UNPRINTABLE_TEST( 000d ); - } - - ////////////////////////////////////////////////////////////////////////// - // TestQuoteAndBackSlash - /////////////////////////////////////////////////////////////////////////// - void TestQuoteAndBackSlash( tss::TestContext& ctx ) - { - cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); - TSTRING str; - - str = _T("\\"); - e.Encode( str ); - ASSERT( str == _T("\\\\") ); - - str = _T("\""); - e.Encode( str ); - ASSERT( str == _T("\\\"") ); - } - - // TODO:BAM -- try multibyte now..... + test_hex_to_char( "100", 0); // should throw + test_hex_to_char( "-01", 0); // should throw +#endif +} - /////////////////////////////////////////////////////////////////////////// - // Basic - /////////////////////////////////////////////////////////////////////////// - void Basic( tss::TestContext& ctx ) - { - try - { - //============================================================= - // TEST UNPRINTABLE ENCODING/ROUNDTRIP - //============================================================= - - util_TestUnprintable( _T("normal string") ); +////////////////////////////////////////////////////////////////////////// +// TestStringToHex -- locale specific test -- only works in ASCII +/////////////////////////////////////////////////////////////////////////// +void test_string_to_hex(const std::string& str, const std::string& expected) +{ + std::string observed = cCharEncoderUtil::CharStringToHexValue(str); + TEST(expected == observed); +} - util_TestUnprintable( _T("return\n") ); - util_TestUnprintable( _T("ret\rurn\n") ); - util_TestUnprintable( _T("ret\rnurn\n") ); +void TestStringToHex() +{ + test_string_to_hex( "\n", "0a" ); + test_string_to_hex( "\r", "0d" ); + test_string_to_hex( "\r\n", "0d0a" ); + test_string_to_hex( "a\r\nb", "610d0a62" ); +} - util_TestUnprintable( _T("bell\x08") ); - util_TestUnprintable( _T("\x08 bell") ); - util_TestUnprintable( _T("be\x08ll") ); - util_TestUnprintable( _T("\x1F\x1F\x1F") ); +////////////////////////////////////////////////////////////////////////// +// TestHexToString -- locale specific test -- only works in Unicode +/////////////////////////////////////////////////////////////////////////// +void test_hex_to_string(const std::string& str, const std::string& expected) +{ + std::string observed = cCharEncoderUtil::HexValueToCharString(str); + TEST(expected == observed); +} - util_TestUnprintable( _T("big\xFF") ); - util_TestUnprintable( _T("\xEE big") ); - util_TestUnprintable( _T("\xEE\xEEtwo big") ); - util_TestUnprintable( _T("small\x01") ); - util_TestUnprintable( _T("\x01\x01two small") ); - - //============================================================= - // TEST UNCONVERTABLE CHARS - //============================================================= - TSTRING strMessWithMe = _T("Mess with me..."); - for( size_t c = TSS_TCHAR_MIN; - c < TSS_TCHAR_MAX; - c++ ) - { - if( ( c != '\0' ) ) - { - strMessWithMe += c; - } - } - util_TestUnprintable( strMessWithMe ); +void TestHexToString() +{ + TCERR << "\nTODO: TestHexToString in displayencoder_t.cpp needs to be fixed; currently disabled." << std::endl; +#if 0 + test_hex_to_string( "0a", "\n"); + test_hex_to_string( "0d", "\r"); + test_hex_to_string( "0d0a", "\r\n"); + test_hex_to_string( "610d0a62", "a\r\nb"); +#endif +} + +#if 0 +////////////////////////////////////////////////////////////////////////// +// TestUnconvertable -- locale specific test -- only works in Unicode +/////////////////////////////////////////////////////////////////////////// +void TestUnconvertable() +{ + cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); + const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); + TSTRING str; + TCHAR ch; + + // only use lowercase strings with this define + #define TSS_UNCONVERTABLE_TEST( n ) \ + ch = 0x ## n; \ + str = ch; \ + e.Encode( str ); \ +// ct.tolower( str.begin(), str.end() ); \ + ASSERT( str == _T("\\x") _T( #n ) _T("x") ); + + TSS_UNCONVERTABLE_TEST( fefe ); + TSS_UNCONVERTABLE_TEST( 1234 ); + TSS_UNCONVERTABLE_TEST( ffff ); + TSS_UNCONVERTABLE_TEST( 1000 ); + TSS_UNCONVERTABLE_TEST( 543c ); + TSS_UNCONVERTABLE_TEST( cccc ); + TSS_UNCONVERTABLE_TEST( 9999 ); + TSS_UNCONVERTABLE_TEST( 0123 ); + TSS_UNCONVERTABLE_TEST( 0100 ); +} + +////////////////////////////////////////////////////////////////////////// +// TestUnprintable -- locale specific test -- only works in Unicode +/////////////////////////////////////////////////////////////////////////// +void TestUnprintable() +{ + cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); + const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); + TSTRING str; + TCHAR ch; + + // only use lowercase strings with this define + #define TSS_UNPRINTABLE_TEST( n ) \ + ch = 0x ## n; \ + str = ch; \ + e.Encode( str ); \ +// ct.tolower( str.begin(), str.end() ); \ + ASSERT( str == _T("\\x") _T( #n ) _T("x") ); + + TSS_UNPRINTABLE_TEST( 000a ); + TSS_UNPRINTABLE_TEST( 000d ); +} +#endif + +////////////////////////////////////////////////////////////////////////// +// TestQuoteAndBackSlash +/////////////////////////////////////////////////////////////////////////// +void TestQuoteAndBackSlash() +{ + cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); + TSTRING str; + + str = _T("\\"); + e.Encode( str ); + ASSERT( str == _T("\\\\") ); - //============================================================= - // TEST \\ and \x ENCODING/ROUNDTRIP - //============================================================= + str = _T("\""); + e.Encode( str ); + ASSERT( str == _T("\\\"") ); +} - util_TestUnprintable( _T("\\Other \\\\slashes") ); - util_TestUnprintable( _T("\\Other slashes\\\\") ); - util_TestUnprintable( _T("O\\ther slashes\\\\") ); - util_TestUnprintable( _T("\\\\\\") ); +// TODO:BAM -- try multibyte now..... + + +/////////////////////////////////////////////////////////////////////////// +// Basic +/////////////////////////////////////////////////////////////////////////// +void TestDisplayEncoderBasic() +{ + try + { + //============================================================= + // TEST UNPRINTABLE ENCODING/ROUNDTRIP + //============================================================= + + util_TestUnprintable( _T("normal string") ); + + util_TestUnprintable( _T("return\n") ); + util_TestUnprintable( _T("ret\rurn\n") ); + util_TestUnprintable( _T("ret\rnurn\n") ); + + util_TestUnprintable( _T("bell\x08") ); + util_TestUnprintable( _T("\x08 bell") ); + util_TestUnprintable( _T("be\x08ll") ); + + util_TestUnprintable( _T("\x1F\x1F\x1F") ); + + util_TestUnprintable( _T("big\xFF") ); + util_TestUnprintable( _T("\xEE big") ); + util_TestUnprintable( _T("\xEE\xEEtwo big") ); + util_TestUnprintable( _T("small\x01") ); + util_TestUnprintable( _T("\x01\x01two small") ); - util_TestUnprintable( _T("\\xTricky") ); - util_TestUnprintable( _T("Tri\\xcky") ); - util_TestUnprintable( _T("Tricky\\x") ); - util_TestUnprintable( _T("\\Tricky\\\\x") ); - - - //============================================================= - // TEST UNCONVERTABLE, UNPRINTABLE, AND \\ and \" CHARS - //============================================================= - TSTRING strMessWithMe2 = _T("Mess with me..."); - for( size_t ch = TSS_TCHAR_MIN; - ch < TSS_TCHAR_MAX; - ch++ ) - { - if( ( ch != '\0' ) ) - { - strMessWithMe2 += ch; - } - } - - strMessWithMe2 += _T("\r\n\t\b\\\"\\\\\\\"\v\""); - util_TestUnprintable( strMessWithMe2 ); - - // TODO:BAM -- create multibyte tests (create a mb string at random, then test it. - // make sure there are '\' and '"' in it ) - } - catch( eError& e ) + //============================================================= + // TEST UNCONVERTABLE CHARS + //============================================================= + TSTRING strMessWithMe = _T("Mess with me..."); + for( size_t c = TSS_TCHAR_MIN; + c < TSS_TCHAR_MAX; + c++ ) { - cErrorReporter::PrintErrorMsg( e ); - ASSERT(false); + if( ( c != '\0' ) ) + { + strMessWithMe += c; + } } - } -}; + util_TestUnprintable( strMessWithMe ); + + //============================================================= + // TEST \\ and \x ENCODING/ROUNDTRIP + //============================================================= -TSS_BeginTestSuiteFrom( cDisplayEncoderTest ) + util_TestUnprintable( _T("\\Other \\\\slashes") ); + util_TestUnprintable( _T("\\Other slashes\\\\") ); + util_TestUnprintable( _T("O\\ther slashes\\\\") ); + util_TestUnprintable( _T("\\\\\\") ); + + util_TestUnprintable( _T("\\xTricky") ); + util_TestUnprintable( _T("Tri\\xcky") ); + util_TestUnprintable( _T("Tricky\\x") ); + util_TestUnprintable( _T("\\Tricky\\\\x") ); + + + //============================================================= + // TEST UNCONVERTABLE, UNPRINTABLE, AND \\ and \" CHARS + //============================================================= + TSTRING strMessWithMe2 = _T("Mess with me..."); + for( size_t ch = TSS_TCHAR_MIN; + ch < TSS_TCHAR_MAX; + ch++ ) + { + if( ( ch != '\0' ) ) + { + strMessWithMe2 += ch; + } + } + + strMessWithMe2 += _T("\r\n\t\b\\\"\\\\\\\"\v\""); + util_TestUnprintable( strMessWithMe2 ); + + // TODO:BAM -- create multibyte tests (create a mb string at random, then test it. + // make sure there are '\' and '"' in it ) + } + catch( eError& e ) + { + cErrorReporter::PrintErrorMsg( e ); + ASSERT(false); + } +} + +/*TSS_BeginTestSuiteFrom( cDisplayEncoderTest ) TSS_AddTestCase( Basic ); TSS_AddTestCase( TestHexToChar ); @@ -348,8 +336,6 @@ TSS_BeginTestSuiteFrom( cDisplayEncoderTest ) TSS_AddTestCase( TestUnprintable ); TSS_AddTestCase( TestQuoteAndBackSlash ); -TSS_EndTestSuite( cDisplayEncoderTest ) +TSS_EndTestSuite( cDisplayEncoderTest )*/ -#endif // TSS_TEST -// eof: displayencoder_t.cpp diff --git a/src/twtest/policyparser_t.cpp b/src/twtest/policyparser_t.cpp index d1f4fb3..2353f14 100644 --- a/src/twtest/policyparser_t.cpp +++ b/src/twtest/policyparser_t.cpp @@ -44,6 +44,7 @@ #include "fs/fspropset.h" #include "fco/fcospeclist.h" #include "twtest/test.h" +#include "util/fileutil.h" #include // helper class that checks output of each fcospec @@ -52,44 +53,70 @@ public: static bool VerifyNameAndStartPoint(iFCOSpec *pfsspec, TSTRING &name); }; -void TestPolicyParser() +TSTRING get_test_file_dir() { - cDebug d("TestPolicyParser()"); + if(cFileUtil::IsDir("../src/parser/testfiles")) + return "../src/parser/testfiles"; + + if(cFileUtil::IsDir("src/parser/testfiles")) + return "src/parser/testfiles"; + + return ""; +} - // - // file: pol.txt - // +void test_policy_file(const std::string& polfile) +{ try { cDebug::AddOutTarget(cDebug::OUT_STDOUT); - + + TSTRING pol_path = get_test_file_dir(); + pol_path.append("/"); + pol_path.append(polfile); + std::ifstream in; - in.open( "../twparser/testfiles/pol.txt" ); + in.open(pol_path); if( ! in.good() ) throw eParserHelper( _T("couldn't open test file") ); - + cPolicyParser parser( in ); - + cGenreSpecListVector policy; cErrorQueue errorQ; cErrorReporter errorR; cErrorTracer errorT; - + // set up an error bucket that will spit things to stderr errorT.SetChild( &errorR ); errorQ.SetChild( &errorT ); - + parser.Execute( policy, &errorQ ); - return; } catch(eError& e) { TCERR << (int)e.GetID() << " : " << e.GetMsg().c_str() << std::endl; return; } - + + TCERR << "Parsed policy test file " << polfile << std::endl; return; } + + + +void TestPolicyParser() +{ + cDebug d("TestPolicyParser()"); + + test_policy_file("pol.txt"); +// test_policy_file("directives.txt"); //fails unless you substitute your hostname for 'your_host' in this file + +// TODO: test currently segfaults if you create more than one policy parser in a process. (Not a real world scenario). + +/* test_policy_file("poleasy.txt"); + test_policy_file("polhard.txt"); + test_policy_file("polruleattr.txt"); */ +} diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index 7cec46e..019282a 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -39,11 +39,7 @@ #include "core/core.h" #include "db/db.h" #include "twcrypto/twcrypto.h" - -#ifdef PARSER_PRESENT -#include "parser/parser.h" -#endif - +#include "twparser/twparser.h" #include "tw/tw.h" #include "fco/fco.h" @@ -104,9 +100,7 @@ void TestHashTable(); void TestFCONameTbl(); void TestConfigFile(); -#ifdef PARSER_PRESENT void TestPolicyParser(); -#endif//PARSER_PRESENT void TestFCOSpecHelper(); void TestCrypto(); @@ -131,9 +125,7 @@ void TestIntegrityCheck(); void TestFCODatabaseFile(); void TestWchar16(); void TestStringEncoder(); -#ifdef TSS_TEST -void TestDisplayEncoder(); -#endif +//void TestDisplayEncoder(); void TestGrowHeap(); void TestPlatform(); //void TestBlockFile(); @@ -143,6 +135,17 @@ void TestTWLocale(); void TestFileUtil(); void TestFCONameTranslator(); void TestCodeConverter(); + +void TestCharToHex(); +void TestHexToChar(); +void TestStringToHex(); +void TestHexToString(); +//void TestUnconvertable(); +//void TestUnprintable(); +void TestQuoteAndBackSlash(); +void TestDisplayEncoderBasic(); +void TestCharUtilBasic(); + /// This is easier than all the (cpp) files and declarations #include "stringutil_t.h" @@ -203,9 +206,7 @@ static void Test(int testID) case 43: TestTCHAR(); break; case 44: TestUnixFSServices(); break; case 46: TestConfigFile(); break; -#ifdef PARSER_PRESENT case 47: TestPolicyParser(); break; -#endif//PARSER_PRESENT case 48: TestKeyFile(); break; case 49: TestTWUtil(); break; case 50: TestFSPropDisplayer(); break; @@ -218,10 +219,8 @@ static void Test(int testID) case 58: TestGenreSpecList(); break; //case 59: TestIntegrityCheck(); break; case 65: TestWchar16(); break; - case 66: TestStringEncoder(); break; -#ifdef TSS_TEST - case 67: TestDisplayEncoder(); break; -#endif + case 66: TestStringEncoder(); break; + //case 67: TestDisplayEncoder(); break; case 69: TestGrowHeap(); break; case 70: TestPlatform(); break; //case 71: TestBlockFile(); break; @@ -231,7 +230,17 @@ static void Test(int testID) case 75: TestTWLocale(); break; case 76: TestFCONameTranslator(); break; case 77: TestStringUtil(); break; - case 78: TestCodeConverter(); break; + case 78: TestCodeConverter(); break; + + case 79: TestCharToHex(); break; + case 80: TestHexToChar(); break; + case 81: TestStringToHex(); break; + case 82: TestHexToString(); break; + // case 83: TestUnconvertable(); break; + // case 84: TestUnprintable(); break; + case 85: TestQuoteAndBackSlash(); break; + case 86: TestDisplayEncoderBasic(); break; + case 87: TestCharUtilBasic(); break; } } @@ -245,9 +254,7 @@ cTest::cTest() TSS_Dependency( cCore ); TSS_Dependency( cDb ); TSS_Dependency( cTWCrypto ); -#ifdef PARSER_PRESENT - TSS_Dependency( cParser ); -#endif//PARSER_PRESENT + TSS_Dependency( cTWParser ); TSS_Dependency( cTW ); TSS_Dependency( cFCO ); TSS_Dependency( cFS ); From 2c03fdf8787b358fcd9c3d10569cc78d01431ad3 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 27 Mar 2017 00:50:33 -0700 Subject: [PATCH 33/43] Enable/repair more unit tests, and undo an earlier change to hex_to_char() that was causing test failures --- src/core/displayencoder.cpp | 2 +- src/tw/configfile.cpp | 5 ++ src/tw/configfile.h | 4 ++ src/twtest/charutil_t.cpp | 3 +- src/twtest/cmdlineparser_t.cpp | 92 ++++++++++++++---------------- src/twtest/configfile_t.cpp | 49 +++++++--------- src/twtest/dbdatasource_t.cpp | 10 +++- src/twtest/displayencoder_t.cpp | 26 +++++---- src/twtest/error_t.cpp | 44 ++++++++------ src/twtest/errorbucketimpl_t.cpp | 25 ++++---- src/twtest/fcocompare_t.cpp | 48 +++++++++------- src/twtest/fconametranslator_t.cpp | 22 +++---- src/twtest/fcopropimpl_t.cpp | 22 +++++++ src/twtest/fcoreport_t.cpp | 1 + src/twtest/fcospecattr_t.cpp | 1 + src/twtest/file_t.cpp | 1 + src/twtest/fspropcalc_t.cpp | 43 ++++++++------ src/twtest/genrespeclist_t.cpp | 9 +-- src/twtest/genreswitcher_t.cpp | 17 +++--- src/twtest/srefcountobj_t.cpp | 7 ++- src/twtest/stringencoder_t.cpp | 3 + src/twtest/test.cpp | 6 +- 22 files changed, 249 insertions(+), 191 deletions(-) diff --git a/src/core/displayencoder.cpp b/src/core/displayencoder.cpp index 0bca15c..3b3536d 100644 --- a/src/core/displayencoder.cpp +++ b/src/core/displayencoder.cpp @@ -568,7 +568,7 @@ TCHAR cCharEncoderUtil::hex_to_char( TSTRING::const_iterator first, if( ss.bad() || ss.fail() ) ThrowAndAssert( eBadHexConversion( TSTRING( first, last ) ) ); - if( ch > (unsigned long)max_char || ch < (unsigned long)min_char ) + if( (TCHAR)ch > max_char || (TCHAR)ch < min_char ) ThrowAndAssert( eBadHexConversion( TSTRING( first, last ) ) ); return (TCHAR)ch; diff --git a/src/tw/configfile.cpp b/src/tw/configfile.cpp index c6dc7a4..af13e78 100644 --- a/src/tw/configfile.cpp +++ b/src/tw/configfile.cpp @@ -293,6 +293,11 @@ bool cConfigFile::Lookup( const TSTRING& sKey, TSTRING& sVal ) const return( fFound ); } +void cConfigFile::Insert( const TSTRING& sKey, const TSTRING& sVal ) +{ + mStringHashTable.Insert(sKey, sVal); +} + /////////////////////////////////////////////////////////////////////////////// // GetFileHeaderID() /////////////////////////////////////////////////////////////////////////////// diff --git a/src/tw/configfile.h b/src/tw/configfile.h index 2546a97..6cbf2e9 100644 --- a/src/tw/configfile.h +++ b/src/tw/configfile.h @@ -107,6 +107,10 @@ public: bool Lookup( const TSTRING& tstrKey, TSTRING& tstrVal ) const; // returns true if key is found in internal container and returns its value in tstrVal. + + void Insert( const TSTRING& tstrKey, const TSTRING& tstrVal ); + // add key+value to config data. visible for unit testing. + void WriteString( TSTRING& configText ); // writes all key/value pairs from internal container to filename as "name=value\n" void ReadString( const TSTRING configText ); // throw( eConfigFile ); diff --git a/src/twtest/charutil_t.cpp b/src/twtest/charutil_t.cpp index 4c04bf2..ff6872c 100644 --- a/src/twtest/charutil_t.cpp +++ b/src/twtest/charutil_t.cpp @@ -40,6 +40,7 @@ #include "core/charutil.h" #include "core/debug.h" #include "core/errorbucketimpl.h" +#include "twtest/test.h" void PrintChars( const TSTRING& str ) @@ -78,7 +79,7 @@ void TestCharUtilBasic() catch( eError& e ) { cErrorReporter::PrintErrorMsg( e ); - ASSERT(false); + TEST(false); } } diff --git a/src/twtest/cmdlineparser_t.cpp b/src/twtest/cmdlineparser_t.cpp index 80854c0..57eaec1 100644 --- a/src/twtest/cmdlineparser_t.cpp +++ b/src/twtest/cmdlineparser_t.cpp @@ -41,7 +41,7 @@ const int argc1 = 9; const TCHAR* argv1[] = { - _T("tripwire.exe"), + _T("tripwire"), _T("-m"), _T("Init"), _T("-tp"), @@ -55,7 +55,7 @@ const TCHAR* argv1[] = const int argc2 = 3; const TCHAR* argv2[] = { - _T("tripwire.exe"), + _T("tripwire"), _T("-m"), _T("-v") }; @@ -63,7 +63,7 @@ const TCHAR* argv2[] = const int argc3 = 3; const TCHAR* argv3[] = { - _T("tripwire.exe"), + _T("tripwire"), _T("dog"), _T("-v"), }; @@ -72,7 +72,7 @@ const TCHAR* argv3[] = const int argc4 = 5; const TCHAR* argv4[] = { - _T("tripwire.exe"), + _T("tripwire"), _T("-tp"), _T("-v"), _T("frog"), @@ -82,7 +82,7 @@ const TCHAR* argv4[] = const int argc5 = 4; const TCHAR* argv5[] = { - _T("tripwire.exe"), + _T("tripwire"), _T("-tp"), _T("-v"), _T("frog") @@ -100,6 +100,33 @@ static void PrintCmdLine(int argc, const TCHAR** argv, cDebug d) d.TraceDebug(_T(">>>%s\n"), str.c_str()); } +static void test_parse(cCmdLineParser& parser, const int argc, const TCHAR** argv, bool should_throw) +{ +#ifdef _DEBUG + cDebug d("test_parse"); + PrintCmdLine(argc, argv, d); +#endif + + bool threw = false; + + try { + parser.Parse(argc, argv); + + } catch (eError& e) { + if (!should_throw) + TCERR << e.GetMsg() << std::endl; + threw = true; + } + + TEST(threw == should_throw); + +#ifdef _DEBUG + parser.TraceContents(); +#endif +} + + + void TestCmdLineParser() { enum ArgId { ID_M, ID_TP, ID_V, ID_UNNAMED }; @@ -113,58 +140,22 @@ void TestCmdLineParser() cDebug d("TestCmdLineParser"); - PrintCmdLine(argc1, argv1, d); - p.Parse(argc1, argv1); - #ifdef _DEBUG - p.TraceContents(); - #endif + test_parse(p, argc1, argv1, false); + test_parse(p, argc2, argv2, true); + test_parse(p, argc3, argv3, true); + test_parse(p, argc4, argv4, false); - PrintCmdLine(argc2, argv2, d); - p.Parse(argc2, argv2); // should fail. - #ifdef _DEBUG - p.TraceContents(); - #endif - - PrintCmdLine(argc3, argv3, d); - p.Parse(argc3, argv3); // should fail - #ifdef _DEBUG - p.TraceContents(); - #endif - - PrintCmdLine(argc4, argv4, d); - p.Parse(argc4, argv4); - #ifdef _DEBUG - p.TraceContents(); - #endif - - /* - // TODO - test mutual exclusion... - - cCmdLineParser::ErrorType et; - TSTRING errStr; + // command line arg mutual exclusion d.TraceDebug("** Making -m and -v mutually exclusive, then running on first cmd line...\n"); p.AddMutEx(ID_M, ID_V); - p.Parse(argc1, argv1); // should fail - p.GetErrorInfo(et, errStr); - TEST(et == cCmdLineParser::ERR_MUTUAL_EXCLUSION); - d.TraceDebug(_T("Mutual exclusion test worked; here is the error string: %s\n"), errStr.c_str()); - */ + test_parse(p, argc1, argv1, true); // should fail // make the command line want one parameter d.TraceDebug("** Changing cmd line to only want one last param...\n"); p.AddArg(ID_UNNAMED, TSTRING(_T("")), TSTRING(_T("")), cCmdLineParser::PARAM_ONE); - PrintCmdLine(argc4, argv4, d); - p.Parse(argc4, argv4); // should fail - #ifdef _DEBUG - p.TraceContents(); - #endif - - PrintCmdLine(argc5, argv5, d); - p.Parse(argc5, argv5); - #ifdef _DEBUG - p.TraceContents(); - #endif + test_parse(p, argc4, argv4, true); + test_parse(p, argc5, argv5, false); // TODO -- test a bunch more!!! } @@ -172,7 +163,8 @@ void TestCmdLineParser() { TCERR << _T("Command line error: "); TCERR << e.GetMsg() << std::endl; - //TODO... TEST(false); + //TODO... + TEST(false); } } diff --git a/src/twtest/configfile_t.cpp b/src/twtest/configfile_t.cpp index 98a7a64..7ae3b8b 100644 --- a/src/twtest/configfile_t.cpp +++ b/src/twtest/configfile_t.cpp @@ -117,8 +117,10 @@ void TestConfigFile(void) cTWUtil::PrintErrorMsg( e ); } } +} -#ifdef NOT_BRIANS_TEST +void TestConfigFile2(void) +{ cDebug d("Testconfigfile"); d.TraceDetail("Entering...\n"); iFSServices* pFSServices = iFSServices::GetInstance(); @@ -129,32 +131,21 @@ void TestConfigFile(void) TSTRING currpath; pFSServices->GetCurrentDir(currpath); const TSTRING testTWROOT = currpath; - const TSTRING testTWBIN = (testTWROOT + _T("/bin/")); - const TSTRING testTWCFG = (testTWROOT + _T("/etc/")); - const TSTRING testTWMAN = (testTWROOT + _T("/man/")); - const TSTRING testTWHTML = (testTWROOT + _T("/html/")); - const TSTRING testTWDB = (testTWROOT + _T("/db/")); - const TSTRING testTWKEY = (testTWROOT + _T("/key/")); - const TSTRING testTWREPORT = (testTWROOT + _T("/report/")); - const TSTRING testTWPASSWORD = (testTWROOT + _T("/null_password")); + //TODO maybe also test read failure when mandatory config values aren't set + + //Begin tests of config. module parser: cConfigFile write_cfgmod; - //Filename for writing/reading some value pairs: - const TSTRING testfile = testTWCFG + _T("tripwire.cfg"); + //Add all the mandatory config options. + write_cfgmod.Insert( _T("POLFILE"), "test.pol"); + write_cfgmod.Insert( _T("DBFILE"), "test.twd"); + write_cfgmod.Insert( _T("REPORTFILE"), "test.twr"); + write_cfgmod.Insert( _T("SITEKEYFILE"), "site.key"); + write_cfgmod.Insert( _T("LOCALKEYFILE"), "local.key"); - //Insert the test values into cConfigFile's hashtable: - /* - write_cfgmod.Insert( _T("TWROOT"), testTWROOT); - write_cfgmod.Insert( _T("TWBIN"), testTWBIN); - write_cfgmod.Insert( _T("TWCFG"), testTWCFG); - write_cfgmod.Insert( _T("TWMAN"), testTWMAN); - write_cfgmod.Insert( _T("TWHTML"), testTWHTML); - write_cfgmod.Insert( _T("TWDB"), testTWDB); - write_cfgmod.Insert( _T("TWKEY"), testTWKEY); - write_cfgmod.Insert( _T("TWREPORT"), testTWREPORT); - write_cfgmod.Insert( _T("TWPASSWORD"), testTWPASSWORD); - */ + //Filename for writing/reading some value pairs: + const TSTRING testfile = testTWROOT + _T("/tripwire.cfg"); //Store these values on disk. TSTRING configText; @@ -173,19 +164,19 @@ void TestConfigFile(void) catch (eError& error) { TCERR << (int)error.GetID() << std::endl << error.GetMsg() << std::endl; - ASSERT(false); + TEST(false); } //These TSTRINGS will hold info. from .Lookup: TSTRING lookup1, lookup2; - read_cfgmod.Lookup( _T("TWROOT"), lookup1); - read_cfgmod.Lookup( _T("TWDB"), lookup2); + read_cfgmod.Lookup( _T("POLFILE"), lookup1); + read_cfgmod.Lookup( _T("DBFILE"), lookup2); d.TraceDetail("First lookup's value: %s \n", lookup1.c_str()); d.TraceDetail("Second lookup's value: %s \n", lookup2.c_str()); - TEST( lookup1 == testTWROOT ); - TEST( lookup2 == testTWDB ); + TEST( lookup1 == "test.pol" ); + TEST( lookup2 == "test.twd" ); d.TraceDetail("Tests Passed!\n"); -#endif // NOT_BRIANS_TEST +//#endif // NOT_BRIANS_TEST } diff --git a/src/twtest/dbdatasource_t.cpp b/src/twtest/dbdatasource_t.cpp index 0f83e09..15c4322 100644 --- a/src/twtest/dbdatasource_t.cpp +++ b/src/twtest/dbdatasource_t.cpp @@ -40,6 +40,7 @@ #include "fco/fcopropset.h" #include "fco/fcoprop.h" #include "fco/fco.h" +#include "twtest/test.h" static void GetNoun( TSTRING& noun ) { @@ -84,11 +85,16 @@ static void PrintFCO( const iFCO* pFCO ) void TestDbDataSource() { + TCERR << std::endl << "TestDbDataSource needs to be redesigned so it doesn't require user interaction" << std::endl; + +#if 0 cDebug d("TestDbDataSource"); cHierDatabase db; - const TSTRING dbName = _T("c:/tmp/tw.db"); + const TSTRING dbName = _T("tw.db"); + + try { // TODO -- get the case sensitiveness and delimiting char out of the factory instead of iFSServices @@ -296,5 +302,7 @@ void TestDbDataSource() catch( eError& e ) { d.TraceError("*** Caught error: %d %s\n", e.GetID(), e.GetMsg().c_str() ); + TEST(false); } +#endif } diff --git a/src/twtest/displayencoder_t.cpp b/src/twtest/displayencoder_t.cpp index 88c4618..1a467a6 100644 --- a/src/twtest/displayencoder_t.cpp +++ b/src/twtest/displayencoder_t.cpp @@ -104,17 +104,25 @@ void TestCharToHex() /////////////////////////////////////////////////////////////////////////// // TestHexToChar /////////////////////////////////////////////////////////////////////////// -void test_hex_to_char(const TSTRING& str, char expected) +void test_hex_to_char(const TSTRING& str, char expected, bool should_throw=false) { - char observed = cCharEncoderUtil::hex_to_char( str.begin(), str.end() ); - TEST(expected == observed); + bool threw = false; + try + { + char observed = cCharEncoderUtil::hex_to_char( str.begin(), str.end() ); + TEST(expected == observed); + } + catch(eError& e) + { + threw = true; + } + + TEST(should_throw == threw); } void TestHexToChar() { - TCERR << "\nTODO: TestHexToChar in displayencoder_t.cpp needs to be fixed; currently disabled." << std::endl; -#if 0 test_hex_to_char( "fe", 0xfe ); test_hex_to_char( "ff", 0xff ); test_hex_to_char( "00", 0x00 ); @@ -122,9 +130,8 @@ void TestHexToChar() test_hex_to_char( "7f", 0x7f ); test_hex_to_char( "80", 0x80 ); - test_hex_to_char( "100", 0); // should throw - test_hex_to_char( "-01", 0); // should throw -#endif + test_hex_to_char( "100", 0, true); // should throw + test_hex_to_char( "-01", 0, true); // should throw } @@ -157,13 +164,10 @@ void test_hex_to_string(const std::string& str, const std::string& expected) void TestHexToString() { - TCERR << "\nTODO: TestHexToString in displayencoder_t.cpp needs to be fixed; currently disabled." << std::endl; -#if 0 test_hex_to_string( "0a", "\n"); test_hex_to_string( "0d", "\r"); test_hex_to_string( "0d0a", "\r\n"); test_hex_to_string( "610d0a62", "a\r\nb"); -#endif } #if 0 diff --git a/src/twtest/error_t.cpp b/src/twtest/error_t.cpp index fd3a24c..1519fcd 100644 --- a/src/twtest/error_t.cpp +++ b/src/twtest/error_t.cpp @@ -34,40 +34,50 @@ #include "core/stdcore.h" #include "core/error.h" +#include "core/errorgeneral.h" +#include "core/errorutil.h" #include "twtest/test.h" #include void TestError() { -//#pragma message( __FILE__ "(1) : TODO - implement this test file") - -/* + bool threw = false; try { std::cout << "Before Exception" << std::endl; std::cout << "Line number before throw: " << __LINE__ << std::endl; - THROW_ERROR(53, _T("This is an error!")); + throw eErrorGeneral(_T("This is an error!")); std::cout << "After Exception" << std::endl; } catch(eError& e) { - TEST(e.GetErrorNum() == 53); + threw = true; TEST(_tcscmp(e.GetMsg().c_str(), _T("This is an error!")) == 0); - TCOUT << _T("Exception caught!\n\tErrorNum=") << e.GetErrorNum() << _T("\n\t") << e.GetMsg() << std::endl; - } - - try - { - THROW_INTERNAL("error_t.cpp"); - } - catch(eInternal& e) - { - TEST(e.GetErrorNum() == eInternal::ERR_INTERNAL); - TCOUT << _T("Internal error caught!\n\tErrorNum=") << e.GetErrorNum() << _T("\n\t") << e.GetMsg() << std::endl; + TCOUT << _T("Exception caught!\n\nID=") << e.GetID() << _T("\n\t") << e.GetMsg() << std::endl; } catch(...) { TEST(false); } -*/ + + TEST(threw); + + + try + { + threw = false; + throw eInternal("error_t.cpp"); + } + catch(eInternal& e) + { + threw = true; + TEST(_tcscmp(e.GetMsg().c_str(), _T("error_t.cpp")) == 0); + TCOUT << _T("Internal error caught!\n\nID=") << e.GetID() << _T("\n\t") << e.GetMsg() << std::endl; + } + catch(...) + { + TEST(false); + } + + TEST(threw); } diff --git a/src/twtest/errorbucketimpl_t.cpp b/src/twtest/errorbucketimpl_t.cpp index e9d8e59..1a7d96a 100644 --- a/src/twtest/errorbucketimpl_t.cpp +++ b/src/twtest/errorbucketimpl_t.cpp @@ -37,11 +37,13 @@ #include "core/debug.h" #include "core/archive.h" #include "core/errorgeneral.h" +#include "core/errortable.h" // test option 7 void TestErrorBucketImpl() { -/* + cDebug d("TestErrorBucketImpl"); + //This whole function is in sorry shape... TODO: Fix this DRA d.TraceDebug("Entering...\n"); @@ -54,13 +56,13 @@ void TestErrorBucketImpl() //These calls to PrintErrorMsg are broken. The code is probably old. -DRA // Test error reporting - cErrorReporter::PrintErrorMsg(eError(_T("This should have a single line."))); - cErrorReporter::PrintErrorMsg(eError(_T("This should have a mulitiple lines since I have") + cErrorReporter::PrintErrorMsg(eErrorGeneral(_T("This should have a single line."))); + cErrorReporter::PrintErrorMsg(eErrorGeneral(_T("This should have a mulitiple lines since I have") _T(" put so much text here. But it does have a lot") _T(" of spaces so cErrorReporter should have no") _T(" problem breaking it up.") )); - cErrorReporter::PrintErrorMsg(eError(_T("This has many long words: ") + cErrorReporter::PrintErrorMsg(eErrorGeneral(_T("This has many long words: ") _T("40chars_________________________________") _T(" short words ") _T("50chars___________________________________________") @@ -69,7 +71,7 @@ void TestErrorBucketImpl() _T(" short words short words short words short words ") _T("90chars___________________________________________________________________________________") )); - cErrorReporter::PrintErrorMsg(eError(_T("The error reporter should handle newlines.\n") + cErrorReporter::PrintErrorMsg(eErrorGeneral(_T("The error reporter should handle newlines.\n") _T("Newlines should break up the text appropriately. Who knows when they will occur. Can't have them getting in the way.\n") _T("And one last line with a big char strings: 90chars___________________________________________________________________________________ 40chars_________________________________ 50chars___________________________________________") )); @@ -109,13 +111,14 @@ void TestErrorBucketImpl() } } - TODO - test this stuff that's commented out + //TODO - test this stuff that's commented out - TCOUT << _T("Following string should be a cArchive::ERR_OPEN_FAILED error:\n"); - TCOUT << cErrorTable::GetErrorString(cArchive::ERR_OPEN_FAILED) << std::endl; +// TCOUT << _T("Following string should be a cArchive::ERR_OPEN_FAILED error:\n"); +// TCOUT << cErrorTable::GetErrorString(cArchive::ERR_OPEN_FAILED) << std::endl; +/* This isn't going to work anymore, given that we don't have numeric errror constants // print out all error strings -#if 1 + // Look up all errors. // Note: our current error printing format limits us to 4 digit errors, so this should work for a while. int errornum; @@ -134,9 +137,9 @@ void TestErrorBucketImpl() TCOUT << _T(": ") << errorString << std::endl; } } -#endif +*/ d.TraceDebug("Leaving...\n"); -*/ + } diff --git a/src/twtest/fcocompare_t.cpp b/src/twtest/fcocompare_t.cpp index 0c74573..180da11 100644 --- a/src/twtest/fcocompare_t.cpp +++ b/src/twtest/fcocompare_t.cpp @@ -35,6 +35,7 @@ #include "core/debug.h" #include "fs/fsobject.h" #include "fs/fspropcalc.h" +#include "fs/fsdatasourceiter.h" #include "twtest/test.h" #include @@ -42,7 +43,7 @@ /////////////////////////////////////////////////////////////////////////////// // PrintProps -- prints out all the valid property names and values as pairs... /////////////////////////////////////////////////////////////////////////////// -/* + static void PrintProps(const iFCO* pFCO) { cDebug d("PrintProps"); @@ -57,13 +58,10 @@ static void PrintProps(const iFCO* pFCO) } } } -*/ + void TestFCOCompare() { -#pragma message( __FILE__ "(1) : TODO - implement this test file") -#if 0 - const TCHAR* FILE_NAME = TEMP_DIR _T("/dog.txt"); const char* FILE_NAME_N = TEMP_DIR_N "/dog.txt"; @@ -84,8 +82,9 @@ void TestFCOCompare() fstr.close(); // create the test FCO - cFSDataSource ds; - iFCO* pFCO = ds.CreateFCO(cFCOName(FILE_NAME), 0); + cFSDataSourceIter ds; + ds.SeekToFCO(cFCOName(FILE_NAME), false); + iFCO* pFCO = ds.CreateFCO(); TEST(pFCO); // measure a couple of properties, some of which will change... @@ -104,15 +103,14 @@ void TestFCOCompare() // first, try comparing it to itself... cFCOCompare comp; - cFCOCompare::CompareResult result; comp.SetPropsToCmp(v); - comp.Compare(pFCO, pFCO, result); - d.TraceDebug("Compare to itself is (expect true) %s\n", result.mResult == cFCOCompare::EQUAL? "true" : "false"); - TEST(result.mResult == cFCOCompare::EQUAL); + unsigned int result = comp.Compare(pFCO, pFCO); + d.TraceDebug("Compare to itself is (expect true) %s\n", result == cFCOCompare::EQUAL? "true" : "false"); + TEST(result == cFCOCompare::EQUAL); // change the file... d.TraceDebug("Changing the file...\n"); - fstr.open(FILE_NAME_N); + fstr.open(FILE_NAME); if(fstr.bad()) { d.TraceError("Unable to reopen %s!\n", FILE_NAME_N); @@ -122,36 +120,42 @@ void TestFCOCompare() fstr << "Meow! Meow! Meow! Meow!" << std::endl; fstr.close(); - iFCO* pFCO2 = ds.CreateFCO(cFCOName(FILE_NAME), 0); + //need a new data source iter, otherwise the existing FCO gets updated & you get a ref to it, + // and the resulting FCOs always match. + cFSDataSourceIter ds2; + ds2.SeekToFCO(cFCOName(FILE_NAME), false); + iFCO* pFCO2 = ds2.CreateFCO(); ASSERT(pFCO2); pFCO2->AcceptVisitor(&propCalc); d.TraceDebug("Second FCO's properties:\n"); PrintProps(pFCO2); - comp.Compare(pFCO, pFCO2, result); - d.TraceDebug("Compare to new object is (expect false) %s\n", result.mResult == cFCOCompare::EQUAL? "true" : "false"); - TEST(result.mResult == cFCOCompare::UNEQUAL); + result = comp.Compare(pFCO, pFCO2); + d.TraceDebug("Compare to new object is (expect false) %s\n", result == cFCOCompare::EQUAL? "true" : "false"); + TEST(result == cFCOCompare::PROPS_UNEQUAL); d.TraceDebug("Properties that differ are:\n"); - result.mPropVector.TraceContents(); + //result.mPropVector.TraceContents(); + cFSDataSourceIter ds3; + ds3.SeekToFCO(cFCOName(FILE_NAME), false); // try testing properties that weren't calculated... d.TraceDebug("Comparing FCOs with different properties calculated\n"); - iFCO* pFCO3 = ds.CreateFCO(cFCOName(FILE_NAME), 0); + iFCO* pFCO3 = ds3.CreateFCO(); v = propCalc.GetPropVector(); v.AddItem(cFSPropSet::PROP_MD5); propCalc.SetPropVector(v); pFCO3->AcceptVisitor(&propCalc); // do the compare comp.SetPropsToCmp(v); - comp.Compare(pFCO2, pFCO3, result); - TEST(result.mResult == cFCOCompare::PROPS_NOT_ALL_VALID); + result = comp.Compare(pFCO2, pFCO3); + TEST(result == cFCOCompare::PROPS_NOT_ALL_VALID); d.TraceDebug("Properties not valid are (should be %d):\n", cFSPropSet::PROP_MD5); - result.mPropVector.TraceContents(); + //result.mPropVector.TraceContents(); // release the fcos pFCO3->Release(); pFCO2->Release(); pFCO->Release(); -#endif + return; } diff --git a/src/twtest/fconametranslator_t.cpp b/src/twtest/fconametranslator_t.cpp index 76d75be..878e0e5 100644 --- a/src/twtest/fconametranslator_t.cpp +++ b/src/twtest/fconametranslator_t.cpp @@ -39,7 +39,7 @@ #include "fco/fconametranslator.h" #include "fco/genreswitcher.h" #include "fco/fconame.h" - +#include "twtest/test.h" void TestName( const TCHAR* pchName, const TCHAR* pchGenre ); void TestUnprintable( const TCHAR* pchName, const TCHAR* pchGenre ); @@ -61,9 +61,9 @@ void TestName( const TCHAR* pchName, const TCHAR* pchGenre ) // set up name translator // iFCONameTranslator* mpCurNT = NULL; - cGenre::Genre gNTFS = cGenreSwitcher::GetInstance()->StringToGenre( pchGenre ); - ASSERT( gNTFS != cGenre::GENRE_INVALID ); - mpCurNT = cGenreSwitcher::GetInstance()->GetFactoryForGenre( gNTFS )->GetNameTranslator(); + cGenre::Genre genre = cGenreSwitcher::GetInstance()->StringToGenre( pchGenre ); + TEST( genre != cGenre::GENRE_INVALID ); + mpCurNT = cGenreSwitcher::GetInstance()->GetFactoryForGenre( genre )->GetNameTranslator(); // // encode name @@ -76,13 +76,13 @@ void TestName( const TCHAR* pchName, const TCHAR* pchGenre ) // unencode name // cFCOName fcoNameNew; - ASSERT( mpCurNT->DisplayStringToFCOName( strName, fcoNameNew ) ); + TEST( mpCurNT->DisplayStringToFCOName( strName, fcoNameNew ) ); TCOUT << _T("> back to: <") << fcoNameNew.AsString() << _T(">") << std::endl; // // check result // - ASSERT( fcoNameNew == fcoName ); + TEST( fcoNameNew == fcoName ); } @@ -92,9 +92,9 @@ void TestUnprintable( const TCHAR* pchName, const TCHAR* pchGenre ) // set up name translator // iFCONameTranslator* mpCurNT = NULL; - cGenre::Genre gNTFS = cGenreSwitcher::GetInstance()->StringToGenre( pchGenre ); - ASSERT( gNTFS != cGenre::GENRE_INVALID ); - mpCurNT = cGenreSwitcher::GetInstance()->GetFactoryForGenre( gNTFS )->GetNameTranslator(); + cGenre::Genre genre = cGenreSwitcher::GetInstance()->StringToGenre( pchGenre ); + TEST( genre != cGenre::GENRE_INVALID ); + mpCurNT = cGenreSwitcher::GetInstance()->GetFactoryForGenre( genre )->GetNameTranslator(); // // encode name @@ -107,11 +107,11 @@ void TestUnprintable( const TCHAR* pchName, const TCHAR* pchGenre ) // unencode name // cFCOName fcoNameNew; - ASSERT( mpCurNT->DisplayStringToFCOName( strName, fcoNameNew ) ); + TEST( mpCurNT->DisplayStringToFCOName( strName, fcoNameNew ) ); // // check result // - ASSERT( fcoNameNew == fcoName ); + TEST( fcoNameNew == fcoName ); } diff --git a/src/twtest/fcopropimpl_t.cpp b/src/twtest/fcopropimpl_t.cpp index 1dc7a2d..11179c5 100644 --- a/src/twtest/fcopropimpl_t.cpp +++ b/src/twtest/fcopropimpl_t.cpp @@ -33,6 +33,7 @@ #include "fco/stdfco.h" #include "fco/fcopropimpl.h" #include "core/debug.h" +#include "twtest/test.h" void TestFCOPropImpl() { @@ -51,22 +52,43 @@ void TestFCOPropImpl() pui64.SetValue(456); pui64b.SetValue(333); d.TraceDebug(_T("property int64 = (should be -456) %s\n"), pi64.AsString().c_str()); + TEST(pi64.AsString() == "-456"); + // test a few operators d.TraceDebug("-456 < 456 (uint cmp to int should fail)= %d\n", pi64.Compare(&pui64, iFCOProp::OP_LT)); + TEST( iFCOProp::CMP_WRONG_PROP_TYPE == pi64.Compare(&pui64, iFCOProp::OP_LT) ); + cFCOPropInt64 p2i64; p2i64.SetValue(4); + d.TraceDebug("-456 < 4 = %d\n", pi64.Compare(&p2i64, iFCOProp::OP_LT)); + TEST( iFCOProp::CMP_TRUE == pi64.Compare(&p2i64, iFCOProp::OP_LT)); + d.TraceDebug("4 == 456 = %d\n", p2i64.Compare(&pi64, iFCOProp::OP_EQ)); + TEST( iFCOProp::CMP_FALSE == p2i64.Compare(&pi64, iFCOProp::OP_EQ)); + d.TraceDebug("333ui64 == 456ui64 = %d\n", pui64.Compare(&pui64b, iFCOProp::OP_EQ)); + TEST( iFCOProp::CMP_FALSE == p2i64.Compare(&pi64, iFCOProp::OP_EQ)); + cFCOPropTSTRING pt1; cFCOPropTSTRING pt2; pt1.SetValue(TSTRING(_T("bar"))); pt2.SetValue(TSTRING(_T("foo"))); + d.TraceDebug(_T("property TSTRING = (should be \"bar\") %s\n"), pt1.AsString().c_str()); + TEST(pt1.AsString() == "bar"); + d.TraceDebug(_T("property TSTRING = (should be \"foo\") %s\n"), pt2.AsString().c_str()); + TEST(pt2.AsString() == "foo"); + d.TraceDebug("bar == foo = %d\n", pt1.Compare(&pt2, iFCOProp::OP_EQ)); + TEST( iFCOProp::CMP_FALSE == pt1.Compare(&pt2, iFCOProp::OP_EQ)); + d.TraceDebug("bar == bar = %d\n", pt1.Compare(&pt1, iFCOProp::OP_EQ)); + TEST( iFCOProp::CMP_TRUE == pt1.Compare(&pt1, iFCOProp::OP_EQ)); + d.TraceDebug("bar == 456 = %d\n", pt1.Compare(&pi64, iFCOProp::OP_EQ)); + TEST( iFCOProp::CMP_WRONG_PROP_TYPE == pt1.Compare(&pi64, iFCOProp::OP_EQ)); d.TraceDebug("Leaving...\n"); return; diff --git a/src/twtest/fcoreport_t.cpp b/src/twtest/fcoreport_t.cpp index 28fbc6c..2959547 100644 --- a/src/twtest/fcoreport_t.cpp +++ b/src/twtest/fcoreport_t.cpp @@ -88,6 +88,7 @@ static void TraceReport(const cFCOReport& r, cDebug& d) } } +//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws void TestFCOReport() { cDebug d("TestFCOReport"); diff --git a/src/twtest/fcospecattr_t.cpp b/src/twtest/fcospecattr_t.cpp index e0c4861..ce244c6 100644 --- a/src/twtest/fcospecattr_t.cpp +++ b/src/twtest/fcospecattr_t.cpp @@ -50,6 +50,7 @@ static void TraceSpecAttr(const cFCOSpecAttr* pAttr, cDebug d) } } +//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws void TestFCOSpecAttr() { cDebug d("TestFCOSpecAttr"); diff --git a/src/twtest/file_t.cpp b/src/twtest/file_t.cpp index 7783dfa..8be0e24 100644 --- a/src/twtest/file_t.cpp +++ b/src/twtest/file_t.cpp @@ -37,6 +37,7 @@ #include "twtest/test.h" #include +//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws void TestFile() { diff --git a/src/twtest/fspropcalc_t.cpp b/src/twtest/fspropcalc_t.cpp index 8bff266..d70bc3f 100644 --- a/src/twtest/fspropcalc_t.cpp +++ b/src/twtest/fspropcalc_t.cpp @@ -33,15 +33,21 @@ #include "fs/stdfs.h" #include "fs/fspropcalc.h" #include "core/debug.h" +#include "core/archive.h" +#include "core/fsservices.h" #include "fco/fcopropset.h" #include "fs/fspropset.h" +#include "fs/fsdatasourceiter.h" #include "twtest/test.h" #include "fco/fco.h" +#include +#include + /////////////////////////////////////////////////////////////////////////////// // PrintProps -- prints out all the valid property names and values as pairs... /////////////////////////////////////////////////////////////////////////////// -/* + static void PrintProps(const iFCO* pFCO) { cDebug d("PrintProps"); @@ -52,35 +58,39 @@ static void PrintProps(const iFCO* pFCO) { if(v.ContainsItem(i)) { - d.TraceDebug("[%d] %s\t%s\n", i, pSet->GetPropName(i), pSet->GetPropAt(i)->AsString().c_str()); + d.TraceDebug("[%d] %s\t%s\n", i, pSet->GetPropName(i).c_str(), pSet->GetPropAt(i)->AsString().c_str()); } } } -*/ - void TestFSPropCalc() { -#pragma message( __FILE__ "(1) : TODO - implement this test file") -#if 0 cDebug d("TestFSPropCalc"); - cFSDataSource ds; - - iFSServices* pFSServices = iFSServices::GetInstance(); - bool bCaseSensitive = pFSServices->IsCaseSensitive(); + cFSDataSourceIter ds; + TSTRING foo_bin = TEMP_DIR; + foo_bin.append("/foo.bin"); + + //iFSServices* pFSServices = iFSServices::GetInstance(); // oh boy! I finally get to test property calculation! d.TraceDebug("Creating FCO c:\\temp\\foo.bin\n"); + std::ofstream fstr(foo_bin); + if(fstr.bad()) + { + d.TraceError("Unable to create test file %s!\n", foo_bin.c_str()); + TEST(false); + } + fstr.close(); + cFileArchive arch; - int ret; - ret = arch.OpenReadWrite(TEMP_DIR _T("/foo.bin"), true); - TEST(ret); + arch.OpenReadWrite(foo_bin.c_str(), true); arch.WriteBlob("\x1\x2\x3\x4\x5\x6\x7\x8\x9\x0", 10); arch.Close(); // get the fco but none of its children... - iFCO* pFCO = ds.CreateFCO(cFCOName(TEMP_DIR _T("/foo.bin")), 0); + ds.SeekToFCO(cFCOName(foo_bin), false); + iFCO* pFCO = ds.CreateFCO(); ASSERT(pFCO); // create the calculator and set some properties to calculate... @@ -111,8 +121,7 @@ void TestFSPropCalc() // test only calculating unevaluated props... d.TraceDebug("invalidating PROP_MD5 in fco, and changing the file. \n\tAll should remain the same except md5.\n"); - ret = arch.OpenReadWrite(TEMP_DIR _T("/foo.bin"), true); - TEST(ret); + arch.OpenReadWrite(foo_bin.c_str(), true); arch.WriteString(_T("Bark Bark Bark\n")); arch.Close(); @@ -126,6 +135,6 @@ void TestFSPropCalc() // release the fco pFCO->Release(); -#endif + return; } diff --git a/src/twtest/genrespeclist_t.cpp b/src/twtest/genrespeclist_t.cpp index d7b839b..3e569dc 100644 --- a/src/twtest/genrespeclist_t.cpp +++ b/src/twtest/genrespeclist_t.cpp @@ -37,12 +37,10 @@ #include "fco/genrespeclist.h" #include "twtest/test.h" #include "fco/fcospecimpl.h" +#include "fs/fs.h" void TestGenreSpecList() { -#pragma message( __FILE__ "(1) : TODO - implement this test file") -#if 0 - cDebug d("TestGenreSpecList"); d.TraceDebug("Entering...\n"); @@ -51,8 +49,8 @@ void TestGenreSpecList() TEST(gslPair.GetGenre() == cGenre::GENRE_INVALID); - gslPair.SetGenre(cGenre::FS); - TEST(gslPair.GetGenre() == cGenre::FS); + gslPair.SetGenre(cFS::GenreID()); + TEST(gslPair.GetGenre() == cFS::GenreID()); cFCOSpecList speclist; cFCOSpecImpl* fsSpec = new cFCOSpecImpl(_T("test fsspce name"), NULL); @@ -91,6 +89,5 @@ void TestGenreSpecList() TEST(gslVector.at(2).GetSpecList().Lookup(fsSpec)->GetName() == gslPair3.GetSpecList().Lookup(fsSpec)->GetName()); d.TraceDebug("All tests passed.\n"); -#endif } diff --git a/src/twtest/genreswitcher_t.cpp b/src/twtest/genreswitcher_t.cpp index a8a58c2..3e898c3 100644 --- a/src/twtest/genreswitcher_t.cpp +++ b/src/twtest/genreswitcher_t.cpp @@ -36,23 +36,22 @@ #include "fco/stdfco.h" #include "fco/genreswitcher.h" #include "twtest/test.h" +#include "fs/fs.h" void TestGenre() { - TCERR << "TODO: genreswitcher_t.cpp test ifdef'd due to unhandled exception" << std::endl; - -#if 0 cDebug d("TestGenre"); d.TraceDebug("Entering...\n"); - TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(0x00020001)) == 0x00020001); - TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(0x00010001)) == 0x00010001); - TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(0x00010002)) == 0x00010002); + TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cFS::GenreID())) == cFS::GenreID()); + + //TODO: GenreToString() dies w/ GENRE_INVALID. Figure out if this should be changed. + // + //TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cGenre::GENRE_INVALID)) == cGenre::GENRE_INVALID); + - TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("fs")) == 0x00020001); - TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("NT file system")) == 0x00010001); + TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("fs")) == cFS::GenreID()); TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("none of the above")) == cGenre::GENRE_INVALID); d.TraceDebug("All tests passed.\n"); -#endif } diff --git a/src/twtest/srefcountobj_t.cpp b/src/twtest/srefcountobj_t.cpp index c2f586b..3ac76ae 100644 --- a/src/twtest/srefcountobj_t.cpp +++ b/src/twtest/srefcountobj_t.cpp @@ -40,6 +40,7 @@ #include "core/debug.h" #include "core/archive.h" #include "core/srefcountobj.h" +#include "twtest/test.h" class cSerRefCountObjTest : public iSerRefCountObj { @@ -133,9 +134,9 @@ void TestSerRefCountObj() serializer.Finit(); } - ASSERT(pObj1 == pObj3); - ASSERT(pObj1 == pObj4); - ASSERT(pObj1 != pObj2); + TEST(pObj1 == pObj3); + TEST(pObj1 == pObj4); + TEST(pObj1 != pObj2); pObj1->Release(); pObj2->Release(); diff --git a/src/twtest/stringencoder_t.cpp b/src/twtest/stringencoder_t.cpp index 2f0852c..646ca31 100644 --- a/src/twtest/stringencoder_t.cpp +++ b/src/twtest/stringencoder_t.cpp @@ -39,6 +39,7 @@ #include "util/stdutil.h" #include "util/stringencoder.h" +#include "twtest/test.h" //========================================================================= // STANDARD LIBRARY INCLUDES @@ -88,5 +89,7 @@ void OutputString( TSTRING& str ) TCOUT << _T("Plain string: <") << str << _T(">") << endl; TCOUT << _T("Encoded string: <") << qe.Encode( str ) << _T(">") << endl; TCOUT << _T("Decoded string: <") << qe.Unencode( str ) << _T(">") << endl << endl ; + + TEST( str == qe.Unencode(qe.Encode(str)) ); } diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index 019282a..4d5b71a 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -145,6 +145,7 @@ void TestHexToString(); void TestQuoteAndBackSlash(); void TestDisplayEncoderBasic(); void TestCharUtilBasic(); +void TestConfigFile2(); /// This is easier than all the (cpp) files and declarations #include "stringutil_t.h" @@ -170,7 +171,7 @@ static void Test(int testID) case 5: TestDebug(); break; case 6: TestError(); break; case 7: TestErrorBucketImpl(); break; - //case 8: TestFCOCompare(); break; + case 8: TestFCOCompare(); break; //case 9: TestFCODatabase(); break; //case 11: TestFCOErrorQueue(); break; case 12: TestFCOName(); break; @@ -188,7 +189,7 @@ static void Test(int testID) case 24: TestFileHeader(); break; //case 25: TestFSDataSource(); break; case 26: TestFSPropSet(); break; - //case 27: TestFSPropCalc(); break; + case 27: TestFSPropCalc(); break; case 28: TestFCOSpecImpl(); break; case 29: TestHashTable(); break; // case 30: TestObjectPool(); break; @@ -241,6 +242,7 @@ static void Test(int testID) case 85: TestQuoteAndBackSlash(); break; case 86: TestDisplayEncoderBasic(); break; case 87: TestCharUtilBasic(); break; + case 88: TestConfigFile2(); break; } } From 7d66656c106f8672d2165b708b9f735c96ad62f1 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 27 Mar 2017 16:43:00 -0700 Subject: [PATCH 34/43] Build fix for tests, since you don't always have an ifstream/ofstream constructor that takes a string reference --- src/twtest/fspropcalc_t.cpp | 2 +- src/twtest/policyparser_t.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/twtest/fspropcalc_t.cpp b/src/twtest/fspropcalc_t.cpp index d70bc3f..1e56b4c 100644 --- a/src/twtest/fspropcalc_t.cpp +++ b/src/twtest/fspropcalc_t.cpp @@ -75,7 +75,7 @@ void TestFSPropCalc() // oh boy! I finally get to test property calculation! d.TraceDebug("Creating FCO c:\\temp\\foo.bin\n"); - std::ofstream fstr(foo_bin); + std::ofstream fstr(foo_bin.c_str()); if(fstr.bad()) { d.TraceError("Unable to create test file %s!\n", foo_bin.c_str()); diff --git a/src/twtest/policyparser_t.cpp b/src/twtest/policyparser_t.cpp index 2353f14..8a5c3c5 100644 --- a/src/twtest/policyparser_t.cpp +++ b/src/twtest/policyparser_t.cpp @@ -75,7 +75,7 @@ void test_policy_file(const std::string& polfile) pol_path.append(polfile); std::ifstream in; - in.open(pol_path); + in.open(pol_path.c_str()); if( ! in.good() ) throw eParserHelper( _T("couldn't open test file") ); From f549b069af9af36b2af11359b6d823bc9606a16a Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 27 Mar 2017 18:49:07 -0700 Subject: [PATCH 35/43] Remove installer check for tar since installer doesn't actually use it; remove some cleanup meant for an ancient patch lost in the mists of time --- configure | 7 ------- configure.ac | 6 ------ installer/install.sh | 12 ------------ 3 files changed, 25 deletions(-) diff --git a/configure b/configure index e92f2bd..00df1a1 100755 --- a/configure +++ b/configure @@ -3462,13 +3462,6 @@ fi ac_config_headers="$ac_config_headers config.h" - - - - -rm -f src/tripwire/syslog.h 2> /dev/null -chmod 755 install-sh 2> /dev/null - CFLAGS=${CFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} diff --git a/configure.ac b/configure.ac index e10a6af..2e72058 100644 --- a/configure.ac +++ b/configure.ac @@ -11,12 +11,6 @@ AM_CONFIG_HEADER(config.h) AC_COPYRIGHT([The developer of the original code and/or files is Tripwire, Inc. Portions created by Tripwire, Inc. are copyright 2000-2017 Tripwire, Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights reserved.]) AC_REVISION([$Revision: 2.4.3.5 $]) -dnl ################################# -dnl Cleanup Cruft Leftover From Patch -dnl ################################# -rm -f src/tripwire/syslog.h 2> /dev/null -chmod 755 install-sh 2> /dev/null - dnl ############### dnl Setup defaults dnl ############### diff --git a/installer/install.sh b/installer/install.sh index 3d571ae..5b39d45 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -42,18 +42,6 @@ else c="" fi -##------------------------------------------------------- -## Better have a copy of tar! -## If /bin/sh does not exist or is not readable (seems -## fairly unlikely), then this will fail. -##------------------------------------------------------- - -(tar cvf /dev/null /bin/sh) 2> /dev/null 1>&2 -if [ $? -ne 0 ]; then - echo "tar command not found -- aborting install." - exit 1 -fi - ##------------------------------------------------------- ## Can't live without sed. ##------------------------------------------------------- From 4af1375fb15846b3589606ca4dd7f453d4741072 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 27 Mar 2017 22:45:55 -0700 Subject: [PATCH 36/43] More unit test cleanup, + fix a warning in msystem le_set() --- src/core/msystem.cpp | 1 - src/twtest/blockfile_t.cpp | 3 +- src/twtest/blockrecordarray_t.cpp | 2 +- src/twtest/cmdlineparser_t.cpp | 2 + src/twtest/codeconvert_t.cpp | 14 +-- src/twtest/crytpo_t.cpp | 8 +- src/twtest/displayencoder_t.cpp | 16 ++-- src/twtest/fcocompare_t.cpp | 2 +- src/twtest/fcodatabasefile_t.cpp | 2 +- src/twtest/fcopropvector_t.cpp | 3 + src/twtest/fcoreport_t.cpp | 142 ++++++++++++++++-------------- src/twtest/fcospecattr_t.cpp | 68 ++++++++------ src/twtest/file_t.cpp | 73 ++++++++------- src/twtest/fspropcalc_t.cpp | 2 +- src/twtest/fsspec_t.cpp | 39 ++++---- src/twtest/genre_t.cpp | 30 ++----- src/twtest/hierdatabase_t.cpp | 7 +- src/twtest/keyfile_t.cpp | 4 +- src/twtest/platform_t.cpp | 18 ++-- src/twtest/refcountobj_t.cpp | 5 +- src/twtest/test.cpp | 47 +++++----- src/twtest/textreportviewer_t.cpp | 101 ++++++++++++--------- src/twtest/twlocale_t.cpp | 28 +++--- src/twtest/twutil_t.cpp | 42 +++++---- 24 files changed, 350 insertions(+), 309 deletions(-) diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index ae0179d..a4a120a 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -403,7 +403,6 @@ char *env; * just include it from the current environment * (if not defined there, don't define it here) */ - size_t p_size=0; if (strchr(env, '=') == NULL) { q = getenv(env); diff --git a/src/twtest/blockfile_t.cpp b/src/twtest/blockfile_t.cpp index 65089e9..0581f42 100644 --- a/src/twtest/blockfile_t.cpp +++ b/src/twtest/blockfile_t.cpp @@ -43,7 +43,7 @@ void TestBlockFile() try { - static const TCHAR fileName[] = _T("c:/tmp/test.bf"); + static const TCHAR fileName[] = _T("test.bf"); // truncate the file I am going to use... // cFileArchive a; @@ -113,6 +113,7 @@ void TestBlockFile() } catch( eError& e ) { + TCERR << "Exception: " << e.GetMsg() << std::endl; d.TraceError( _T("Exception caught: %d %s\n"), e.GetID(), e.GetMsg().c_str() ); TEST( false ); } diff --git a/src/twtest/blockrecordarray_t.cpp b/src/twtest/blockrecordarray_t.cpp index 4af4aff..c160724 100644 --- a/src/twtest/blockrecordarray_t.cpp +++ b/src/twtest/blockrecordarray_t.cpp @@ -42,7 +42,7 @@ void TestBlockRecordArray() cDebug d( "TestBlockRecordArray" ); try { - static const TCHAR fileName[] = _T("c:/tmp/test.bf"); + static const TCHAR fileName[] = _T("test.bf"); cBlockFile bf; bf.Open( fileName, 2, true ); // opened up with two pages diff --git a/src/twtest/cmdlineparser_t.cpp b/src/twtest/cmdlineparser_t.cpp index 57eaec1..8996d80 100644 --- a/src/twtest/cmdlineparser_t.cpp +++ b/src/twtest/cmdlineparser_t.cpp @@ -88,6 +88,7 @@ const TCHAR* argv5[] = _T("frog") }; +#ifdef _DEBUG static void PrintCmdLine(int argc, const TCHAR** argv, cDebug d) { TSTRING str; @@ -99,6 +100,7 @@ static void PrintCmdLine(int argc, const TCHAR** argv, cDebug d) } d.TraceDebug(_T(">>>%s\n"), str.c_str()); } +#endif static void test_parse(cCmdLineParser& parser, const int argc, const TCHAR** argv, bool should_throw) { diff --git a/src/twtest/codeconvert_t.cpp b/src/twtest/codeconvert_t.cpp index 85eb874..36cb169 100644 --- a/src/twtest/codeconvert_t.cpp +++ b/src/twtest/codeconvert_t.cpp @@ -142,7 +142,7 @@ size_t DistanceToOne( size_t n ) n = ( n >> 1 ); } - ASSERT( n == 1 ); // n was not a power of 2! + TEST( n == 1 ); // n was not a power of 2! return dist; } @@ -159,14 +159,14 @@ void ConvertAndCompareString( const std::string& s ) wc16_string ws; ws.resize( s.length() ); nWrote = iCodeConverter::GetInstance()->Convert( (ntdbs_t)ws.c_str(), ws.length(), s.c_str(), ws.length() ); - ASSERT( nWrote != -1 ); + TEST( nWrote != -1 ); ws.resize( nWrote ); // convert back to mbchar_t string std::string s2; s2.resize( ws.length() * MB_CUR_MAX ); nWrote = iCodeConverter::GetInstance()->Convert( (ntmbs_t)s2.c_str(), s2.length(), ws.c_str(), ws.length() ); - ASSERT( nWrote != -1 ); + TEST( nWrote != -1 ); s2.resize( nWrote ); std::cout << "* Result : "; @@ -195,10 +195,10 @@ void TestMbToDb() for( size_t j = 0; j < 0x10; j++ ) { size_t first_byte = ( i & 0xFF00 ) >> 8; - ASSERT( first_byte <= 0xFF ); + TEST( first_byte <= 0xFF ); size_t second_byte = ( ( i & 0x00F0 ) >> 4 ) | j; - ASSERT( second_byte <= 0xFF ); + TEST( second_byte <= 0xFF ); s[ 2 * j ] = NonZeroChar( (char)first_byte ); s[ ( 2 * j ) + 1 ] = NonZeroChar( (char)second_byte ); @@ -221,10 +221,10 @@ void TestMbToDb() for( size_t j = 0; j < CHARS_AT_A_TIME; j++ ) { size_t first_byte = ( ( i & FIRST_BYTE_MASK ) >> DistanceToOne( CHARS_AT_A_TIME ) ); - ASSERT( first_byte <= 0xFF ); + TEST( first_byte <= 0xFF ); size_t second_byte = ( ( i & ( SECOND_BYTE_MASK << DistanceToOne( CHARS_AT_A_TIME ) ) | j ); - ASSERT( second_byte <= 0xFF ); + TEST( second_byte <= 0xFF ); s[ 2 * j ] = NonZeroChar( (char)first_byte ); s[ ( 2 * j ) + 1 ] = NonZeroChar( (char)second_byte ); diff --git a/src/twtest/crytpo_t.cpp b/src/twtest/crytpo_t.cpp index 6d30c83..5777579 100644 --- a/src/twtest/crytpo_t.cpp +++ b/src/twtest/crytpo_t.cpp @@ -128,11 +128,11 @@ void TestCrypto() cRSAPublicKey* pPublic2; cRSAPrivateKey* pPrivate2; - ASSERT(pPublic->GetWriteLen() < BUFSIZE); + TEST(pPublic->GetWriteLen() < BUFSIZE); pPublic->Write(buf); pPublic2 = new cRSAPublicKey(buf); - ASSERT(pPrivate->GetWriteLen() < BUFSIZE); + TEST(pPrivate->GetWriteLen() < BUFSIZE); pPrivate->Write(buf); pPrivate2 = new cRSAPrivateKey(buf); @@ -298,11 +298,11 @@ void TestCrypto() cElGamalSigPublicKey* pPublic2; cElGamalSigPrivateKey* pPrivate2; - ASSERT(pPublic->GetWriteLen() < BUFSIZE); + TEST(pPublic->GetWriteLen() < BUFSIZE); pPublic->Write(buf); pPublic2 = new cElGamalSigPublicKey(buf); - ASSERT(pPrivate->GetWriteLen() < BUFSIZE); + TEST(pPrivate->GetWriteLen() < BUFSIZE); pPrivate->Write(buf); pPrivate2 = new cElGamalSigPrivateKey(buf); diff --git a/src/twtest/displayencoder_t.cpp b/src/twtest/displayencoder_t.cpp index 1a467a6..cd31847 100644 --- a/src/twtest/displayencoder_t.cpp +++ b/src/twtest/displayencoder_t.cpp @@ -75,7 +75,7 @@ static void util_TestUnprintable( const TSTRING& strCUnprintable ) TSTRING strOut = strEncoded; e.Decode( strOut ); - ASSERT( strOut == strCUnprintable ); + TEST( strOut == strCUnprintable ); } @@ -186,8 +186,8 @@ void TestUnconvertable() ch = 0x ## n; \ str = ch; \ e.Encode( str ); \ -// ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T("\\x") _T( #n ) _T("x") ); + ct.tolower( str.begin(), str.end() ); \ + TEST( str == _T("\\x") _T( #n ) _T("x") ); TSS_UNCONVERTABLE_TEST( fefe ); TSS_UNCONVERTABLE_TEST( 1234 ); @@ -215,8 +215,8 @@ void TestUnprintable() ch = 0x ## n; \ str = ch; \ e.Encode( str ); \ -// ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T("\\x") _T( #n ) _T("x") ); + ct.tolower( str.begin(), str.end() ); \ + TEST( str == _T("\\x") _T( #n ) _T("x") ); TSS_UNPRINTABLE_TEST( 000a ); TSS_UNPRINTABLE_TEST( 000d ); @@ -233,11 +233,11 @@ void TestQuoteAndBackSlash() str = _T("\\"); e.Encode( str ); - ASSERT( str == _T("\\\\") ); + TEST( str == _T("\\\\") ); str = _T("\""); e.Encode( str ); - ASSERT( str == _T("\\\"") ); + TEST( str == _T("\\\"") ); } // TODO:BAM -- try multibyte now..... @@ -325,7 +325,7 @@ void TestDisplayEncoderBasic() catch( eError& e ) { cErrorReporter::PrintErrorMsg( e ); - ASSERT(false); + TEST(false); } } diff --git a/src/twtest/fcocompare_t.cpp b/src/twtest/fcocompare_t.cpp index 180da11..52659c3 100644 --- a/src/twtest/fcocompare_t.cpp +++ b/src/twtest/fcocompare_t.cpp @@ -125,7 +125,7 @@ void TestFCOCompare() cFSDataSourceIter ds2; ds2.SeekToFCO(cFCOName(FILE_NAME), false); iFCO* pFCO2 = ds2.CreateFCO(); - ASSERT(pFCO2); + TEST(pFCO2); pFCO2->AcceptVisitor(&propCalc); d.TraceDebug("Second FCO's properties:\n"); PrintProps(pFCO2); diff --git a/src/twtest/fcodatabasefile_t.cpp b/src/twtest/fcodatabasefile_t.cpp index 3b58d8f..829582a 100644 --- a/src/twtest/fcodatabasefile_t.cpp +++ b/src/twtest/fcodatabasefile_t.cpp @@ -35,5 +35,5 @@ void TestFCODatabaseFile() { - + //TODO - actually test something here } diff --git a/src/twtest/fcopropvector_t.cpp b/src/twtest/fcopropvector_t.cpp index d281683..6328afc 100644 --- a/src/twtest/fcopropvector_t.cpp +++ b/src/twtest/fcopropvector_t.cpp @@ -114,6 +114,8 @@ static bool init (cFCOPropVector &testV) return true; } //end init + +#if 0 // TODO: rework this so it doesn't need user interaction static bool addRemove (cFCOPropVector &test1, cFCOPropVector &test2, cDebug& d) { int var1 = 0 , var2 = 64, var3 = 2; @@ -191,6 +193,7 @@ static bool addRemove (cFCOPropVector &test1, cFCOPropVector &test2, cDebug& d) out &= local; //and-ing of results. return out; }//end addRemove +#endif static bool objManip (cFCOPropVector &testV, cDebug& d) { diff --git a/src/twtest/fcoreport_t.cpp b/src/twtest/fcoreport_t.cpp index 2959547..960c80d 100644 --- a/src/twtest/fcoreport_t.cpp +++ b/src/twtest/fcoreport_t.cpp @@ -42,6 +42,7 @@ #include "core/errorbucketimpl.h" #include "fco/fcospecattr.h" #include "fco/fcospechelper.h" +#include "fs/fs.h" #include // we use this instead of TraceContents() so we can test the report iterators. @@ -62,7 +63,7 @@ static void TraceReport(const cFCOReport& r, cDebug& d) for(specIter.SeekBegin(); ! specIter.Done(); specIter.Next(), ++specCount) { d.TraceDebug(">>> Spec [%d]:\n", specCount); - ASSERT(specIter.GetSpec()); + TEST(specIter.GetSpec()); specIter.GetSpec()->TraceContents(); specIter.GetAttr()->TraceContents(); specIter.GetErrorQueue()->TraceContents(); @@ -88,86 +89,97 @@ static void TraceReport(const cFCOReport& r, cDebug& d) } } -//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws + void TestFCOReport() { cDebug d("TestFCOReport"); - - cFCOSpecImpl* pSpec = new cFCOSpecImpl(_T("/etc"), NULL, new cFCOSpecStopPointSet); - cFCOSpecAttr* pAttr = new cFCOSpecAttr; - cFSObject* addedFCO = new cFSObject(cFCOName(_T("/etc/added_file"))); - cFSObject* removedFCO = new cFSObject(cFCOName(_T("/etc/removed_file"))); - cFSObject* changedFCO = new cFSObject(cFCOName(_T("/etc/changed_file"))); - cFSObject* oldChangedFCO = new cFSObject(cFCOName(_T("/etc/changed_file"))); - cFSObject* newChangedFCO = new cFSObject(cFCOName(_T("/etc/changed_file"))); - cFCOPropVector changedPropVector; - - //Calculate the time taken to generate the test report: - time_t* dummy_arg = NULL; - time_t time_finish; - //time_t time_begin = time(dummy_arg); - + try { - cFCOReport report; + cFCOSpecImpl* pSpec = new cFCOSpecImpl(_T("/etc"), NULL, new cFCOSpecStopPointSet); + cFCOSpecAttr* pAttr = new cFCOSpecAttr; + cFSObject* addedFCO = new cFSObject(cFCOName(_T("/etc/added_file"))); + cFSObject* removedFCO = new cFSObject(cFCOName(_T("/etc/removed_file"))); + cFSObject* changedFCO = new cFSObject(cFCOName(_T("/etc/changed_file"))); + cFSObject* oldChangedFCO = new cFSObject(cFCOName(_T("/etc/changed_file"))); + cFSObject* newChangedFCO = new cFSObject(cFCOName(_T("/etc/changed_file"))); + cFCOPropVector changedPropVector; - changedPropVector.AddItem(cFSPropSet::PROP_SIZE); - pSpec->SetStartPoint(cFCOName(_T("/etc"))); - pAttr->SetName(_T("/etc")); - pAttr->SetSeverity(53); + //Calculate the time taken to generate the test report: + time_t* dummy_arg = NULL; + time_t time_finish; + //time_t time_begin = time(dummy_arg); - report.AddSpec(0x00020001, pSpec, pAttr); // TODO:bam - change these - cFCOReportSpecIter it(report, 0x00020001); // to use cFS::Genre - it.GetAddedSet()->Insert(addedFCO); - it.GetRemovedSet()->Insert(removedFCO); - report.AddChangedFCO(it, oldChangedFCO, newChangedFCO, changedPropVector); - - //Store the time taken to generate the test report: - time_finish = time(dummy_arg); - //report.SetCreationTime( (int64)difftime(time_finish, time_begin)); - //d.TraceDebug("Report calculation time = %I64i seconds.\n", report.GetCreationTime()); - - d.TraceDebug("Before serializing report:\n"); - TraceReport(report, d); { - cFileArchive outFile; - outFile.OpenReadWrite(_T("tmp.twr")); - cSerializerImpl outSer(outFile, cSerializerImpl::S_WRITE); + cFCOReport report; - outSer.Init(); - outSer.WriteObject(&report); - outSer.Finit(); + changedPropVector.AddItem(cFSPropSet::PROP_SIZE); + pSpec->SetStartPoint(cFCOName(_T("/etc"))); + pAttr->SetName(_T("/etc")); + pAttr->SetSeverity(53); - outFile.Close(); + report.AddSpec(cFS::GenreID(), pSpec, pAttr); + cFCOReportSpecIter it(report, cFS::GenreID()); + it.GetAddedSet()->Insert(addedFCO); + it.GetRemovedSet()->Insert(removedFCO); + report.AddChangedFCO(it, oldChangedFCO, newChangedFCO, changedPropVector); - cFileArchive inFile; - inFile.OpenRead(_T("tmp.twr")); - cSerializerImpl inSer(inFile, cSerializerImpl::S_READ); + //Store the time taken to generate the test report: + time_finish = time(dummy_arg); + //report.SetCreationTime( (int64)difftime(time_finish, time_begin)); + //d.TraceDebug("Report calculation time = %I64i seconds.\n", report.GetCreationTime()); - cFCOReport inReport; + d.TraceDebug("Before serializing report:\n"); + TraceReport(report, d); + { + cFileArchive outFile; + outFile.OpenReadWrite(_T("tmp.twr")); + cSerializerImpl outSer(outFile, cSerializerImpl::S_WRITE); - inSer.Init(); - inSer.ReadObject(&inReport); - inSer.Finit(); + outSer.Init(); + outSer.WriteObject(&report); + outSer.Finit(); - d.TraceDebug("Read in serialized report:\n"); - TraceReport(inReport, d); + outFile.Close(); + + cFileArchive inFile; + inFile.OpenRead(_T("tmp.twr")); + cSerializerImpl inSer(inFile, cSerializerImpl::S_READ); + + cFCOReport inReport; + + inSer.Init(); + inSer.ReadObject(&inReport); + inSer.Finit(); + + d.TraceDebug("Read in serialized report:\n"); + TraceReport(inReport, d); + } } + + // TODO -- test cFCOReportSpecIter::Remove() + // TODO -- test cFCOReportChangeIter::Remove() + d.TraceDebug("*** We still need to test Remove() for the two iterator classes!\n"); + + pSpec->Release(); + pAttr->Release(); + addedFCO->Release(); + removedFCO->Release(); + changedFCO->Release(); + oldChangedFCO->Release(); + newChangedFCO->Release(); + } - - // TODO -- test cFCOReportSpecIter::Remove() - // TODO -- test cFCOReportChangeIter::Remove() - d.TraceDebug("*** We still need to test Remove() for the two iterator classes!\n"); - - pSpec->Release(); - pAttr->Release(); - addedFCO->Release(); - removedFCO->Release(); - changedFCO->Release(); - oldChangedFCO->Release(); - newChangedFCO->Release(); - + catch(const eError& e) + { + TCERR << std::endl << e.GetMsg() << std::endl; + TEST(false); + } + catch(...) + { + TEST(false); + } + d.TraceDebug("Leaving...\n"); - return; } diff --git a/src/twtest/fcospecattr_t.cpp b/src/twtest/fcospecattr_t.cpp index ce244c6..0979dee 100644 --- a/src/twtest/fcospecattr_t.cpp +++ b/src/twtest/fcospecattr_t.cpp @@ -36,6 +36,7 @@ #include "twtest/test.h" #include "core/archive.h" #include "core/serializerimpl.h" +#include "twtest/test.h" static void TraceSpecAttr(const cFCOSpecAttr* pAttr, cDebug d) { @@ -50,39 +51,52 @@ static void TraceSpecAttr(const cFCOSpecAttr* pAttr, cDebug d) } } -//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws + void TestFCOSpecAttr() { cDebug d("TestFCOSpecAttr"); - d.TraceDebug("Entering\n"); - cFCOSpecAttr* pAttr = new cFCOSpecAttr; + + try + { + d.TraceDebug("Entering\n"); + cFCOSpecAttr* pAttr = new cFCOSpecAttr; - pAttr->SetName (_T("My Name")); d.TraceDebug("Setting Name = My Name\n"); - pAttr->SetSeverity (53); d.TraceDebug("Setting Severity = 53\n"); - pAttr->AddEmail (_T("dog@bark.com")); d.TraceDebug("Adding email = dog@bark.com\n"); - pAttr->AddEmail (_T("cow@moo.com")); d.TraceDebug("Adding email = cow@moo.com\n"); - pAttr->AddEmail (_T("cat@meow.com")); d.TraceDebug("Adding email = cat@meow.com\n"); + pAttr->SetName (_T("My Name")); d.TraceDebug("Setting Name = My Name\n"); + pAttr->SetSeverity (53); d.TraceDebug("Setting Severity = 53\n"); + pAttr->AddEmail (_T("dog@bark.com")); d.TraceDebug("Adding email = dog@bark.com\n"); + pAttr->AddEmail (_T("cow@moo.com")); d.TraceDebug("Adding email = cow@moo.com\n"); + pAttr->AddEmail (_T("cat@meow.com")); d.TraceDebug("Adding email = cat@meow.com\n"); - // trace contents... - TraceSpecAttr(pAttr, d); + // trace contents... + TraceSpecAttr(pAttr, d); - // test serialization... - d.TraceDebug("Testing Serialization; next output should be the same as the previous\n"); - cMemoryArchive a; - cSerializerImpl s(a, cSerializerImpl::S_WRITE); - s.Init(); - pAttr->Write(&s); - s.Finit(); - a.Seek(0, cBidirArchive::BEGINNING); - cFCOSpecAttr* pNew = new cFCOSpecAttr; - cSerializerImpl s2(a, cSerializerImpl::S_READ); - s2.Init(); - pNew->Read(&s2); - s2.Finit(); + // test serialization... + d.TraceDebug("Testing Serialization; next output should be the same as the previous\n"); + cMemoryArchive a; + cSerializerImpl s(a, cSerializerImpl::S_WRITE); + s.Init(); + pAttr->Write(&s); + s.Finit(); + a.Seek(0, cBidirArchive::BEGINNING); + cFCOSpecAttr* pNew = new cFCOSpecAttr; + cSerializerImpl s2(a, cSerializerImpl::S_READ); + s2.Init(); + pNew->Read(&s2); + s2.Finit(); - // trace contents... - TraceSpecAttr(pNew, d); + // trace contents... + TraceSpecAttr(pNew, d); - pNew->Release(); - pAttr->Release(); + pNew->Release(); + pAttr->Release(); + } + catch(const eError& e) + { + TCERR << std::endl << e.GetMsg() << std::endl; + TEST(false); + } + catch(...) + { + TEST(false); + } } diff --git a/src/twtest/file_t.cpp b/src/twtest/file_t.cpp index 8be0e24..8f0f16d 100644 --- a/src/twtest/file_t.cpp +++ b/src/twtest/file_t.cpp @@ -37,44 +37,57 @@ #include "twtest/test.h" #include -//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws void TestFile() { + try + { + TSTRING fileName = TEMP_DIR; + fileName += _T("/file_test.bin"); - TSTRING fileName = TEMP_DIR; - fileName += _T("/file_test.bin"); + //Create a temporary file for testing: + FILE* testStream; + testStream = _tfopen( fileName.c_str(), _T("w+b")); + TEST(testStream); + + TSTRING testString( _T("This is a test") ); + int iTestStringLength = testString.length(); - //Create a temporary file for testing: - FILE* testStream; - testStream = _tfopen( fileName.c_str(), _T("w+b")); - TSTRING testString( _T("This is a test") ); - int iTestStringLength = testString.length(); + //Write some data to the stream... + fwrite( testString.c_str(), sizeof(TCHAR), iTestStringLength, testStream ); + fclose( testStream ); - //Write some data to the stream... - fwrite( testString.c_str(), sizeof(TCHAR), iTestStringLength, testStream ); - fclose( testStream ); + //Open the file again, for reading only this time. + testStream = _tfopen( fileName.c_str(), _T("rb") ); + TEST(testStream); + + cFile fTempFile; + //Try attaching one of our file objects to the stream. + //TODO: fTempFile.AttachRead( testStream ); - //Open the file again, for reading only this time. - testStream = _tfopen( fileName.c_str(), _T("rb") ); + //Try reading something from the file object + TCHAR buffer[40]; + TCHAR buffer2[40]; - cFile fTempFile; - //Try attaching one of our file objects to the stream. -//TODO: fTempFile.AttachRead( testStream ); + fTempFile.Read( buffer, sizeof(TCHAR) * iTestStringLength ); + fTempFile.Close(); - //Try reading something from the file object - TCHAR buffer[40]; - TCHAR buffer2[40]; - - fTempFile.Read( buffer, sizeof(TCHAR) * iTestStringLength ); - fTempFile.Close(); - - testStream = _tfopen( fileName.c_str(), _T("a+b") ); -//TODO: fTempFile.AttachReadWrite( testStream ); - - //Now try writing something to the stream. - fTempFile.Write( testString.c_str(), sizeof(TCHAR) * iTestStringLength ); - fTempFile.Rewind(); - fTempFile.Read( buffer2, sizeof(TCHAR) * iTestStringLength * 2 ); + testStream = _tfopen( fileName.c_str(), _T("a+b") ); + TEST(testStream); + //TODO: fTempFile.AttachReadWrite( testStream ); + //Now try writing something to the stream. + fTempFile.Write( testString.c_str(), sizeof(TCHAR) * iTestStringLength ); + fTempFile.Rewind(); + fTempFile.Read( buffer2, sizeof(TCHAR) * iTestStringLength * 2 ); + } + catch(const eError& e) + { + TCERR << std::endl << e.GetMsg() << std::endl; + TEST(false); + } + catch(...) + { + TEST(false); + } } diff --git a/src/twtest/fspropcalc_t.cpp b/src/twtest/fspropcalc_t.cpp index 1e56b4c..33df796 100644 --- a/src/twtest/fspropcalc_t.cpp +++ b/src/twtest/fspropcalc_t.cpp @@ -91,7 +91,7 @@ void TestFSPropCalc() // get the fco but none of its children... ds.SeekToFCO(cFCOName(foo_bin), false); iFCO* pFCO = ds.CreateFCO(); - ASSERT(pFCO); + TEST(pFCO); // create the calculator and set some properties to calculate... cFSPropCalc propCalc; diff --git a/src/twtest/fsspec_t.cpp b/src/twtest/fsspec_t.cpp index 472e9f9..cc6586d 100644 --- a/src/twtest/fsspec_t.cpp +++ b/src/twtest/fsspec_t.cpp @@ -34,13 +34,14 @@ #include "fco/stdfco.h" #include "fco/fcospecimpl.h" #include "core/debug.h" -//#include "fs/fsdatasource.h" +#include "fs/fsdatasourceiter.h" #include "fco/iterproxy.h" #include "core/error.h" #include "twtest/test.h" #include "fco/fcospechelper.h" #include "core/fsservices.h" + /////////////////////////////////////////////////////////////////////////////// // PrintFCOTree -- recursively prints an fco's name and all of it's children's /////////////////////////////////////////////////////////////////////////////// @@ -69,43 +70,35 @@ void TestFCOSpecImpl() cDebug d("TestFCOSpecImpl"); d.TraceDebug("Entering...\n"); - //********************* - // - // TODO -- As of tripwire 2.1, this needs to be updated! - // 28 Jan 99 mdb - // - //********************* - ASSERT( false ); -/* - cFSDataSource dataSrc; - iFSServices* pFSS = iFSServices::GetInstance(); - + cFSDataSourceIter dataSrc; // test AllChildStopPoint fcos... d.TraceDebug("Now testing a spec whose start point is the only thing it maps to (%s)\n", TEMP_DIR); cFCOSpecImpl* pSpec2 = new cFCOSpecImpl(TEMP_DIR, &dataSrc, new cFCOSpecNoChildren); pSpec2->SetStartPoint(cFCOName(TEMP_DIR)); - iFCO* pFCO = pSpec2->CreateFCO(pSpec2->GetStartPoint(), iFCODataSource::CHILDREN_ALL); - PrintFCOTree(pFCO, d, 0); + dataSrc.SeekToFCO(pSpec2->GetStartPoint(), false); + iFCO* pFCO = dataSrc.CreateFCO(); + TEST(pFCO); + //PrintFCOTree(pFCO, d, 0); pFCO->Release(); // create an FSSpec and set up some start and stop points... cFCOSpecStopPointSet* pSet = new cFCOSpecStopPointSet; cFCOSpecImpl* pSpec = new cFCOSpecImpl(_T("Test FSSpec"), &dataSrc, pSet); - pSpec->SetStartPoint(cFCOName(_T("d:/code"))); - pSet->Add(cFCOName(_T("d:/code/open gl"))); - pSet->Add(cFCOName(_T("d:/code/pclient"))); + pSpec->SetStartPoint(cFCOName(_T("/etc"))); + pSet->Add(cFCOName(_T("/etc/open gl"))); + pSet->Add(cFCOName(_T("/etc/pclient"))); // create all the fcos... - pFCO = pSpec->CreateFCO(pSpec->GetStartPoint(), iFCODataSource::CHILDREN_ALL); - ASSERT(pFCO); - PrintFCOTree(pFCO, d, 0); - pFCO->Release(); + cFSDataSourceIter dataSrc2; + dataSrc2.SeekToFCO(pSpec->GetStartPoint(), false); + iFCO* pFCO2 = dataSrc2.CreateFCO(); + TEST(pFCO2); + //PrintFCOTree(pFCO, d, 0); + pFCO2->Release(); // TODO -- test Clone(), copy ctor, operator= pSpec->Release(); - return; -*/ } diff --git a/src/twtest/genre_t.cpp b/src/twtest/genre_t.cpp index e8dd325..a62de95 100644 --- a/src/twtest/genre_t.cpp +++ b/src/twtest/genre_t.cpp @@ -36,38 +36,26 @@ #include "fco/stdfco.h" #include "fco/genreswitcher.h" #include "twtest/test.h" +#include "fs/fs.h" -#ifdef _CPPRTTI #include "fs/fsfactory.h" -#include "ntfs/ntfsfactory.h" -#endif void TestGenreSwitcher() { -#pragma message( __FILE__ "(1) : TODO - implement this test file") -#if 0 cDebug d("TestGenreSwitcher"); d.TraceDebug("Entering...\n"); - // normally we use the cGenreSwitcher::GetInstance() interface - // to get access the class singleton. But for testing purposes - // we will put have one reside on the stack. - cGenreSwitcher genreSwitcher; + cGenreSwitcher* genreSwitcher = cGenreSwitcher::GetInstance(); - TEST(genreSwitcher.CurrentGenre() == cGenre::GENRE_INVALID); + TEST(genreSwitcher->CurrentGenre() == cFS::GenreID()); + + // can't switch to invalid genre + //genreSwitcher->SelectGenre(cGenre::GENRE_INVALID); + //TEST(genreSwitcher->CurrentGenre() == cGenre::GENRE_INVALID); - genreSwitcher.SelectGenre(cGenre::FS); - TEST(genreSwitcher.CurrentGenre() == cGenre::FS); - #ifdef _CPPRTTI + genreSwitcher->SelectGenre(cFS::GenreID()); + TEST(genreSwitcher->CurrentGenre() == cFS::GenreID()); TEST(typeid(*iTWFactory::GetInstance()) == typeid(cFSFactory)); - #endif - - genreSwitcher.SelectGenre(cGenre::NTFS); - TEST(genreSwitcher.CurrentGenre() == cGenre::NTFS); - #ifdef _CPPRTTI - TEST(typeid(*iTWFactory::GetInstance()) == typeid(cNTFSFactory)); - #endif d.TraceDebug("All tests passed.\n"); -#endif //#if 0 } diff --git a/src/twtest/hierdatabase_t.cpp b/src/twtest/hierdatabase_t.cpp index e3a7545..22d6d49 100644 --- a/src/twtest/hierdatabase_t.cpp +++ b/src/twtest/hierdatabase_t.cpp @@ -73,12 +73,15 @@ static void GetNoun( TSTRING& noun ) /////////////////////////////////////////////////////////////////////////////// void TestHierDatabaseInteractive() { + TCERR << std::endl << "TestHierDatabaseInteractive needs to be redesigned (& renamed) to not require user interaction" << std::endl; + +#if 0 cDebug d( "TestHierDatabaseInteractive" ); try { cHierDatabase db; //db.Open( _T("c:/tmp/tw.hdb"), 5, true); - db.Open( _T("c:/tmp/tw.db"), 5, false); + db.Open( _T("tw.db"), 5, false); cHierDatabase::iterator iter(&db); while( true ) @@ -346,5 +349,5 @@ void TestHierDatabaseInteractive() d.TraceError( "Exception caught: %d %s\n", e.GetID(), e.GetMsg().c_str() ); TEST( false ); } - +#endif } diff --git a/src/twtest/keyfile_t.cpp b/src/twtest/keyfile_t.cpp index fd03d3f..fa6f79d 100644 --- a/src/twtest/keyfile_t.cpp +++ b/src/twtest/keyfile_t.cpp @@ -70,8 +70,8 @@ void TestKeyFile() { cElGamalSig elGamal(*keyfile.GetPublicKey()); - ASSERT(elGamal.GetBlockSizePlain() < 9000); - ASSERT(elGamal.GetBlockSizeCipher() < 9000); + TEST(elGamal.GetBlockSizePlain() < 9000); + TEST(elGamal.GetBlockSizeCipher() < 9000); std::string s = "haybaby"; cPrivateKeyProxy key; TEST(key.AquireKey(keyfile, (int8*)s.data(), 7)); diff --git a/src/twtest/platform_t.cpp b/src/twtest/platform_t.cpp index 742fb24..bd40342 100644 --- a/src/twtest/platform_t.cpp +++ b/src/twtest/platform_t.cpp @@ -203,15 +203,15 @@ void TestAlignment() void TestSizes() { /* - ASSERT( CanBeRepresentedAs( char(), char() ) ); - ASSERT( CanBeRepresentedAs( char(), unsigned char() ) ); - ASSERT( CanBeRepresentedAs( unsigned char(), char() ) ); - ASSERT( CanBeRepresentedAs( unsigned char(), unsigned char() ) ); - ASSERT( CanBeRepresentedAs( signed char(), char() ) ); - ASSERT( CanBeRepresentedAs( char(), signed char() ) ); - ASSERT( CanBeRepresentedAs( signed char(), signed char() ) ); - ASSERT( CanBeRepresentedAs( signed char(), unsigned char() ) ); - ASSERT( CanBeRepresentedAs( char(), signed char() ) ); + TEST( CanBeRepresentedAs( char(), char() ) ); + TEST( CanBeRepresentedAs( char(), unsigned char() ) ); + TEST( CanBeRepresentedAs( unsigned char(), char() ) ); + TEST( CanBeRepresentedAs( unsigned char(), unsigned char() ) ); + TEST( CanBeRepresentedAs( signed char(), char() ) ); + TEST( CanBeRepresentedAs( char(), signed char() ) ); + TEST( CanBeRepresentedAs( signed char(), signed char() ) ); + TEST( CanBeRepresentedAs( signed char(), unsigned char() ) ); + TEST( CanBeRepresentedAs( char(), signed char() ) ); */ } diff --git a/src/twtest/refcountobj_t.cpp b/src/twtest/refcountobj_t.cpp index dc04d1d..4d81267 100644 --- a/src/twtest/refcountobj_t.cpp +++ b/src/twtest/refcountobj_t.cpp @@ -119,7 +119,7 @@ void TestRefCountObj() db.TraceAlways("Entering...\n"); - // Note the following test of Reference counted objects containing + // Note the following test of Reference counted objects containing // copies of themselves failed. Perhaps someday we will upgrade the // reference counting interface to allow this type of structure. /* @@ -157,11 +157,12 @@ void TestRefCountObj() } } + //These fields only exist in debug builds, so we can't use TEST() here. ASSERT(cRefCountObj::objectCounter == 0); ASSERT(cRefCountObj::referenceCounter == 0); db.TraceAlways("Done...\n"); - + return; } diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index 4d5b71a..8775c60 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -71,13 +71,11 @@ void TestFCOSpec(); void TestFCOPropVector(); void TestFileHeader(); void TestFSPropSet(); -void TestFSDataSource(); void TestFCOSpecImpl(); void TestFSPropCalc(); void TestFCOPropImpl(); void TestFCOCompare(); //void TestTripwire(); -void TestFCOSetUtil(); void TestWin32FSServices(); void TestFCOSpecList(); void TestFCOReport(); @@ -88,7 +86,6 @@ void TestRefCountObj(); void TestSignature(); void TestSerRefCountObj(); void TestUnixFSServices(); -//void TestFCODatabase(); void TestError(); void TestDebug(); void TestFcoSpecUtil(); @@ -96,7 +93,7 @@ void TestTypes(); void TestTCHAR(); void TestErrorBucketImpl(); void TestHashTable(); -//void TestTextReportViewer(); +void TestTextReportViewer(); void TestFCONameTbl(); void TestConfigFile(); @@ -108,16 +105,14 @@ void TestCryptoArchive(); void TestFCOSpecAttr(); void TestCmdLineParser(); void TestTaskTimer(); -//void TestObjectPool(); void TestKeyFile(); -void TestFCOSetCached(); void TestTWUtil(); void TestFSPropDisplayer(); void TestFSPropDisplayer(); void TestGenre(); void TestFSDataSourceIter(); void TestGenerateDb(); -//void TestHierDatabaseInteractive(); +void TestHierDatabaseInteractive(); void TestGenreSwitcher(); void TestDbDataSource(); void TestGenreSpecList(); @@ -125,12 +120,11 @@ void TestIntegrityCheck(); void TestFCODatabaseFile(); void TestWchar16(); void TestStringEncoder(); -//void TestDisplayEncoder(); + void TestGrowHeap(); void TestPlatform(); -//void TestBlockFile(); -//void TestBlockRecordArray(); -//void TestHierDatabaseInteractive(); +void TestBlockFile(); +void TestBlockRecordArray(); void TestTWLocale(); void TestFileUtil(); void TestFCONameTranslator(); @@ -158,10 +152,12 @@ void Usage() _T("(runs test id's 1, 2, 3, and 12)\n\n"); } -const int MAX_TEST_ID = 100; +const int MAX_TEST_ID = 88; static void Test(int testID) { + TCERR << std::endl << "=== Running test ID #" << testID << " ===" << std::endl; + switch (testID) { case 1: TestArchive(); break; @@ -172,37 +168,36 @@ static void Test(int testID) case 6: TestError(); break; case 7: TestErrorBucketImpl(); break; case 8: TestFCOCompare(); break; - //case 9: TestFCODatabase(); break; - //case 11: TestFCOErrorQueue(); break; + case 12: TestFCOName(); break; case 13: TestFCONameTbl(); break; case 14: TestFCOPropVector(); break; case 15: TestFCOPropImpl(); break; case 16: TestFCOReport(); break; - //case 17: TestFCOSetCached(); break; + case 18: TestFCOSetImpl(); break; - //case 19: TestFCOSetUtil(); break; + case 20: TestFCOSpecAttr(); break; case 21: TestFCOSpecHelper(); break; case 22: TestFCOSpecList(); break; case 23: TestFcoSpecUtil(); break; case 24: TestFileHeader(); break; - //case 25: TestFSDataSource(); break; + case 26: TestFSPropSet(); break; case 27: TestFSPropCalc(); break; case 28: TestFCOSpecImpl(); break; case 29: TestHashTable(); break; -// case 30: TestObjectPool(); break; + case 31: TestRefCountObj(); break; case 32: TestSerializerImpl(); break; case 33: TestSerRefCountObj(); break; case 34: TestSignature(); break; case 35: TestTaskTimer(); break; //case 36: TestTripwire(); break; - //case 37: TestTextReportViewer(); break; + case 37: TestTextReportViewer(); break; case 39: TestSerRefCountObj(); break; case 40: TestError(); break; - //case 41: TestFCODatabase(); break; + case 41: TestFCODatabaseFile(); break; case 42: TestHashTable(); break; case 43: TestTCHAR(); break; case 44: TestUnixFSServices(); break; @@ -214,19 +209,19 @@ static void Test(int testID) case 52: TestGenre(); break; case 53: TestFSDataSourceIter(); break; //case 54: TestGenerateDb(); break; - //case 55: TestHierDatabaseInteractive(); break; + case 55: TestHierDatabaseInteractive(); break; case 56: TestGenreSwitcher(); break; case 57: TestDbDataSource(); break; case 58: TestGenreSpecList(); break; //case 59: TestIntegrityCheck(); break; + case 65: TestWchar16(); break; case 66: TestStringEncoder(); break; - //case 67: TestDisplayEncoder(); break; + case 69: TestGrowHeap(); break; case 70: TestPlatform(); break; - //case 71: TestBlockFile(); break; - //case 72: TestBlockRecordArray(); break; - //case 73: TestHierDatabaseInteractive(); break; + case 71: TestBlockFile(); break; + case 72: TestBlockRecordArray(); break; case 74: TestFileUtil(); break; case 75: TestTWLocale(); break; case 76: TestFCONameTranslator(); break; @@ -244,6 +239,8 @@ static void Test(int testID) case 87: TestCharUtilBasic(); break; case 88: TestConfigFile2(); break; } + + TCERR << std::endl << "=== test ID #" << testID << " completed ===" << std::endl; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/twtest/textreportviewer_t.cpp b/src/twtest/textreportviewer_t.cpp index 1d970d1..731969c 100644 --- a/src/twtest/textreportviewer_t.cpp +++ b/src/twtest/textreportviewer_t.cpp @@ -36,6 +36,7 @@ #include "tw/stdtw.h" #include #include +#include #include "tw/fcoreport.h" #include "fco/fcospecimpl.h" @@ -56,7 +57,7 @@ #include "tw/fcoreportutil.h" #include "tw/headerinfo.h" -#ifdef FIXED_TRV_TEST_SUITE +//#ifdef FIXED_TRV_TEST_SUITE void MakeFile( TSTRING& fcoNameMakeMe ); void MakeDir( const TCHAR* const lpszDirName ); @@ -80,7 +81,7 @@ static void TraceReport(const cFCOReport& r, cDebug& d) for(specIter.SeekBegin(); ! specIter.Done(); specIter.Next(), ct++) { d.TraceDebug(">>> Spec [%d]:\n", ct); - ASSERT(specIter.GetSpec()); + TEST(specIter.GetSpec()); specIter.GetSpec()->TraceContents(); specIter.GetErrorQueue()->TraceContents(); @@ -105,8 +106,30 @@ static void TraceReport(const cFCOReport& r, cDebug& d) } } +/* + // + // basic functionality + // + void DisplayReportAndHaveUserUpdateIt( const TSTRING& edName, ReportingLevel level = FULL_REPORT ); //throw (eFSServices, eTextReportViewer, eInternal); + // outputs the given report to a temp file, opens an editor, has + // the user view changes to the database, and, by selecting FCO entries, + // chooses which changes to write to the database. Unchecked entries + // are removed from the report + // edName is the name of the editor to use to update the report + + virtual void PrintTextReport( const TSTRING& strFilename, ReportingLevel level = FULL_REPORT ); //throw (eTextReportViewer); + // if strFilename is "-", will print to TCOUT + virtual void PrintTextReport( TOSTREAM& ostr, ReportingLevel level = FULL_REPORT ); //throw (eTextReportViewer); + // prints the report to the specified ostream + */ + + + void TestTextReportViewer() { + TCERR << std::endl << "TestTextReportViewer needs to be cleaned up & fixed, currently disabled" << std::endl; + +#if 0 cFCOReport report; cFCOReportGenreIter genreIter(report); cFCOReportSpecIter specIter(genreIter); @@ -119,7 +142,7 @@ void TestTextReportViewer() try { iFSServices* pFSServices = iFSServices::GetInstance(); - ASSERT( pFSServices ); + TEST( pFSServices ); TSTRING fcoNameTempDir; pFSServices->GetTempDirName( fcoNameTempDir ); @@ -127,9 +150,9 @@ void TestTextReportViewer() fcoNameSpec1 = fcoNameTempDir += _T("SPEC1/"); fcoNameSpec2 = fcoNameTempDir += _T("SPEC2/"); - pFSServices->Mkdir( fcoNameTempDir ); - pFSServices->Mkdir( fcoNameSpec1.AsString() ); - pFSServices->Mkdir( fcoNameSpec2.AsString() ); + mkdir( fcoNameTempDir.c_str(), 0777 ); + mkdir( fcoNameSpec1.AsString().c_str(), 0777 ); + mkdir( fcoNameSpec2.AsString().c_str(), 0777 ); fcoNameTempFile = fcoNameTempDir += _T("twtempXXXXXX"); pFSServices->MakeTempFilename( fcoNameTempFile ); @@ -137,12 +160,12 @@ void TestTextReportViewer() catch(eFSServices& /* e */) { // TODO: properly handle error - ASSERT( false ); + TEST( false ); } - + // need two prop calcs because..... // if cFSPropCalc::VisitFSObject succeeds, cFSPropCalc stores the FCO in - // an internal set (why, I don't know), and the cFCOSet ASSERTs that the same + // an internal set (why, I don't know), and the cFCOSet TESTs that the same // FCO isn't inserted more than once. But since we visit changed FCOs twice // in this test routine, we need two calcs. Make sense? Oh, well. cFSPropCalc* pPropCalc = new cFSPropCalc; @@ -153,7 +176,7 @@ void TestTextReportViewer() cFCOSpecImpl* pSpec = new cFCOSpecImpl( fcoNameSpec1.AsString(), NULL, pStopPts); cFCOSpecAttr* pAttr = new cFCOSpecAttr; - + cFCOPropVector v; for( int i = 0; i < 32; i++ ) v.AddItem( i ); @@ -161,7 +184,6 @@ void TestTextReportViewer() pPropCalc->SetPropVector(v); pPropCalc2->SetPropVector(v); - TSTRING fcoNameMakeMe; fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/added_fileXXXXXX"); MakeFile( fcoNameMakeMe ); @@ -172,9 +194,10 @@ void TestTextReportViewer() // MakeTempFile can't handle strings with escaped quotes, so we'll have to do this ourselves fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/\"quoted\\_and_backslashed_file1\""); //TOFSTREAM file1( fcoNameMakeMe.c_str() ); - //ASSERT( file1 ); + //TEST( file1 ); //file1.close(); + cFSObject* addedFCO2 = new cFSObject( cFCOName(fcoNameMakeMe) ); //pPropCalc->VisitFSObject( *addedFCO2 ); @@ -182,7 +205,7 @@ void TestTextReportViewer() // MakeTempFile can't handle strings with escaped quotes, so we'll have to do this ourselves fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/quoted_file\"2\"XXXXXX"); //TOFSTREAM file2( fcoNameMakeMe.c_str() ); - //ASSERT( file2 ); + //TEST( file2 ); //file2.close(); cFSObject* addedFCO3 = new cFSObject( cFCOName(fcoNameMakeMe) ); @@ -199,6 +222,7 @@ void TestTextReportViewer() MakeFile( fcoNameMakeMe ); cFSObject* removedFCO2 = new cFSObject( cFCOName(fcoNameMakeMe) ); pPropCalc->VisitFSObject( *removedFCO2 ); + pSpec->SetStartPoint( fcoNameSpec1 ); pAttr->SetName( fcoNameSpec1.AsString() ); @@ -207,7 +231,9 @@ void TestTextReportViewer() report.AddSpec(0x00020001, pSpec, pAttr, &specIter); // TODO:bam - use cFS::Genre pAttr->Release(); - + TEST(specIter.GetAddedSet()); + TEST(specIter.GetRemovedSet()); + specIter.GetAddedSet()->Insert(addedFCO); specIter.GetAddedSet()->Insert(addedFCO2); specIter.GetAddedSet()->Insert(addedFCO3); @@ -234,6 +260,7 @@ void TestTextReportViewer() changedPropVector1.AddItem(cFSPropSet::PROP_UID); report.AddChangedFCO(specIter, oldChangedFCO, newChangedFCO, changedPropVector1); + // make changed FCO2 cFCOPropVector changedPropVector2; @@ -280,7 +307,7 @@ void TestTextReportViewer() specIter.GetAddedSet()->Insert(addedFCO5); specIter.GetRemovedSet()->Insert(removedFCO5); - + // make changed FCO3 cFCOPropVector changedPropVector3; @@ -321,14 +348,13 @@ void TestTextReportViewer() specIter.Next(); //specIter.GetErrorQueue()->AddError(2, "this is an \"/etc2\" spec error",NULL); - d.TraceDebug(_T("\n======================================================\nStart PrintTextReport...\n======================================================\n\n\n")); TSTRING tstrEmpty( _T("") ); cFCOReportHeader rhi; cFCOReportUtil::FinalizeReport( report ); - cTextReportViewer trv; - trv.DisplayReportAndHaveUserUpdateIt( rhi, report, _T("") ); + cTextReportViewer trv(rhi, report); + trv.DisplayReportAndHaveUserUpdateIt( _T("") ); // test writing of USID cFileArchive outFile; @@ -354,20 +380,20 @@ void TestTextReportViewer() d.TraceDebug("Read in serialized report:\n"); //TraceReport(inReport, d); - trv.PrintTextReport( rhi, inReport, TSTRING( TEMP_DIR _T( "/test2.txt" ) ) ); + trv.PrintTextReport(TSTRING( TEMP_DIR _T( "/test2.txt" ) ) ); //TODO: this does not work any more //trv.LaunchEditorOnFile( TSTRING( TEMP_DIR _T("/test2.txt") ), _T("") ); // look at results - trv.PrintTextReport( rhi, report, fcoNameTempFile ); + trv.PrintTextReport(fcoNameTempFile ); //TODO: this does not work any more //cTextReportViewer::LaunchEditorOnFile( fcoNameTempFile, _T("") ); iFSServices* pFSServices = iFSServices::GetInstance(); - ASSERT( pFSServices ); + TEST( pFSServices ); pFSServices->FileDelete( addedFCO->GetName().AsString() ); pFSServices->FileDelete( addedFCO2->GetName().AsString() ); pFSServices->FileDelete( addedFCO3->GetName().AsString() ); @@ -382,8 +408,8 @@ void TestTextReportViewer() pFSServices->FileDelete( fcoNameTempFile ); // don't remove TEMP_DIR since other people may be using it - pFSServices->Rmdir( fcoNameSpec1.AsString() ); - pFSServices->Rmdir( fcoNameSpec2.AsString() ); + rmdir( fcoNameSpec1.AsString().c_str() ); + rmdir( fcoNameSpec2.AsString().c_str() ); pSpec->Release(); pSpec2->Release(); @@ -404,7 +430,8 @@ void TestTextReportViewer() newChangedFCO3->Release(); oldChangedFCO4->Release(); newChangedFCO4->Release(); - +#endif + return; } @@ -412,50 +439,40 @@ void MakeFile( TSTRING& strNameMakeMe ) { try { - iFSServices* pFSServices = iFSServices::GetInstance(); ASSERT( pFSServices ); + iFSServices* pFSServices = iFSServices::GetInstance(); TEST( pFSServices ); pFSServices->MakeTempFilename( strNameMakeMe ); std::string strA; for( TSTRING::iterator i = strNameMakeMe.begin(); i != strNameMakeMe.end(); ++i ) { char ach[6]; - ASSERT( MB_CUR_MAX <= 6 ); + TEST( MB_CUR_MAX <= 6 ); int n = wctomb( ach, *i ); - ASSERT( n != -1 ); + TEST( n != -1 ); for( int j = 0; j < n; j++ ) strA += ach[j]; } TOFSTREAM file( strA.c_str() ); - ASSERT( file ); + TEST( file ); file.close(); } catch( eFSServices e ) { - ASSERT( false ); + TEST( false ); } catch( ... ) { - ASSERT( false ); + TEST( false ); } } void MakeDir( const TCHAR* const lpszDirName ) { - try - { - iFSServices* pFSServices = iFSServices::GetInstance(); - TSTRING newdir(lpszDirName); - - pFSServices->Mkdir( newdir ); - } - catch( eFSServices e ) - { - ASSERT( false ); - } + TEST(0 == mkdir(lpszDirName, 0777 )) } -#endif //FIXED_TRV_TEST_SUITE +//#endif //FIXED_TRV_TEST_SUITE diff --git a/src/twtest/twlocale_t.cpp b/src/twtest/twlocale_t.cpp index 3899662..c1ad872 100644 --- a/src/twtest/twlocale_t.cpp +++ b/src/twtest/twlocale_t.cpp @@ -51,7 +51,7 @@ void TestHex(); try \ { \ x; \ - ASSERT( false ); \ + TEST( false ); \ } catch( error& ) {} void TestTWLocale() @@ -80,21 +80,21 @@ void TestAtoi() // cTWLocale::InitGlobalLocale(); n = cTWLocale::FormatNumber( str ); - ASSERT( n == 123456 ); + TEST( n == 123456 ); // // Try formatting with "" locale // std::locale::global( std::locale("") ); n = cTWLocale::FormatNumber( str ); - ASSERT( n == 123456 ); + TEST( n == 123456 ); // // Try formatting with "C" locale // std::locale::global( std::locale("") ); n = cTWLocale::FormatNumber( str ); - ASSERT( n == 123456 ); + TEST( n == 123456 ); } void TestItoa() @@ -147,7 +147,7 @@ void TestRoundtrip() strOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( strIn ), strOut ); // don't know if string will be the same due to possible changes in formatting from locale // ASSERT( strOut == strIn ); <---- can't do this ^^^ - ASSERT( 123456 == cTWLocale::FormatNumber( strOut ) ); + TEST( 123456 == cTWLocale::FormatNumber( strOut ) ); // @@ -156,7 +156,7 @@ void TestRoundtrip() int32 nIn = 654321; int32 nOut; nOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( nIn, strIn ) ); - ASSERT( nOut == nIn ); + TEST( nOut == nIn ); } @@ -172,7 +172,7 @@ void TestFlags() // TSTRING str = _T("FF"); int n = cTWLocale::FormatNumber( str, std::ios_base::hex ); - ASSERT( n == 0xFF ); + TEST( n == 0xFF ); // // bad number for dec @@ -184,21 +184,21 @@ void TestFlags() // TSTRING strOct = _T("0712"); n = cTWLocale::FormatNumber( strOct, std::ios_base::oct ); - ASSERT( n == 0712 ); + TEST( n == 0712 ); // // oct again // strOct = _T("00712"); n = cTWLocale::FormatNumber( strOct, std::ios_base::oct ); - ASSERT( n == 0712 ); + TEST( n == 0712 ); // // oct again again // strOct = _T("712"); n = cTWLocale::FormatNumber( strOct, std::ios_base::oct ); - ASSERT( n == 0712 ); + TEST( n == 0712 ); // // try bad oct @@ -212,16 +212,16 @@ void TestHex() TSTRING str; str = cTWLocale::FormatNumberAsHex( 0x1234 ); - ASSERT( str == _T("1234") ); + TEST( str == _T("1234") ); str = cTWLocale::FormatNumberAsHex( 16 ); - ASSERT( str == _T("10") ); + TEST( str == _T("10") ); str = cTWLocale::FormatNumberAsHex( 0x12344321 ); - ASSERT( str == _T("12344321") ); + TEST( str == _T("12344321") ); str = cTWLocale::FormatNumberAsHex( 0xFFFFFFFF ); - ASSERT( str == _T("FFFFFFFF") || str == _T("ffffffff") ); + TEST( str == _T("FFFFFFFF") || str == _T("ffffffff") ); } #endif//DOESNTWORK diff --git a/src/twtest/twutil_t.cpp b/src/twtest/twutil_t.cpp index 545c4bd..71b124f 100644 --- a/src/twtest/twutil_t.cpp +++ b/src/twtest/twutil_t.cpp @@ -34,6 +34,7 @@ #include "tw/stdtw.h" #include "tw/twutil.h" +#include "util/fileutil.h" #include "twtest/test.h" #include @@ -45,8 +46,6 @@ std::string WideToNarrow( const TSTRING& strWide ); void TestTWUtil() { -#pragma message( __FILE__ "(1) : TODO - implement this test file") -#if 0 // TODO: we should test more than the file exists stuff, but that // is all I need to do for right now. cDebug d("TestTWUtil"); @@ -57,7 +56,7 @@ void TestTWUtil() d.TraceAlways("Testing FileExists() and FileWritable()\n"); // assuming the current dir is writable, this test should succeed - TEST(cTWUtil::FileWritable(_T("afilethatdoesnotexist.tmp")) == true); + TEST(cFileUtil::FileWritable(_T("afilethatdoesnotexist.tmp")) == true); TSTRING tmpDir = TEMP_DIR; tmpDir += _T("/fileexistdir"); @@ -65,43 +64,42 @@ void TestTWUtil() tmpFN += _T("/fileexiststest.tmp"); // make a subdir in the TEMP_DIR - _tmkdir(tmpDir.c_str(), 0700); - _tchmod(tmpDir.c_str(), 0700); + mkdir(tmpDir.c_str(), 0700); + chmod(tmpDir.c_str(), 0700); // make sure file is not there - _tchmod(tmpFN.c_str(), 0777); - _tunlink(tmpFN.c_str()); + chmod(tmpFN.c_str(), 0777); + unlink(tmpFN.c_str()); // make sure exists tests false, writable is true // and checking writable should not create the file - TEST(cTWUtil::FileExists(tmpFN) == false); - TEST(cTWUtil::FileWritable(tmpFN) == true) - TEST(cTWUtil::FileExists(tmpFN) == false); + TEST(cFileUtil::FileExists(tmpFN) == false); + TEST(cFileUtil::FileWritable(tmpFN) == true) + TEST(cFileUtil::FileExists(tmpFN) == false); // make the dir read only and make sure write tests false // windows fails this test, perhaps because I am an administrator? - _tchmod(tmpDir.c_str(), 0500); - TEST(cTWUtil::FileWritable(tmpFN) == false); - _tchmod(tmpDir.c_str(), 0700); + chmod(tmpDir.c_str(), 0500); + TEST(cFileUtil::FileWritable(tmpFN) == false); + chmod(tmpDir.c_str(), 0700); // create the file { - std::ofstream ostr(WideToNarrow(tmpFN).c_str()); - ostr << "Hey there.\n"; + std::ofstream ostr(WideToNarrow(tmpFN).c_str()); + ostr << "Hey there.\n"; } // test a read only file - _tchmod(tmpFN.c_str(), 0400); - TEST(cTWUtil::FileWritable(tmpFN) == false); + chmod(tmpFN.c_str(), 0400); + TEST(cFileUtil::FileWritable(tmpFN) == false); // test a writable file - _tchmod(tmpFN.c_str(), 0666); - TEST(cTWUtil::FileWritable(tmpFN) == true); + chmod(tmpFN.c_str(), 0666); + TEST(cFileUtil::FileWritable(tmpFN) == true); // delete the test file and dir - _tunlink(tmpFN.c_str()); - _tunlink(tmpDir.c_str()); -#endif + unlink(tmpFN.c_str()); + unlink(tmpDir.c_str()); } std::string WideToNarrow( const TSTRING& strWide ) From 9e1b078aac03c4882cf70900cd95f02e1e3523b5 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 29 Mar 2017 00:13:22 -0700 Subject: [PATCH 37/43] Fix setting of IS_xxx OS macros for various platforms --- src/core/platform.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/platform.h b/src/core/platform.h index e3eb14a..7e2bc47 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -144,7 +144,7 @@ #define OS OS_OPENBSD #define IS_OPENBSD 1 -#elif defined(_OSX) +#elif defined(__APPLE__) #define OS OS_DARWIN #define IS_DARWIN 1 @@ -157,7 +157,7 @@ #define IS_MIDNIGHTBSD 1 -#elif defined(_SOLARIS) || defined(__sun) +#elif defined(__sun) #define OS OS_SOLARIS #define IS_SOLARIS 1 @@ -165,11 +165,11 @@ #define OS OS_AIX #define IS_AIX 1 -#elif defined (_HPUX) +#elif defined (__hpux) #define OS OS_HPUX #define IS_HPUX 1 -#elif defined(_IRIX) +#elif defined(__sgi) #define OS OS_IRIX #define IS_IRIX 1 From a67d3c3a869fc6731ef5833cca3675ba5b02583b Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 30 Mar 2017 22:22:52 -0700 Subject: [PATCH 38/43] Clean up installer (remove unneeded checks, better editor & pager detection & path handling); update twtest to count failures instead of exiting on first one. --- installer/install.sh | 70 ++++++----------- src/twtest/test.cpp | 183 ++++++++++++++++++++++++------------------- src/twtest/test.h | 4 +- 3 files changed, 128 insertions(+), 129 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 5b39d45..e554aaf 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -17,7 +17,7 @@ ## from Larry Wall's metaconfig. ##------------------------------------------------------- -PATH='.:/bin:/usr/bin' +PATH=".:/bin:/usr/bin:/usr/local/bin:$PATH" export PATH || (echo 'You must use sh to run this script'; kill $$) if [ ! -t 0 ] ; then echo "Say 'sh install.sh', not 'sh < install.sh'" @@ -66,52 +66,24 @@ for p in $awknames; do fi done -##------------------------------------------------------- -## Does this system have a copy of grep we can use? -## Some greps don't return status (amazing, huh?), -## so we look for a copy of grep that -## returns 0 status for an exact match -## returns 0 status for a case-insensitive match -## returns 0 status for a wildcard match -## returns non-zero status for a failed match -##------------------------------------------------------- - -GREP="" -grepnames="grep egrep" -lcgrepstr="findensiemich" # all lower case -mcgrepstr="FindenSieMich" # mixed case -wcgrepstr="sie.ich$" # wild card match -nogrepstr="WoBistDu" # should not be able to find this -for p in $grepnames; do - (echo "$lcgrepstr" | $p "$lcgrepstr") 2> /dev/null 1>&2 - if [ $? -eq 0 ]; then - (echo "$lcgrepstr" | $p -i "$mcgrepstr") 2> /dev/null 1>&2 - if [ $? -eq 0 ]; then - (echo "$lcgrepstr" | $p "$wcgrepstr") 2> /dev/null 1>&2 - if [ $? -eq 0 ]; then - (echo "$lcgrepstr" | $p "$nogrepstr") 2> /dev/null 1>&2 - if [ $? -ne 0 ]; then - GREP=$p - break - fi - fi - fi - fi -done - ##------------------------------------------------------- ## Does this system have a pager that we can use? ## Use cat if desperate. ##------------------------------------------------------- MORE="cat" -morenames="more less cat" +morenames="less more most pg cat" for p in $morenames; do - ($p $0 < /dev/null) 2> /dev/null 1>&2 - if [ $? -eq 0 ]; then - MORE=$p - break - fi + pagerpath=`command -v $p` + + if [ -z $pagerpath ]; then + continue + fi + + if [ -x $pagerpath ]; then + MORE=$pagerpath + break + fi done ##------------------------------------------------------- @@ -404,15 +376,21 @@ else ##------------------------------------------------------- ## Verify that the specified editor program exists ##------------------------------------------------------- - -TWEDITOR=${TWEDITOR:-'/bin/vi'} + +DEFAULTEDITOR=${EDITOR:-‘/bin/vi’} +TWEDITOR=${TWEDITOR:-$DEFAULTEDITOR} +TWEDITOR_PATH=`command -v $TWEDITOR` + +if [ -n ${TWEDITOR_PATH} ]; then + TWEDITOR=$TWEDITOR_PATH +fi if [ -x ${TWEDITOR} ]; then - echo "${TWEDITOR} exists. Continuing installation." - echo + echo "${TWEDITOR} exists. Continuing installation." + echo else - echo "${TWEDITOR} does not exist. Exiting." - exit 1 + echo "${TWEDITOR} not found. Continuing, but your configuration may need to be edited after installation." + echo fi ##------------------------------------------------------- diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index 8775c60..a2d3e44 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -154,90 +154,109 @@ void Usage() const int MAX_TEST_ID = 88; +static int failed_count = 0; + static void Test(int testID) { TCERR << std::endl << "=== Running test ID #" << testID << " ===" << std::endl; - switch (testID) + try { + + switch (testID) + { + case 1: TestArchive(); break; + case 2: TestCmdLineParser(); break; + case 3: TestCrypto(); break; + case 4: TestCryptoArchive(); break; + case 5: TestDebug(); break; + case 6: TestError(); break; + case 7: TestErrorBucketImpl(); break; + case 8: TestFCOCompare(); break; + + case 12: TestFCOName(); break; + case 13: TestFCONameTbl(); break; + case 14: TestFCOPropVector(); break; + case 15: TestFCOPropImpl(); break; + case 16: TestFCOReport(); break; + + case 18: TestFCOSetImpl(); break; + + case 20: TestFCOSpecAttr(); break; + case 21: TestFCOSpecHelper(); break; + case 22: TestFCOSpecList(); break; + case 23: TestFcoSpecUtil(); break; + case 24: TestFileHeader(); break; + + case 26: TestFSPropSet(); break; + case 27: TestFSPropCalc(); break; + case 28: TestFCOSpecImpl(); break; + case 29: TestHashTable(); break; + + case 31: TestRefCountObj(); break; + case 32: TestSerializerImpl(); break; + case 33: TestSerRefCountObj(); break; + case 34: TestSignature(); break; + case 35: TestTaskTimer(); break; + //case 36: TestTripwire(); break; + case 37: TestTextReportViewer(); break; + case 39: TestSerRefCountObj(); break; + case 40: TestError(); break; + case 41: TestFCODatabaseFile(); break; + case 42: TestHashTable(); break; + case 43: TestTCHAR(); break; + case 44: TestUnixFSServices(); break; + case 46: TestConfigFile(); break; + case 47: TestPolicyParser(); break; + case 48: TestKeyFile(); break; + case 49: TestTWUtil(); break; + case 50: TestFSPropDisplayer(); break; + case 52: TestGenre(); break; + case 53: TestFSDataSourceIter(); break; + //case 54: TestGenerateDb(); break; + case 55: TestHierDatabaseInteractive(); break; + case 56: TestGenreSwitcher(); break; + case 57: TestDbDataSource(); break; + case 58: TestGenreSpecList(); break; + //case 59: TestIntegrityCheck(); break; + + case 65: TestWchar16(); break; + case 66: TestStringEncoder(); break; + + case 69: TestGrowHeap(); break; + case 70: TestPlatform(); break; + case 71: TestBlockFile(); break; + case 72: TestBlockRecordArray(); break; + case 74: TestFileUtil(); break; + case 75: TestTWLocale(); break; + case 76: TestFCONameTranslator(); break; + case 77: TestStringUtil(); break; + case 78: TestCodeConverter(); break; + + case 79: TestCharToHex(); break; + case 80: TestHexToChar(); break; + case 81: TestStringToHex(); break; + case 82: TestHexToString(); break; + // case 83: TestUnconvertable(); break; + // case 84: TestUnprintable(); break; + case 85: TestQuoteAndBackSlash(); break; + case 86: TestDisplayEncoderBasic(); break; + case 87: TestCharUtilBasic(); break; + case 88: TestConfigFile2(); break; + } + + } + catch (eError& error) { - case 1: TestArchive(); break; - case 2: TestCmdLineParser(); break; - case 3: TestCrypto(); break; - case 4: TestCryptoArchive(); break; - case 5: TestDebug(); break; - case 6: TestError(); break; - case 7: TestErrorBucketImpl(); break; - case 8: TestFCOCompare(); break; - - case 12: TestFCOName(); break; - case 13: TestFCONameTbl(); break; - case 14: TestFCOPropVector(); break; - case 15: TestFCOPropImpl(); break; - case 16: TestFCOReport(); break; - - case 18: TestFCOSetImpl(); break; - - case 20: TestFCOSpecAttr(); break; - case 21: TestFCOSpecHelper(); break; - case 22: TestFCOSpecList(); break; - case 23: TestFcoSpecUtil(); break; - case 24: TestFileHeader(); break; - - case 26: TestFSPropSet(); break; - case 27: TestFSPropCalc(); break; - case 28: TestFCOSpecImpl(); break; - case 29: TestHashTable(); break; - - case 31: TestRefCountObj(); break; - case 32: TestSerializerImpl(); break; - case 33: TestSerRefCountObj(); break; - case 34: TestSignature(); break; - case 35: TestTaskTimer(); break; - //case 36: TestTripwire(); break; - case 37: TestTextReportViewer(); break; - case 39: TestSerRefCountObj(); break; - case 40: TestError(); break; - case 41: TestFCODatabaseFile(); break; - case 42: TestHashTable(); break; - case 43: TestTCHAR(); break; - case 44: TestUnixFSServices(); break; - case 46: TestConfigFile(); break; - case 47: TestPolicyParser(); break; - case 48: TestKeyFile(); break; - case 49: TestTWUtil(); break; - case 50: TestFSPropDisplayer(); break; - case 52: TestGenre(); break; - case 53: TestFSDataSourceIter(); break; - //case 54: TestGenerateDb(); break; - case 55: TestHierDatabaseInteractive(); break; - case 56: TestGenreSwitcher(); break; - case 57: TestDbDataSource(); break; - case 58: TestGenreSpecList(); break; - //case 59: TestIntegrityCheck(); break; - - case 65: TestWchar16(); break; - case 66: TestStringEncoder(); break; - - case 69: TestGrowHeap(); break; - case 70: TestPlatform(); break; - case 71: TestBlockFile(); break; - case 72: TestBlockRecordArray(); break; - case 74: TestFileUtil(); break; - case 75: TestTWLocale(); break; - case 76: TestFCONameTranslator(); break; - case 77: TestStringUtil(); break; - case 78: TestCodeConverter(); break; - - case 79: TestCharToHex(); break; - case 80: TestHexToChar(); break; - case 81: TestStringToHex(); break; - case 82: TestHexToString(); break; - // case 83: TestUnconvertable(); break; - // case 84: TestUnprintable(); break; - case 85: TestQuoteAndBackSlash(); break; - case 86: TestDisplayEncoderBasic(); break; - case 87: TestCharUtilBasic(); break; - case 88: TestConfigFile2(); break; + cTWUtil::PrintErrorMsg(error); + failed_count++; + } + catch (std::exception& e) { + TCERR << "FAILED: " << e.what() << std::endl; + failed_count++; + } + catch (...) { + TCERR << "FAILED: " << std::endl; + failed_count++; } TCERR << std::endl << "=== test ID #" << testID << " completed ===" << std::endl; @@ -333,9 +352,9 @@ int _tmain(int argc, TCHAR** argv) // force user to hit - std::cout << std::endl << "Tests completed" << std::endl; - - return 0; + std::cout << std::endl << "Tests completed with " << failed_count << " failures." << std::endl; + + return failed_count ? -1 : 0; } diff --git a/src/twtest/test.h b/src/twtest/test.h index 6931009..d465124 100644 --- a/src/twtest/test.h +++ b/src/twtest/test.h @@ -49,6 +49,8 @@ #endif #include +#include + using namespace std; //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -69,7 +71,7 @@ TSS_EndPackage( cTest ) #define TEST(exp) if (!(exp)) \ { \ std::cerr<<"TEST(" << #exp << ") failure, file " << __FILE__ << " line " << __LINE__ << std::endl; \ - exit(-1); \ + throw std::runtime_error(#exp); \ } /////////////////////////////////////////////////////////////////////////////// From 2df8802a713bb951b1d570f0dc6d2dfcef9e0f6b Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 30 Mar 2017 22:52:03 -0700 Subject: [PATCH 39/43] Update readme file --- ReadMe-2.4.3 | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/ReadMe-2.4.3 b/ReadMe-2.4.3 index bbc0ea1..7cc57a8 100644 --- a/ReadMe-2.4.3 +++ b/ReadMe-2.4.3 @@ -1,4 +1,14 @@ -What's new in Open Source Tripwire 2.4.3.2: +What's new in Open Source Tripwire 2.4.3.x: + +* Useful ‘install-strip’, ‘check’, ‘uninstall’ & ‘distcheck’ make targets as of OST 2.4.3.5. Check target invokes both the test-harness framework and twtest unit tests. + +* Verify OST builds without errors w/ GCC 7.0.x; fix new warnings from the new compiler, including deprecation warnings; use std::unique_ptr instead of std::auto_ptr where available. + +* Add ‘—disable-extrawarnings’ configure option, for old compilers that don’t support the ’-Wextra’ compile option. + +* Clean up unit tests, enable various disabled tests, make results more useful. + +* Additional cleanup due to static analysis tool results (CppCheck, Flawfinder, Clang analyzer). * OST now includes optional iconv support when configured with --enable-iconv. When enabled, binary database & report files store paths as UTF-16, making these files more @@ -29,11 +39,6 @@ specifying a build directory outside the source dir now works as expected. * Assorted platform tweaks: Add DOS/FreeDOS + DJGPP as a new platform; support Cygwin //host/share/path syntax for UNC paths; passphrase & tempfile fixes for AROS. - -====================================== - -What was new in earlier 2.4.3 versions: - * This update fixes compilation errors on modern compilers (GCC 4.7+ and LLVM/clang), as well as some additional errors encountered on various platforms. This is intended to supersede patches against 2.4.2.x, e.g. http://www.linuxfromscratch.org/blfs/view/svn/postlfs/tripwire.html @@ -66,15 +71,22 @@ defined incorrectly otherwise. The update has been tested on a variety of platforms: Linuxes -- CentOS 7 (amd64) + gcc 4.8.5 -- Ubuntu 14.0.4 (amd64) + gcc 4.x -- RHEL 3.4 (Itanium) + gcc 3.4.3 - Alpine Linux 3.3.3 + gcc 5.3.0 -- Android 6.0 (arm) + gcc 4.9 -- Raspbian 7 (wheezy) (armv6l) + gcc 4.6.3 -- openSuSE Tumbleweed (20160408) (i586) + gcc 5.3.1 -- RHEL 6.0 (powerpc64) + gcc 4.4.4 +- Alpine Linux 3.5.1 + gcc 6.2.1 +- Arch Linux 232 + gcc 6.3.1 +- Amazon Linux AMI 2016.09 + gcc 4.8.3 +- Android 6.0 (arm) + gcc 4.9 (NDK) +- CentOS 7 (amd64) + gcc 4.8.5 - Fedora 24 Alpha 7 (amd64) + gcc 6.0.0 +- Fedora 27 Rawhide (amd64) + gcc 7.0.1 +- Raspbian 7 (wheezy) (armv6l) + gcc 4.6.3 +- RHEL 3.4 (Itanium) + gcc 3.4.3 +- RHEL 6.0 (powerpc64) + gcc 4.4.4 +- openSuSE Tumbleweed (20160408) (i586) + gcc 5.3.1 +- Oracle Linux 6.8 + gcc 4.4.7 +- Ubuntu 14.0.4 (amd64) + gcc 4.x +- Ubuntu 16.0.4 (amd64) + gcc 5.4.0 +- Wind River Pulsar Linux 8 + gcc 5.2.0 OSX - Mac OS X 10.11 + LLVM 7.0.2 / clang-700.1.81 @@ -90,7 +102,7 @@ BSDs UNIXes - Solaris 10 SPARC + gcc 3.4.6 - Solaris 10 x86 + gcc 3.4.3 -- OpenIndiana 151 + gcc 4.8.5 [an OpenSolaris/illumos distro] +- OpenIndiana 151 + gcc 4.8.5 - AIX 5.2 + gcc 4.3.1 - HP-UX 11.23 + gcc 4.2.3 From 87750882e447d68e872cc6dc9abe92f585c8b9c6 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 30 Mar 2017 23:05:37 -0700 Subject: [PATCH 40/43] Update Changelog & fix a hyphen in ReadMe --- ChangeLog | 8 ++++++++ ReadMe-2.4.3 | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index deca8d5..e5ac5c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2017-03-30 Brian Cox + * Bump version to 2.4.3.5 + * Fix ‘install-strip’, ‘check’, ‘uninstall’, and ‘distcheck’ make targets. + * Fix GCC 7.0.x warnings; use std::unique_ptr instead of deprecated std::auto_ptr where available. + * Add ‘--disable-extrawarnings’ configure option, for old compilers that don’t support the ’-Wextra’ compile option. + * Clean up unit tests & enable disabled tests. + * Address more static analyzer warnings, including from CppCheck & Flawfinder + 2017-03-05 Brian Cox * Bump version to 2.4.3.4 * Fix issue with printing level 2 reports, introduced by fixing a Clang static analyzer quibble in 2.4.3.3. Sigh. diff --git a/ReadMe-2.4.3 b/ReadMe-2.4.3 index 7cc57a8..95d508b 100644 --- a/ReadMe-2.4.3 +++ b/ReadMe-2.4.3 @@ -4,7 +4,7 @@ What's new in Open Source Tripwire 2.4.3.x: * Verify OST builds without errors w/ GCC 7.0.x; fix new warnings from the new compiler, including deprecation warnings; use std::unique_ptr instead of std::auto_ptr where available. -* Add ‘—disable-extrawarnings’ configure option, for old compilers that don’t support the ’-Wextra’ compile option. +* Add ‘--disable-extrawarnings’ configure option, for old compilers that don’t support the ’-Wextra’ compile option. * Clean up unit tests, enable various disabled tests, make results more useful. From 65625c6d0eedde54eef901dc4e988708e496457b Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 31 Mar 2017 00:02:14 -0700 Subject: [PATCH 41/43] Tweak message about documentation location at end of install, so it points somewhere real vs. an empty string --- installer/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/install.sh b/installer/install.sh index e554aaf..3492ccd 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -893,7 +893,7 @@ cat << END_OF_TEXT ---------------------------------------------- The installation succeeded. -Please refer to $README_LOC +Please refer to documentation in $TWDOCS for release information and to the printed user documentation for further instructions on using Tripwire 2.4 Open Source. From 7b86cdd13437f8b6813382b615acd35d3941a357 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 31 Mar 2017 15:09:43 -0700 Subject: [PATCH 42/43] Unit test build fix, make sure is included --- src/twtest/genre_t.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/twtest/genre_t.cpp b/src/twtest/genre_t.cpp index a62de95..666ab10 100644 --- a/src/twtest/genre_t.cpp +++ b/src/twtest/genre_t.cpp @@ -33,6 +33,8 @@ // genre_t.cpp // +#include + #include "fco/stdfco.h" #include "fco/genreswitcher.h" #include "twtest/test.h" From 65e0a0d664c5ea0f6933d15463ee72e5054a0491 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 31 Mar 2017 23:08:44 -0700 Subject: [PATCH 43/43] Tweak unit test error reporting slightly --- src/twtest/test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index a2d3e44..799d587 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -247,6 +247,7 @@ static void Test(int testID) } catch (eError& error) { + TCERR << "FAILED: " ; cTWUtil::PrintErrorMsg(error); failed_count++; } @@ -351,9 +352,9 @@ int _tmain(int argc, TCHAR** argv) //TEST(cRefCountObj::AllRefCountObjDestoryed() == true); // force user to hit - + std::cout << std::endl << "Tests completed with " << failed_count << " failures." << std::endl; - + return failed_count ? -1 : 0; }