From 11ca082152a131863ed4a4727a781b9bdbe5468e Mon Sep 17 00:00:00 2001 From: Jorge Camarero Vera <jorge.camarero@cern.ch> Date: Mon, 28 Mar 2022 17:04:05 +0200 Subject: [PATCH] Resolve "Change compiler FLAGS in cmake files" --- CMakeLists.txt | 38 +++------------- catalogue/CreateAdminUserCmdLineArgsTest.cpp | 12 ++--- catalogue/CreateSchemaCmdLineArgsTest.cpp | 12 ++--- catalogue/DropSchemaCmdLineArgsTest.cpp | 12 ++--- catalogue/PollDatabaseCmdLineArgsTest.cpp | 12 ++--- catalogue/VerifySchemaCmdLineArgsTest.cpp | 12 ++--- common/checksum/ChecksumBlob.cpp | 2 +- eos_cta/CMakeLists.txt | 6 --- mediachanger/DismountCmdLineTest.cpp | 24 +++++----- mediachanger/MountCmdLineTest.cpp | 14 +++--- mediachanger/castorrmc/rmc/CMakeLists.txt | 8 +--- objectstore/RootEntry.cpp | 12 ++--- scheduler/CMakeLists.txt | 11 ++--- .../tape/tapeserver/SCSI/CMakeLists.txt | 11 ----- .../tape/tapeserver/daemon/CMakeLists.txt | 33 +------------- .../tape/tapeserver/drive/CMakeLists.txt | 23 ---------- .../tape/tapeserver/drive/DriveGeneric.cpp | 1 + .../tape/tapeserver/file/CMakeLists.txt | 27 ----------- .../castor/tape/tapeserver/file/FileTest.cpp | 11 ++--- .../tape/tapeserver/file/Structures.hpp | 1 + .../tape/tapeserver/file/StructuresTest.cpp | 10 ++--- .../tape/tapeserver/system/CMakeLists.txt | 6 --- .../tape/tapeserver/system/FileWrappers.cpp | 45 ++++++++++--------- tapeserver/daemon/CMakeLists.txt | 10 ----- .../tapelabel/TapeLabelCmdLineArgsTest.cpp | 14 +++--- xroot_plugins/XrdCtaStream.hpp | 11 ++--- 26 files changed, 116 insertions(+), 262 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 311559ddc5..1e0a8eae86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,31 +31,18 @@ set(CMAKE_CXX_FLAGS "-fPIC -pedantic -Wall -Wextra -Werror -Wno-unused-parameter # to be tested once we have a stable compilation on CC7: #-Wno-unused-parameter -Wlogical-op -Wfloat-equal -Wdeclaration-after- statement -Wundef -Wno-endif-labels -Wshadow -Wunsafe-loop- optimizations -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite- strings -Wconversion -Wmissing-field-initializers -Wredundant-decls -Wnested-externs -Wunreachable-code -Winline -Wvariadic-macros -Wtraditional -Wmissing-prototypes -Wmissing-declarations -Wold-style- definition -Wc++-compat -Wstrict-prototypes -Wpadded -Wcast-qual -Wnon-virtual-dtor -Wlogical-op -Wmissing-declarations -Wsign-conversion -Wredundant-decls -Wold-style-cast -Wshadow -# Explicitly setting the C and C++ compiler flags for the RelWithDebInfo build -# in order to prevent the -O2 flag from being used. -set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g") -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g") - set (BUILD_CMDLINE_ONLY FALSE) execute_process( COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) -if (CMAKE_COMPILER_IS_GNUCC) - message(STATUS "GCC VERSION ${GCC_VERSION}") - if (GCC_VERSION VERSION_GREATER_EQUAL 7.0) - message(STATUS "Detected gcc > 7.0 - switching on support for c++17") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") - elseif (GCC_VERSION VERSION_EQUAL 4.4.7) - message(STATUS "Detected gcc = 4.4.7 - build cmdline only with c++0x") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") - set (BUILD_CMDLINE_ONLY TRUE) - elseif (GCC_VERSION VERSION_GREATER 4.4.7) - message(STATUS "Detected gcc > 4.4.7 - switching on support for c++1y") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y") - endif () -endif () +message(STATUS "Setting support for c++17") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE) +endif() # CTA continue using the old ABI, so we should force it. This command only works on cmake3, # so we should update the requeriments of CMakeLists @@ -63,11 +50,6 @@ endif () # https://docs.ceph.com/en/latest/dev/cxx/ add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0) -set (GCC_VERSION_GE_4_8_0 FALSE) -if (CMAKE_COMPILER_IS_GNUCC AND ((GCC_VERSION VERSION_GREATER 4.8.0) OR (GCC_VERSION VERSION_EQUAL 4.8.0))) - set (GCC_VERSION_GE_4_8_0 TRUE) -endif (CMAKE_COMPILER_IS_GNUCC AND ((GCC_VERSION VERSION_GREATER 4.8.0) OR (GCC_VERSION VERSION_EQUAL 4.8.0))) - # To enable logging for testing purposes set -DENABLE_STDOUT_LOGGING=1 if (ENABLE_STDOUT_LOGGING) add_definitions (-DSTDOUT_LOGGING) @@ -126,14 +108,6 @@ ELSE(DEFINED PackageOnly) # OCCI support is on by default set (OCCI_SUPPORT ON) - # Switch OCCI support off if using gcc 5.1 or higher - #if (CMAKE_COMPILER_IS_GNUCC) - # if (GCC_VERSION VERSION_GREATER 5.0) - # message (STATUS "Detected gcc >= 5.1 - Switching off OCCI support") - # set (OCCI_SUPPORT OFF) - # endif (GCC_VERSION VERSION_GREATER 5.0) - #endif (CMAKE_COMPILER_IS_GNUCC) - if (OCCI_SUPPORT) find_package (oracle-instantclient REQUIRED) endif (OCCI_SUPPORT) diff --git a/catalogue/CreateAdminUserCmdLineArgsTest.cpp b/catalogue/CreateAdminUserCmdLineArgsTest.cpp index e1a85fee3f..175017b67e 100644 --- a/catalogue/CreateAdminUserCmdLineArgsTest.cpp +++ b/catalogue/CreateAdminUserCmdLineArgsTest.cpp @@ -37,12 +37,12 @@ protected: /** * Creates a duplicate string using the new operator. */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; + char *dupString(const std::string &str) { + const int len = str.size(); + char *copy = new char[len + 1]; + std::copy(str.begin(), str.end(), copy); + copy[len] = '\0'; + return copy; } virtual void SetUp() { diff --git a/catalogue/CreateSchemaCmdLineArgsTest.cpp b/catalogue/CreateSchemaCmdLineArgsTest.cpp index 6898da1492..5542fc21eb 100644 --- a/catalogue/CreateSchemaCmdLineArgsTest.cpp +++ b/catalogue/CreateSchemaCmdLineArgsTest.cpp @@ -38,12 +38,12 @@ protected: /** * Creates a duplicate string using the new operator. */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; + char *dupString(const std::string &str) { + const int len = str.size(); + char *copy = new char[len + 1]; + std::copy(str.begin(), str.end(), copy); + copy[len] = '\0'; + return copy; } virtual void SetUp() { diff --git a/catalogue/DropSchemaCmdLineArgsTest.cpp b/catalogue/DropSchemaCmdLineArgsTest.cpp index 0cf7df792c..a9a6dc1195 100644 --- a/catalogue/DropSchemaCmdLineArgsTest.cpp +++ b/catalogue/DropSchemaCmdLineArgsTest.cpp @@ -38,12 +38,12 @@ protected: /** * Creates a duplicate string using the new operator. */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; + char *dupString(const std::string &str) { + const int len = str.size(); + char *copy = new char[len + 1]; + std::copy(str.begin(), str.end(), copy); + copy[len] = '\0'; + return copy; } virtual void SetUp() { diff --git a/catalogue/PollDatabaseCmdLineArgsTest.cpp b/catalogue/PollDatabaseCmdLineArgsTest.cpp index c1911a1bf4..89558abbe1 100644 --- a/catalogue/PollDatabaseCmdLineArgsTest.cpp +++ b/catalogue/PollDatabaseCmdLineArgsTest.cpp @@ -38,12 +38,12 @@ protected: /** * Creates a duplicate string using the new operator. */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; + char *dupString(const std::string &str) { + const int len = str.size(); + char *copy = new char[len + 1]; + std::copy(str.begin(), str.end(), copy); + copy[len] = '\0'; + return copy; } virtual void SetUp() { diff --git a/catalogue/VerifySchemaCmdLineArgsTest.cpp b/catalogue/VerifySchemaCmdLineArgsTest.cpp index d745c9bdbe..18ffe5bfe7 100644 --- a/catalogue/VerifySchemaCmdLineArgsTest.cpp +++ b/catalogue/VerifySchemaCmdLineArgsTest.cpp @@ -38,12 +38,12 @@ protected: /** * Creates a duplicate string using the new operator. */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; + char *dupString(const std::string &str) { + const int len = str.size(); + char *copy = new char[len + 1]; + std::copy(str.begin(), str.end(), copy); + copy[len] = '\0'; + return copy; } virtual void SetUp() { diff --git a/common/checksum/ChecksumBlob.cpp b/common/checksum/ChecksumBlob.cpp index 00d7191bc7..8087672160 100644 --- a/common/checksum/ChecksumBlob.cpp +++ b/common/checksum/ChecksumBlob.cpp @@ -25,7 +25,7 @@ namespace checksum { void ChecksumBlob::insert(ChecksumType type, const std::string &value) { // Validate the length of the checksum - size_t expectedLength; + size_t expectedLength = 0; switch(type) { case NONE: expectedLength = 0; break; case ADLER32: diff --git a/eos_cta/CMakeLists.txt b/eos_cta/CMakeLists.txt index 69eeebab52..b10e0c4468 100644 --- a/eos_cta/CMakeLists.txt +++ b/eos_cta/CMakeLists.txt @@ -42,12 +42,6 @@ set_source_files_properties( foreach(PROTO_SRC ${ProtoSourcesEosCta} ${ProtoSourcesMigration} ${ProtoGrpcSourcesMigration}) set_property(SOURCE ${PROTO_SRC} PROPERTY COMPILE_FLAGS " -Wno-missing-field-initializers -fPIC -Wno-narrowing -Wno-implicit-fallthrough") - # Add -Wno-narrowing -Wno-implicit-fallthrough compiler flags if using gcc version 7 or greater - if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION VERSION_EQUAL 7 OR GCC_VERSION VERSION_GREATER 7) - set_property(SOURCE ${PROTO_SRC} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-narrowing -Wno-implicit-fallthrough") - endif(GCC_VERSION VERSION_EQUAL 7 OR GCC_VERSION VERSION_GREATER 7) - endif(CMAKE_COMPILER_IS_GNUCC) endforeach(PROTO_SRC) add_library(XrdSsiPbEosCta ${ProtoSourcesEosCta}) diff --git a/mediachanger/DismountCmdLineTest.cpp b/mediachanger/DismountCmdLineTest.cpp index ba32b2e3eb..30f0164be0 100644 --- a/mediachanger/DismountCmdLineTest.cpp +++ b/mediachanger/DismountCmdLineTest.cpp @@ -39,12 +39,12 @@ protected: /** * Creates a duplicate string using the new operator. */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; + char *dupString(const std::string &str) { + const int len = str.size(); + char *copy = new char[len + 1]; + std::copy(str.begin(), str.end(), copy); + copy[len] = '\0'; + return copy; } virtual void SetUp() { @@ -71,7 +71,7 @@ TEST_F(cta_mediachanger_DismountCmdLineTest, copy_constructor) { Argcv *args= new Argcv(); m_argsList.push_back(args); args->argc = 3; - args->argv = new char *[4]; + args->argv = new char *[4]; args->argv[0] = dupString("cta-mediachanger-dismount"); args->argv[1] = dupString("vid"); args->argv[2] = dupString("smc1"); @@ -98,7 +98,7 @@ TEST_F(cta_mediachanger_DismountCmdLineTest, assignment) { Argcv *args1= new Argcv(); m_argsList.push_back(args1); args1->argc = 3; - args1->argv = new char *[4]; + args1->argv = new char *[4]; args1->argv[0] = dupString("cta-mediachanger-dismount"); args1->argv[1] = dupString("vid"); args1->argv[2] = dupString("smc1"); @@ -113,7 +113,7 @@ TEST_F(cta_mediachanger_DismountCmdLineTest, assignment) { Argcv *args2= new Argcv(); m_argsList.push_back(args2); args2->argc = 3; - args2->argv = new char *[4]; + args2->argv = new char *[4]; args2->argv[0] = dupString("cta-mediachanger-dismount"); args2->argv[1] = dupString("vid"); args2->argv[2] = dupString("smc2"); @@ -140,16 +140,16 @@ TEST_F(cta_mediachanger_DismountCmdLineTest, assignment) { TEST_F(cta_mediachanger_DismountCmdLineTest, scsi) { using namespace cta::mediachanger; - + Argcv *args = new Argcv(); m_argsList.push_back(args); args->argc = 3; - args->argv = new char *[4]; + args->argv = new char *[4]; args->argv[0] = dupString("cta-mediachanger-dismount"); args->argv[1] = dupString("vid"); args->argv[2] = dupString("smc1"); args->argv[3] = NULL; - + std::unique_ptr<DismountCmdLine> cmdLine; ASSERT_NO_THROW(cmdLine.reset(new DismountCmdLine(args->argc, args->argv))); diff --git a/mediachanger/MountCmdLineTest.cpp b/mediachanger/MountCmdLineTest.cpp index 343a5d2a6e..c427abae03 100644 --- a/mediachanger/MountCmdLineTest.cpp +++ b/mediachanger/MountCmdLineTest.cpp @@ -39,12 +39,12 @@ protected: /** * Creates a duplicate string using the new operator. */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; + char *dupString(const std::string &str) { + const int len = str.size(); + char *copy = new char[len + 1]; + std::copy(str.begin(), str.end(), copy); + copy[len] = '\0'; + return copy; } virtual void SetUp() { @@ -119,7 +119,7 @@ TEST_F(cta_mediachanger_MountCmdLineTest, assignment) { args2->argv[1] = dupString("vid"); args2->argv[2] = dupString("smc2"); args2->argv[3] = NULL; - + MountCmdLine cmdLine2(args2->argc, args2->argv); ASSERT_FALSE(cmdLine2.getHelp()); ASSERT_FALSE(cmdLine2.getDebug()); diff --git a/mediachanger/castorrmc/rmc/CMakeLists.txt b/mediachanger/castorrmc/rmc/CMakeLists.txt index 92ab8c916c..0c7079c98c 100644 --- a/mediachanger/castorrmc/rmc/CMakeLists.txt +++ b/mediachanger/castorrmc/rmc/CMakeLists.txt @@ -28,12 +28,8 @@ set (RMCD_SRC_FILES spectra_like_libs.c ) -if(CMAKE_COMPILER_IS_GNUCC) - # Add -Wno-format-overflow compiler flag if using gcc version 7 or greater - if (GCC_VERSION VERSION_EQUAL 7 OR GCC_VERSION VERSION_GREATER 7) - set_property(SOURCE rmc_send_scsi_cmd.c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-format-overflow") - endif (GCC_VERSION VERSION_EQUAL 7 OR GCC_VERSION VERSION_GREATER 7) -endif(CMAKE_COMPILER_IS_GNUCC) +# Add -Wno-format-overflow compiler flag +set_property(SOURCE rmc_send_scsi_cmd.c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-format-overflow") add_executable(cta-rmcd ${RMCD_SRC_FILES}) target_link_libraries(cta-rmcd ctarmccommon) diff --git a/objectstore/RootEntry.cpp b/objectstore/RootEntry.cpp index 8600858c4c..b89ee61e2f 100644 --- a/objectstore/RootEntry.cpp +++ b/objectstore/RootEntry.cpp @@ -857,13 +857,13 @@ void RootEntry::removeRepackQueueAndCommit(common::dataStructures::RepackQueueTy checkPayloadWritable(); // find the address of the repack queue object try { - bool hasQueue; + bool hasQueue = false; switch (queueType) { - case common::dataStructures::RepackQueueType::Pending: - hasQueue = m_payload.has_repackrequestspendingqueuepointer(); - break; - case common::dataStructures::RepackQueueType::ToExpand: - hasQueue = m_payload.has_repackrequeststoexpandqueuepointer(); + case common::dataStructures::RepackQueueType::Pending: + hasQueue = m_payload.has_repackrequestspendingqueuepointer(); + break; + case common::dataStructures::RepackQueueType::ToExpand: + hasQueue = m_payload.has_repackrequeststoexpandqueuepointer(); } if (!hasQueue) { throw NoSuchRepackQueue("In RootEntry::removeRepackQueueAndCommit: trying to remove non-existing repack queue"); diff --git a/scheduler/CMakeLists.txt b/scheduler/CMakeLists.txt index f155d33d04..38e1bcace0 100644 --- a/scheduler/CMakeLists.txt +++ b/scheduler/CMakeLists.txt @@ -63,14 +63,9 @@ add_library (ctaschedulerunittests SHARED set_property(TARGET ctaschedulerunittests PROPERTY SOVERSION "${CTA_SOVERSION}") set_property(TARGET ctaschedulerunittests PROPERTY VERSION "${CTA_LIBVERSION}") -if(CMAKE_COMPILER_IS_GNUCC) - # Add -Wno-unused-function compiler flag if using gcc version 6 or greater - if (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6) - set_property(SOURCE OStoreDB/OStoreDBTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") - set_property(SOURCE SchedulerDatabaseTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") - set_property(SOURCE SchedulerTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") - endif (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6) -endif(CMAKE_COMPILER_IS_GNUCC) +set_property(SOURCE OStoreDB/OStoreDBTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") +set_property(SOURCE SchedulerDatabaseTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") +set_property(SOURCE SchedulerTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") target_link_libraries (ctaschedulerunittests ctascheduler) diff --git a/tapeserver/castor/tape/tapeserver/SCSI/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/SCSI/CMakeLists.txt index 63e2e74ae9..a296bbc496 100644 --- a/tapeserver/castor/tape/tapeserver/SCSI/CMakeLists.txt +++ b/tapeserver/castor/tape/tapeserver/SCSI/CMakeLists.txt @@ -16,17 +16,6 @@ cmake_minimum_required (VERSION 3.17) include_directories(${CMAKE_SOURCE_DIR}/tapeserver) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - set_property(SOURCE Device.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - set_property(SOURCE DeviceTest.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - set_property(SOURCE StructuresTest.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) - add_library(SCSI Device.cpp Structures.cpp Constants.cpp Exception.cpp) add_library(ctatapeserverscsiunittests SHARED diff --git a/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt index 17c23ce4f0..d1e6231499 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt +++ b/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt @@ -48,30 +48,8 @@ set(CTATAPESERVERDAEMON_LIBRARY_SRCS TapeWriteSingleThread.cpp TapeWriteTask.cpp) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - foreach(CTATAPESERVERDAEMON_LIBRARY_SRC - ${CTATAPESERVERDAEMON_LIBRARY_SRCS} - CatalogueTest.cpp - DataTransferSessionTest.cpp - DiskReadTaskTest.cpp - DiskWriteTaskTest.cpp - DiskWriteTaskTest.cpp - DiskWriteThreadPoolTest.cpp - MigrationReportPackerTest.cpp - ProcessForkerProxyDummy.cpp - ProcessForkerTest.cpp - RecallTaskInjectorTest.cpp) - set_property(SOURCE ${CTATAPESERVERDAEMON_LIBRARY_SRC} - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endforeach(CTATAPESERVERDAEMON_LIBRARY_SRC) - - # Add -Wno-unused-function compiler flag if using gcc version 6 or greater - if (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6) - set_property(SOURCE DataTransferSessionTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") - endif (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6) - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) +# Add -Wno-unused-function compiler flag +set_property(SOURCE DataTransferSessionTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") add_library(ctaTapeServerDaemon ${CTATAPESERVERDAEMON_LIBRARY_SRCS}) @@ -94,13 +72,6 @@ add_library(ctatapeserverdaemonunittests SHARED set_property(TARGET ctatapeserverdaemonunittests PROPERTY SOVERSION "${CTA_SOVERSION}") set_property(TARGET ctatapeserverdaemonunittests PROPERTY VERSION "${CTA_LIBVERSION}") -if(CMAKE_COMPILER_IS_GNUCC) - # Add -Wno-unused-function compiler flag if using gcc version 6 or greater - if (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6) - set_property(SOURCE RecallReportPackerTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function") - endif (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6) -endif(CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(ctatapeserverdaemonunittests ctamessagesutils) #ctaschedulerutils diff --git a/tapeserver/castor/tape/tapeserver/drive/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/drive/CMakeLists.txt index 69e7729321..9b9e2ac54d 100644 --- a/tapeserver/castor/tape/tapeserver/drive/CMakeLists.txt +++ b/tapeserver/castor/tape/tapeserver/drive/CMakeLists.txt @@ -20,25 +20,9 @@ set(TAPEDRIVE_LIBRARY_SRCS DriveGeneric.cpp FakeDrive.cpp) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - foreach(TAPEDRIVE_LIBRARY_SRC ${TAPEDRIVE_LIBRARY_SRCS}) - set_property(SOURCE ${TAPEDRIVE_LIBRARY_SRC} - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endforeach(TAPEDRIVE_LIBRARY_SRC) - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) - add_library(TapeDrive ${TAPEDRIVE_LIBRARY_SRCS}) target_link_libraries(TapeDrive SCSI ctatapedaemon) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - set_property(SOURCE TapeDriveReadWriteTest.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) - add_executable(TapeDriveReadWriteTest TapeDriveReadWriteTest.cpp) target_link_libraries(TapeDriveReadWriteTest @@ -52,13 +36,6 @@ target_link_libraries(TapeDriveReadWriteTest gtest pthread) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - set_property(SOURCE DriveTest.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) - add_library(ctatapeserverdriveunittests SHARED DriveTest.cpp) set_property(TARGET ctatapeserverdriveunittests PROPERTY SOVERSION "${CTA_SOVERSION}") diff --git a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp index 793a774999..8cc0545528 100644 --- a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp +++ b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp @@ -641,6 +641,7 @@ drive::LBPInfo drive::DriveGeneric::getLBPInfo() { //------------------------------------------------------------------------------ // Encryption interface //------------------------------------------------------------------------------ +#pragma GCC diagnostic ignored "-Wstringop-truncation" void drive::DriveGeneric::setEncryptionKey(const std::string &encryption_key) { if(!isEncryptionCapEnabled()) throw cta::exception::Exception("In DriveGeneric::setEncryptionKey: Tried to enable encryption on drive " diff --git a/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt index 50bb447a2b..f434743add 100644 --- a/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt +++ b/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt @@ -24,22 +24,6 @@ set(TAPESERVER_FILE_LIBRARY_SRCS File.cpp Structures.cpp) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - foreach(TAPESERVER_FILE_LIBRARY_SRC ${TAPESERVER_FILE_LIBRARY_SRCS}) - set_property(SOURCE ${TAPESERVER_FILE_LIBRARY_SRC} - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endforeach(TAPESERVER_FILE_LIBRARY_SRC) - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) - -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - set_property(SOURCE BasicReadWriteTest.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) - add_executable(BasicReadWriteTest BasicReadWriteTest.cpp) @@ -56,17 +40,6 @@ target_link_libraries(BasicReadWriteTest add_library(File ${TAPESERVER_FILE_LIBRARY_SRCS}) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - set_property(SOURCE StructuresTest.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - set_property(SOURCE FileTest.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - set_property(SOURCE CryptoPPTest.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) - add_library(ctatapeserverfileunittests SHARED StructuresTest.cpp FileTest.cpp diff --git a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp index 457d5ed5df..6d44dd7431 100644 --- a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp +++ b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp @@ -95,18 +95,19 @@ namespace unitTests { TEST_F(castorTapeFileTest, throwsWhenUsingSessionTwice) { const std::string testString("Hello World!"); - castor::tape::tapeFile::WriteSession *ws; - ASSERT_NO_THROW(ws = new castor::tape::tapeFile::WriteSession(d, volInfo, 0, true, false)); + std::unique_ptr<castor::tape::tapeFile::WriteSession> ws; + ASSERT_NO_THROW(ws = std::make_unique<castor::tape::tapeFile::WriteSession>( + castor::tape::tapeFile::WriteSession(d, volInfo, 0, true, false))); ASSERT_EQ(ws->m_compressionEnabled, true); ASSERT_EQ(ws->m_vid.compare(label), 0); ASSERT_EQ(ws->isCorrupted(), false); { std::unique_ptr<castor::tape::tapeFile::WriteFile> wf; - ASSERT_NO_THROW(wf.reset(new castor::tape::tapeFile::WriteFile(ws, fileToMigrate, block_size))); - wf->write(testString.c_str(),testString.size()); + ASSERT_NO_THROW(wf = std::make_unique<castor::tape::tapeFile::WriteFile>( + ws.get(), fileToMigrate, block_size)); + wf->write(testString.c_str(),testString.size()); wf->close(); } - delete ws; castor::tape::tapeFile::ReadSession *rs; rs = new castor::tape::tapeFile::ReadSession(d, volInfo, false); { diff --git a/tapeserver/castor/tape/tapeserver/file/Structures.hpp b/tapeserver/castor/tape/tapeserver/file/Structures.hpp index 008f1d4743..033015c590 100644 --- a/tapeserver/castor/tape/tapeserver/file/Structures.hpp +++ b/tapeserver/castor/tape/tapeserver/file/Structures.hpp @@ -482,6 +482,7 @@ namespace tape { * c = century (blank=19; 0=20; 1=21; etc.) * yy= year (00-99) ddd = day (001-366) */ + #pragma GCC diagnostic ignored "-Wformat-overflow" inline void setDate(char(& t)[6]) { time_t current_time; struct tm localTime; diff --git a/tapeserver/castor/tape/tapeserver/file/StructuresTest.cpp b/tapeserver/castor/tape/tapeserver/file/StructuresTest.cpp index af1079ad30..ffcfd60ec2 100644 --- a/tapeserver/castor/tape/tapeserver/file/StructuresTest.cpp +++ b/tapeserver/castor/tape/tapeserver/file/StructuresTest.cpp @@ -20,11 +20,11 @@ #include <gmock/gmock-cardinalities.h> namespace unitTests { - + class testVOL1: public castor::tape::tapeFile::VOL1 { public: void backdoorSetLBPMethodString(const std::string & LBPString) { - ::strncpy(m_LBPMethod, LBPString.c_str(), sizeof(m_LBPMethod)); + strcpy(m_LBPMethod, LBPString.c_str()); } }; @@ -68,14 +68,14 @@ namespace unitTests { vol1Label.backdoorSetLBPMethodString("XY"); ASSERT_THROW(vol1Label.getLBPMethod(), cta::exception::Exception); } - + class testVOL1withCRC: public castor::tape::tapeFile::VOL1withCrc { public: void backdoorSetLBPMethodString(const std::string & LBPString) { - ::strncpy(m_LBPMethod, LBPString.c_str(), sizeof(m_LBPMethod)); + strcpy(m_LBPMethod, LBPString.c_str()); } }; - + TEST(castor_tape_AULFile, VOL1WithCRC) { typedef castor::tape::SCSI::logicBlockProtectionMethod LBPM; testVOL1withCRC vol1LabelWithCRC; diff --git a/tapeserver/castor/tape/tapeserver/system/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/system/CMakeLists.txt index d7f5c9acde..5741def78a 100644 --- a/tapeserver/castor/tape/tapeserver/system/CMakeLists.txt +++ b/tapeserver/castor/tape/tapeserver/system/CMakeLists.txt @@ -21,9 +21,3 @@ set_property(SOURCE Wrapper.cpp APPEND PROPERTY COMPILE_FLAGS -fno-strict-aliasing ) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - set_property(SOURCE Wrapper.cpp - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) diff --git a/tapeserver/castor/tape/tapeserver/system/FileWrappers.cpp b/tapeserver/castor/tape/tapeserver/system/FileWrappers.cpp index 56d1f93023..8e13f7659d 100644 --- a/tapeserver/castor/tape/tapeserver/system/FileWrappers.cpp +++ b/tapeserver/castor/tape/tapeserver/system/FileWrappers.cpp @@ -761,34 +761,35 @@ int System::stIBM3592DeviceFile::logSenseDriveReadBackwardErrorsPage(sg_io_hdr_t int System::stIBM3592DeviceFile::logSensePerformanceCharacteristicsPage(sg_io_hdr_t * sgio_h) { SCSI::Structures::logSenseCDB_t* cdb = (SCSI::Structures::logSenseCDB_t*) (sgio_h->cmdp); - unsigned char *output; + unsigned char output_80[] = { + 0x77, 0x80, 0x00, 0x1e, 0x00, 0x00, 0x60, 0x01, 0x50, 0x00, 0x01, 0x60, 0x01, 0x50, 0x00, 0x10, // 0x00 + 0x60, 0x01, 0x01, 0x00, 0x11, 0x60, 0x01, 0x50, 0x00, 0x12, 0x60, 0x01, 0x50, 0x00, 0x1a, 0x60, // 0x10 + 0x01, 0x50 // 0x20 + }; + unsigned char output_91[] = { + 0x77, 0x91, 0x00, 0xd0, 0x01, 0x02, 0x60, 0x04, 0x00, 0x00, 0x05, 0x59, 0x02, 0x02, 0x60, 0x04, //0x00 + 0x00, 0x00, 0x10, 0x4b, 0x03, 0x02, 0x60, 0x04, 0x00, 0x11, 0x34, 0x7d, 0x03, 0xd0, 0x60, 0x04, //0x10 + 0x00, 0x60, 0x1a, 0xd3, 0x04, 0x02, 0x60, 0x04, 0x00, 0x0f, 0x7c, 0x0b, 0x04, 0xd0, 0x60, 0x04, //0x20 + 0x00, 0x62, 0xf3, 0x75, 0x05, 0x02, 0x60, 0x04, 0x00, 0x02, 0xb1, 0x68, 0x05, 0xd4, 0x60, 0x04, //0x30 + 0x00, 0x00, 0x05, 0x1b, 0x06, 0x02, 0x60, 0x04, 0x00, 0x20, 0x49, 0x13, 0x07, 0x02, 0x60, 0x04, //0x40 + 0x00, 0x06, 0xa7, 0xe9, 0x08, 0x02, 0x60, 0x04, 0x00, 0x00, 0x72, 0xcf, 0x09, 0x02, 0x60, 0x04, //0x50 + 0x00, 0x00, 0x00, 0x00, 0x0a, 0x02, 0x60, 0x04, 0x00, 0x00, 0x00, 0x2a, 0x0c, 0x02, 0x60, 0x04, //0x60 + 0x00, 0x4d, 0xcb, 0x5c, 0x0c, 0x0e, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x12, 0x60, 0x04, //0x70 + 0x00, 0x4d, 0xcb, 0x5c, 0x0c, 0x1e, 0x60, 0x04, 0x00, 0x00, 0x07, 0x03, 0x0c, 0x22, 0x60, 0x04, //0x80 + 0x00, 0x00, 0x00, 0x00, 0x0c, 0x2e, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa2, 0x60, 0x04, //0x90 + 0x00, 0x00, 0x22, 0x39, 0x0c, 0xae, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x14, 0x60, 0x04, //0xa0 + 0x00, 0x02, 0x23, 0xac, 0x0d, 0x24, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xa4, 0x60, 0x04, //0xb0 + 0x00, 0x00, 0x00, 0x00, 0x0d, 0xf0, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xf1, 0x60, 0x04, //0xc0 + 0x00, 0x00, 0x00, 0x00 //0xd0 + }; + + unsigned char *output = 0; unsigned int output_size = 0; if(cdb->subPageCode == 0x80 || cdb->subPageCode == 0x40) { - unsigned char output_80[] = { - 0x77, 0x80, 0x00, 0x1e, 0x00, 0x00, 0x60, 0x01, 0x50, 0x00, 0x01, 0x60, 0x01, 0x50, 0x00, 0x10, // 0x00 - 0x60, 0x01, 0x01, 0x00, 0x11, 0x60, 0x01, 0x50, 0x00, 0x12, 0x60, 0x01, 0x50, 0x00, 0x1a, 0x60, // 0x10 - 0x01, 0x50 // 0x20 - }; output = output_80; output_size = sizeof(output_80); } else if(cdb->subPageCode == 0x91 || cdb->subPageCode == 0x51) { ; - unsigned char output_91[] = { - 0x77, 0x91, 0x00, 0xd0, 0x01, 0x02, 0x60, 0x04, 0x00, 0x00, 0x05, 0x59, 0x02, 0x02, 0x60, 0x04, //0x00 - 0x00, 0x00, 0x10, 0x4b, 0x03, 0x02, 0x60, 0x04, 0x00, 0x11, 0x34, 0x7d, 0x03, 0xd0, 0x60, 0x04, //0x10 - 0x00, 0x60, 0x1a, 0xd3, 0x04, 0x02, 0x60, 0x04, 0x00, 0x0f, 0x7c, 0x0b, 0x04, 0xd0, 0x60, 0x04, //0x20 - 0x00, 0x62, 0xf3, 0x75, 0x05, 0x02, 0x60, 0x04, 0x00, 0x02, 0xb1, 0x68, 0x05, 0xd4, 0x60, 0x04, //0x30 - 0x00, 0x00, 0x05, 0x1b, 0x06, 0x02, 0x60, 0x04, 0x00, 0x20, 0x49, 0x13, 0x07, 0x02, 0x60, 0x04, //0x40 - 0x00, 0x06, 0xa7, 0xe9, 0x08, 0x02, 0x60, 0x04, 0x00, 0x00, 0x72, 0xcf, 0x09, 0x02, 0x60, 0x04, //0x50 - 0x00, 0x00, 0x00, 0x00, 0x0a, 0x02, 0x60, 0x04, 0x00, 0x00, 0x00, 0x2a, 0x0c, 0x02, 0x60, 0x04, //0x60 - 0x00, 0x4d, 0xcb, 0x5c, 0x0c, 0x0e, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x12, 0x60, 0x04, //0x70 - 0x00, 0x4d, 0xcb, 0x5c, 0x0c, 0x1e, 0x60, 0x04, 0x00, 0x00, 0x07, 0x03, 0x0c, 0x22, 0x60, 0x04, //0x80 - 0x00, 0x00, 0x00, 0x00, 0x0c, 0x2e, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa2, 0x60, 0x04, //0x90 - 0x00, 0x00, 0x22, 0x39, 0x0c, 0xae, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x14, 0x60, 0x04, //0xa0 - 0x00, 0x02, 0x23, 0xac, 0x0d, 0x24, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xa4, 0x60, 0x04, //0xb0 - 0x00, 0x00, 0x00, 0x00, 0x0d, 0xf0, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xf1, 0x60, 0x04, //0xc0 - 0x00, 0x00, 0x00, 0x00 //0xd0 - }; output = output_91; output_size = sizeof(output_91); } diff --git a/tapeserver/daemon/CMakeLists.txt b/tapeserver/daemon/CMakeLists.txt index f16180106c..c6a6a42bd2 100644 --- a/tapeserver/daemon/CMakeLists.txt +++ b/tapeserver/daemon/CMakeLists.txt @@ -39,16 +39,6 @@ add_library(ctatapedaemon TpconfigLine.cpp Tpconfig.cpp) -if(CMAKE_COMPILER_IS_GNUCC) - if(GCC_VERSION_GE_4_8_0) - foreach(CTATAPESERVERDAEMON_LIBRARY_SRC - DriveHandler.cpp) - set_property(SOURCE ${CTATAPESERVERDAEMON_LIBRARY_SRC} - PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs") - endforeach(CTATAPESERVERDAEMON_LIBRARY_SRC) - endif(GCC_VERSION_GE_4_8_0) -endif(CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(ctatapedaemon ctatapesession ctaTapeServerDaemon diff --git a/tapeserver/tapelabel/TapeLabelCmdLineArgsTest.cpp b/tapeserver/tapelabel/TapeLabelCmdLineArgsTest.cpp index f254bbfff4..796e5cdfdb 100644 --- a/tapeserver/tapelabel/TapeLabelCmdLineArgsTest.cpp +++ b/tapeserver/tapelabel/TapeLabelCmdLineArgsTest.cpp @@ -39,12 +39,12 @@ protected: /** * Creates a duplicate string using the new operator. */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; + char *dupString(const std::string &str) { + const int len = str.size(); + char *copy = new char[len + 1]; + std::copy(str.begin(), str.end(), copy); + copy[len] = '\0'; + return copy; } virtual void SetUp() { @@ -290,7 +290,7 @@ TEST_F(cta_tapeserver_tapelabel_TapeLabelCmdLineArgsTest, oldVid_missed) { args->argv[2] = dupString("VID001"); args->argv[3] = dupString("-o"); args->argv[4] = nullptr; - + ASSERT_THROW(TapeLabelCmdLineArgs cmdLine(args->argc, args->argv), cta::exception::CommandLineNotParsed); } diff --git a/xroot_plugins/XrdCtaStream.hpp b/xroot_plugins/XrdCtaStream.hpp index 6ef3e7fd65..8cd6dd18ab 100644 --- a/xroot_plugins/XrdCtaStream.hpp +++ b/xroot_plugins/XrdCtaStream.hpp @@ -65,7 +65,7 @@ public: virtual Buffer *GetBuff(XrdSsiErrInfo &eInfo, int &dlen, bool &last) override { XrdSsiPb::Log::Msg(XrdSsiPb::Log::DEBUG, LOG_SUFFIX, "GetBuff(): XrdSsi buffer fill request (", dlen, " bytes)"); - XrdSsiPb::OStreamBuffer<Data> *streambuf; + std::unique_ptr<XrdSsiPb::OStreamBuffer<Data>> streambuf; try { if(isDone()) { @@ -74,31 +74,28 @@ public: return nullptr; } - streambuf = new XrdSsiPb::OStreamBuffer<Data>(dlen); + streambuf = std::make_unique<XrdSsiPb::OStreamBuffer<Data>>(dlen); - dlen = fillBuffer(streambuf); + dlen = fillBuffer(streambuf.get()); XrdSsiPb::Log::Msg(XrdSsiPb::Log::DEBUG, LOG_SUFFIX, "GetBuff(): Returning buffer with ", dlen, " bytes of data."); } catch(cta::exception::Exception &ex) { std::ostringstream errMsg; errMsg << __FUNCTION__ << " failed: Caught CTA exception: " << ex.what(); eInfo.Set(errMsg.str().c_str(), ECANCELED); - delete streambuf; return nullptr; } catch(std::exception &ex) { std::ostringstream errMsg; errMsg << __FUNCTION__ << " failed: " << ex.what(); eInfo.Set(errMsg.str().c_str(), ECANCELED); - delete streambuf; return nullptr; } catch(...) { std::ostringstream errMsg; errMsg << __FUNCTION__ << " failed: Caught an unknown exception"; eInfo.Set(errMsg.str().c_str(), ECANCELED); - delete streambuf; return nullptr; } - return streambuf; + return streambuf.release(); } private: -- GitLab