diff --git a/modules/c++/nitf/apps/show_nitf++/pch.h b/modules/c++/nitf/apps/show_nitf++/pch.h index 8177193ae..e9911867d 100644 --- a/modules/c++/nitf/apps/show_nitf++/pch.h +++ b/modules/c++/nitf/apps/show_nitf++/pch.h @@ -41,6 +41,7 @@ #pragma warning(disable: 5204) // '...': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly #pragma warning(disable: 5220) // '...': a non-static data member with a volatile qualified type no longer implies #pragma warning(disable: 4355) // '...': used in base member initializer list +#pragma warning(disable: 5105) // macro expansion producing '...' has undefined behavior #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include diff --git a/modules/c++/nitf/unittests/test_hash_table_1++.cpp b/modules/c++/nitf/unittests/test_hash_table_1++.cpp index 8f382d942..c13fbd5ae 100644 --- a/modules/c++/nitf/unittests/test_hash_table_1++.cpp +++ b/modules/c++/nitf/unittests/test_hash_table_1++.cpp @@ -151,8 +151,6 @@ TEST_CASE(test_hash_table_iterator) } TEST_MAIN( - (void)argc; - (void)argv; TEST_CHECK(test_hash_table_1); TEST_CHECK(test_hash_table_iterator); -) \ No newline at end of file +) diff --git a/modules/c++/nitf/unittests/test_load_plugins.cpp b/modules/c++/nitf/unittests/test_load_plugins.cpp index 4aaee43ca..c94707f56 100644 --- a/modules/c++/nitf/unittests/test_load_plugins.cpp +++ b/modules/c++/nitf/unittests/test_load_plugins.cpp @@ -30,32 +30,28 @@ #include "TestCase.h" -static void load_plugin(const std::string& testName, const char* tre) +static void retrieveTREHandler(const std::string& testName, const char* tre) { nitf_Error error; - auto reg = nitf::PluginRegistry::getInstance(error); + auto const reg = nitf::PluginRegistry::getInstance(error); TEST_ASSERT(reg != nullptr); - nitf::HashTable::print(*(reg->treHandlers)); + //nitf::HashTable::print(*(reg->treHandlers)); int bad = 0; - auto test_main_ = - nitf::PluginRegistry::retrieveTREHandler(*reg, - tre, - bad, - error); + auto const test_main_ = nitf::PluginRegistry::retrieveTREHandler(*reg, tre, bad, error); TEST_ASSERT_EQ(0, bad); TEST_ASSERT(test_main_ != nullptr); } -static const std::vector& all_plugins() +static const auto& all_TREs() { - static const std::vector all_plugins_ + static const std::vector retval { #if _MSC_VER && NITRO_PCH // only build a handful in Visual Studio - "ACCHZB", "ACCPOB", "ACFTA", "AIMIDB", "CSCRNA", "ENGRDA", "HISTOA", "JITCID", "PTPRAA", "RPFHDR", + "ACCHZB", "ACCPOB", "ACFTA", "AIMIDB", "CSCRNA", "CSEXRB", "ENGRDA", "HISTOA", "JITCID", "PTPRAA", "RPFHDR", #else "ACCHZB", "BANDSB", "CSDIDA", "GEOLOB", "JITCID", "NBLOCA", "PIAPEB", "REGPTB", "RSMIDA", "STEROB", "ACCPOB", "BCKGDA", "CSEPHA", "GEOPSB", "MAPLOB", "OBJCTA", "PIAPRC", "RPC00B", "RSMPCA", "STREOB", @@ -69,59 +65,59 @@ static const std::vector& all_plugins() "BANDSA", "CSCRNA", "EXPLTB", "J2KLRA", "MTIRPB", "PIAPEA", "PTPRAA", "RSMGIA", "STDIDC", #endif }; - return all_plugins_; + return retval; } -TEST_CASE(test_load_all_plugins_C) +TEST_CASE(test_retrieveTREHandler) { - nitf::Test::setNitfPluginPath(); - - for (const auto& tre : all_plugins()) + for (const auto& tre : all_TREs()) { - load_plugin(testName, tre.c_str()); + retrieveTREHandler(testName, tre.c_str()); } } TEST_CASE(test_load_PTPRAA) { - nitf::Test::setNitfPluginPath(); - load_plugin(testName, "PTPRAA"); + retrieveTREHandler(testName, "PTPRAA"); } TEST_CASE(test_load_ENGRDA) { - nitf::Test::setNitfPluginPath(); - load_plugin(testName, "ENGRDA"); + retrieveTREHandler(testName, "ENGRDA"); } -static void loadPlugin(const std::string& testName, const std::string& path) -{ - try - { -#ifdef _WIN32 - // need the full path to load on Linux - nitf::PluginRegistry::loadPlugin(path); -#endif - TEST_SUCCESS; - } - catch (const nitf::NITFException& ex) - { - TEST_FAIL_MSG(ex.toString()); - } -} -TEST_CASE(test_load_all_plugins) +TEST_CASE(test_load_all_TREs) { - nitf::Test::setNitfPluginPath(); + const nitf::TRE tre("ACCPOB"); - for (const auto& tre : all_plugins()) + for (const auto& tre : all_TREs()) { - loadPlugin(testName, tre); + // TREs are quite the same thing as an arbitrary "plug in;" the underlying + // infrastructure is all built on shared-libraries/DLLs, but details differ. + // + // As a result, we can't expect loadPlugin() will "just work" on a TRE name. + // Unfortunately, the behavior is different on Windows and Linux. :-( + #if _WIN32 + // Keep this around for now as it works ... but it's not necessarily correct. + // Mostly an excuse to exercise more code. + try + { + nitf::PluginRegistry::loadPlugin(tre); + } + catch (const nitf::NITFException& ex) + { + TEST_FAIL_MSG(ex.toString()); + } + #endif // _WIN32 + TEST_ASSERT(nitf::PluginRegistry::treHandlerExists(tre)); } } TEST_MAIN( + nitf::Test::setNitfPluginPath(); + TEST_CHECK(test_load_PTPRAA); - TEST_CHECK(test_load_ENGRDA); - TEST_CHECK(test_load_all_plugins_C); - TEST_CHECK(test_load_all_plugins); + TEST_CHECK(test_load_ENGRDA); + TEST_CHECK(test_retrieveTREHandler); + TEST_CHECK(test_load_all_TREs); ) \ No newline at end of file diff --git a/modules/c++/nitf/unittests/test_tre_create++.cpp b/modules/c++/nitf/unittests/test_tre_create++.cpp index 9ffe05000..bc3f884fc 100644 --- a/modules/c++/nitf/unittests/test_tre_create++.cpp +++ b/modules/c++/nitf/unittests/test_tre_create++.cpp @@ -7,8 +7,6 @@ TEST_CASE(test_tre_create_329) { - nitf::Test::setNitfPluginPath(); - // https://github.com/mdaus/nitro/issues/329 nitf::TRE tre("HISTOA", "HISTOA"); // allocates fields SYSTEM .. NEVENTS @@ -21,8 +19,6 @@ TEST_CASE(test_tre_create_329) TEST_CASE(test_tre_clone_329) { - nitf::Test::setNitfPluginPath(); - // https://github.com/mdaus/nitro/issues/329 const std::string rd = "begin1020030004ABCDEFend"; @@ -43,6 +39,8 @@ TEST_CASE(test_tre_clone_329) } TEST_MAIN( + nitf::Test::setNitfPluginPath(); + TEST_CHECK(test_tre_create_329); TEST_CHECK(test_tre_clone_329); ) diff --git a/modules/c++/nitf/unittests/test_tre_mods++.cpp b/modules/c++/nitf/unittests/test_tre_mods++.cpp index 8eb85006b..1c2b4a870 100644 --- a/modules/c++/nitf/unittests/test_tre_mods++.cpp +++ b/modules/c++/nitf/unittests/test_tre_mods++.cpp @@ -159,8 +159,6 @@ struct /*namespace*/ TREs TEST_CASE(setFields) { - nitf::Test::setNitfPluginPath(); - // create an ACFTA TRE nitf::TRE tre("ACFTA"); @@ -180,8 +178,6 @@ TEST_CASE(setFields) TEST_CASE(setBinaryFields) { - nitf::Test::setNitfPluginPath(); - nitf::TRE tre("RPFHDR"); const int value = 123; tre.setField("LOCSEC", value); @@ -193,8 +189,6 @@ TEST_CASE(setBinaryFields) TEST_CASE(cloneTRE) { - nitf::Test::setNitfPluginPath(); - nitf::TRE tre("JITCID"); tre.setField("FILCMT", "fyi"); @@ -208,8 +202,6 @@ TEST_CASE(cloneTRE) TEST_CASE(basicIteration) { - nitf::Test::setNitfPluginPath(); - nitf::TRE tre("ACCPOB"); // The entire TRE is one loop, and we haven't told it @@ -237,8 +229,6 @@ TEST_CASE(basicIteration) TEST_CASE(use_ENGRDA) { - nitf::Test::setNitfPluginPath(); - nitf::TRE engrda("ENGRDA", "ENGRDA"); engrda.setField("RESRC", "HSS"); @@ -263,8 +253,6 @@ TEST_CASE(use_ENGRDA) TEST_CASE(use_ENGRDA_typed_fields) { - nitf::Test::setNitfPluginPath(); - nitf::TRE engrda("ENGRDA", "ENGRDA"); nitf::TREField_BCS_A<20> RESRC(engrda, "RESRC"); @@ -297,8 +285,6 @@ TEST_CASE(use_ENGRDA_typed_fields) TEST_CASE(use_typed_ENGRDA) { - nitf::Test::setNitfPluginPath(); - TREs::ENGRDA engrda; // nitf::TRE engrda("ENGRDA", "ENGRDA"); engrda.RESRC = "HSS"; // engrda.setField("RESRC", "HSS"); @@ -347,8 +333,6 @@ TEST_CASE(use_typed_ENGRDA) TEST_CASE(use_CSEXRB_typed_fields) { - nitf::Test::setNitfPluginPath(); - nitf::TRE tre("CSEXRB", "CSEXRB"); constexpr auto length = 12; @@ -362,8 +346,6 @@ TEST_CASE(use_CSEXRB_typed_fields) TEST_CASE(populateWhileIterating) { - nitf::Test::setNitfPluginPath(); - nitf::TRE tre("ACCPOB"); size_t numFields = 0; for (auto it = tre.begin(); it != tre.end(); ++it) @@ -388,8 +370,6 @@ TEST_CASE(populateWhileIterating) TEST_CASE(overflowingNumericFields) { - nitf::Test::setNitfPluginPath(); - nitf::TRE tre("CSCRNA"); // This field has a length of 9, so check that it's properly @@ -418,6 +398,8 @@ TEST_CASE(overflowingNumericFields) } TEST_MAIN( + nitf::Test::setNitfPluginPath(); + TEST_CHECK(setFields); TEST_CHECK(setBinaryFields); TEST_CHECK(cloneTRE); diff --git a/modules/c++/nitf/unittests/test_tre_mods.cpp b/modules/c++/nitf/unittests/test_tre_mods.cpp index be2517963..5bee638c7 100644 --- a/modules/c++/nitf/unittests/test_tre_mods.cpp +++ b/modules/c++/nitf/unittests/test_tre_mods.cpp @@ -26,8 +26,6 @@ TEST_CASE(testNestedMod) { - nitf::Test::setNitfPluginPath(); - nitf_Error error; NITF_BOOL exists; nitf_TRE* tre = nitf_TRE_construct("ACCHZB", NULL, &error); @@ -61,8 +59,6 @@ TEST_CASE(testNestedMod) TEST_CASE(testIncompleteCondMod) { - nitf::Test::setNitfPluginPath(); - nitf_Error error; NITF_BOOL exists; nitf_TRE* tre = nitf_TRE_construct("ACCPOB", NULL, &error); @@ -89,8 +85,6 @@ TEST_CASE(testIncompleteCondMod) TEST_CASE(testClone) { - nitf::Test::setNitfPluginPath(); - NITF_BOOL exists; nitf_TRE* dolly; /* used for clone */ nitf_Field* clonedField = NULL; @@ -116,8 +110,6 @@ TEST_CASE(testClone) TEST_CASE(testBasicMod) { - nitf::Test::setNitfPluginPath(); - /* construct a tre */ NITF_BOOL exists; nitf_Error error; @@ -147,8 +139,6 @@ TEST_CASE(testBasicMod) TEST_CASE(testSize) { - nitf::Test::setNitfPluginPath(); - nitf_Error error; int treLength; nitf_TRE* tre = nitf_TRE_construct("AIMIDB", NULL, &error); @@ -163,8 +153,6 @@ TEST_CASE(testSize) TEST_CASE(iterateUnfilled) { - nitf::Test::setNitfPluginPath(); - nitf_Error error; nitf_TRECursor cursor; nitf_TRE* tre = nitf_TRE_construct("ACCPOB", NULL, &error); @@ -186,8 +174,6 @@ TEST_CASE(iterateUnfilled) TEST_CASE(populateThenIterate) { - nitf::Test::setNitfPluginPath(); - nitf_Error error; nitf_TRECursor cursor; nitf_TRE* tre = nitf_TRE_construct("ACCPOB", NULL, &error); @@ -214,8 +200,6 @@ TEST_CASE(populateThenIterate) TEST_CASE(populateWhileIterating) { - nitf::Test::setNitfPluginPath(); - nitf_Error error; nitf_TRECursor cursor; nitf_TRE* tre = nitf_TRE_construct("ACCPOB", NULL, &error); @@ -247,6 +231,8 @@ TEST_CASE(populateWhileIterating) } TEST_MAIN( + nitf::Test::setNitfPluginPath(); + TEST_CHECK(testClone); TEST_CHECK(testSize); TEST_CHECK(testBasicMod); diff --git a/modules/c++/nitf/unittests/test_writer_3++.cpp b/modules/c++/nitf/unittests/test_writer_3++.cpp index d2955dd26..e68dd3d37 100644 --- a/modules/c++/nitf/unittests/test_writer_3++.cpp +++ b/modules/c++/nitf/unittests/test_writer_3++.cpp @@ -28,6 +28,7 @@ #include #include +#include #include "TestCase.h" @@ -268,4 +269,4 @@ TEST_CASE(test_buffered_write_) TEST_MAIN( TEST_CHECK(test_writer_3_); TEST_CHECK(test_buffered_write_); - ) \ No newline at end of file + ) diff --git a/modules/c++/pch.h b/modules/c++/pch.h index 2d5aa6125..e2236fd36 100644 --- a/modules/c++/pch.h +++ b/modules/c++/pch.h @@ -28,6 +28,7 @@ CODA_OSS_disable_warning_pop #define NOMINMAX #pragma warning(push) #pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc. Undefined behavior may occur if this function throws an exception. +#pragma warning(disable: 5105) // macro expansion producing '...' has undefined behavior #include #pragma warning(pop) diff --git a/modules/c/j2k/shared/J2KCompress.c b/modules/c/j2k/shared/J2KCompress.c index 5eb24805e..9af824236 100644 --- a/modules/c/j2k/shared/J2KCompress.c +++ b/modules/c/j2k/shared/J2KCompress.c @@ -20,23 +20,14 @@ * */ +#include + #ifdef HAVE_J2K_H #if _MSC_VER -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#endif -#pragma warning(push) -#pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to '...' -#include -#pragma warning(pop) -#undef min -#undef max - #pragma warning(disable: 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified #endif // _MSC_VER -#include #include NITF_CXX_GUARD diff --git a/modules/c/j2k/shared/J2KDecompress.c b/modules/c/j2k/shared/J2KDecompress.c index 12daa2020..c9b2c0a4a 100644 --- a/modules/c/j2k/shared/J2KDecompress.c +++ b/modules/c/j2k/shared/J2KDecompress.c @@ -20,23 +20,14 @@ * */ +#include + #ifdef HAVE_J2K_H #if _MSC_VER -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#endif -#pragma warning(push) -#pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to '...' -#include -#pragma warning(pop) -#undef min -#undef max - #pragma warning(disable: 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified #endif // _MSC_VER -#include #include NITF_CXX_GUARD diff --git a/modules/c/nitf/include/import/nitf.h b/modules/c/nitf/include/import/nitf.h index 14afa57f2..3f03e9bb4 100644 --- a/modules/c/nitf/include/import/nitf.h +++ b/modules/c/nitf/include/import/nitf.h @@ -20,8 +20,32 @@ * */ -#ifndef __IMPORT_NITF_H__ -#define __IMPORT_NITF_H__ +#pragma once +#ifndef NITRO_nitf_import_nitf_h_INCLUDED_ +#define NITRO_nitf_import_nitf_h_INCLUDED_ + +#if _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4820) // '...' : '...' bytes padding added after data member '...' +#pragma warning(disable: 4668) // '...' is not defined as a preprocessor macro, replacing with '...' for '...' +#pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to '...' function under -EHc. Undefined behavior may occur if this function throws an exception. +#pragma warning(disable: 5105) // macro expansion producing '...' has undefined behavior +#pragma warning(disable: 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified +#pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to '...' +#pragma warning(disable: 5105) // macro expansion producing '...' has undefined behavior +#endif + +#if _MSC_VER +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#undef min +#undef max +#endif #include "nitf/BandInfo.h" #include "nitf/BandSource.h" @@ -67,4 +91,8 @@ #include "nitf/DirectBlockSource.h" #include "nitf/WriterOptions.h" +#if _MSC_VER +#pragma warning(pop) #endif + +#endif // NITRO_nitf_import_nitf_h_INCLUDED_ \ No newline at end of file diff --git a/modules/c/nitf/shared/ACCHZB.c b/modules/c/nitf/shared/ACCHZB.c index 108de34b5..2107c87b4 100644 --- a/modules/c/nitf/shared/ACCHZB.c +++ b/modules/c/nitf/shared/ACCHZB.c @@ -20,12 +20,6 @@ * */ -#if _MSC_VER -#pragma warning(disable: 4820) // '...' : '...' bytes padding added after data member '...' -#pragma warning(disable: 4668) // '...' is not defined as a preprocessor macro, replacing with '...' for '...' -#pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to '...' function under -EHc. Undefined behavior may occur if this function throws an exception. -#endif - #include NITF_CXX_GUARD diff --git a/modules/c/nitf/shared/JITCID.c b/modules/c/nitf/shared/JITCID.c index 50ee19ed4..73bacd87a 100644 --- a/modules/c/nitf/shared/JITCID.c +++ b/modules/c/nitf/shared/JITCID.c @@ -20,12 +20,7 @@ * */ -#if _MSC_VER -#pragma warning(disable: 4820) // '...' : '...' bytes padding added after data member '...' -#pragma warning(disable: 4668) // '...' is not defined as a preprocessor macro, replacing with '...' for '...' -#pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to '...' function under -EHc. Undefined behavior may occur if this function throws an exception. -#endif - +#include #include #include diff --git a/modules/c/nitf/source/BandInfo.c b/modules/c/nitf/source/BandInfo.c index c70ee3f1c..685c5ac33 100644 --- a/modules/c/nitf/source/BandInfo.c +++ b/modules/c/nitf/source/BandInfo.c @@ -80,7 +80,7 @@ NITFAPI(void) nitf_BandInfo_destruct(nitf_BandInfo ** info) _NITF_DESTRUCT_FIELD(&(*info), NITF_NLUTS); _NITF_DESTRUCT_FIELD(&(*info), NITF_NELUT); - if (&(*info)->lut) + if ((*info)->lut) { nitf_LookupTable_destruct(&(*info)->lut); } diff --git a/modules/c/pch.h b/modules/c/pch.h index 5928459c7..ca4079d2d 100644 --- a/modules/c/pch.h +++ b/modules/c/pch.h @@ -20,6 +20,7 @@ #pragma warning(push) #pragma warning(disable: 4820) // '...': '...' bytes padding added after data member '...' +#pragma warning(disable: 5105) // macro expansion producing '...' has undefined behavior #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include