Commit affa63e4 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'aptool_fortification' into 'master'

Aptool fortification

See merge request !93
parents 873ecbba 12c82158
Pipeline #101487 passed with stages
in 21 minutes and 8 seconds
TriBITS
googletest
testframework
CMakeLists.txt.user CMakeLists.txt.user
.vscode .vscode
build/ build/
......
variables:
GIT_SUBMODULE_STRATEGY: normal
stages: stages:
- test - test
- analysis - analysis
.windows_before_script: &windows_before_script
before_script:
- set PATH=%PATH%;c:\vendors\mingw-w64\x86_64-4.8.5-posix-seh-rt_v4-rev0\mingw64\bin;c:\vendors\mingw-w64\qt\5.9.1\bin
.windows_msvc_before_script: &windows_msvc_before_script
before_script:
- set PATH=c:\Qt\5.9.1\msvc2013_64\bin;%PATH%;c:\Program Files (x86)\NSIS\Bin
mac_gcc_testing: mac_gcc_testing:
tags: tags:
- mac - mac
script: script:
- which git - which git
- git --version - git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- module load cmake gcc/4.8.5 qt/5.9.1 vtk/8.1.0 - module load cmake gcc/4.8.5 qt/5.9.1 vtk/8.1.0
- which cmake - which cmake
- which python - which python
...@@ -23,8 +18,19 @@ mac_gcc_testing: ...@@ -23,8 +18,19 @@ mac_gcc_testing:
- python TriBITS/tribits/ci_support/clone_extra_repos.py - python TriBITS/tribits/ci_support/clone_extra_repos.py
- mkdir build - mkdir build
- cd build - cd build
- cmake -DTasmanian_DIR=/opt/tasmanian/6.0 -DDEBUG_OUTPUT=1 -DBUILDNAME=$(uname -s)-GCC-4.8.5-Debug-${CI_BUILD_REF_NAME} -DCMAKE_BUILD_TYPE=DEBUG -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_SECONDARY_TESTED_CODE=ON -Dradix_ENABLE_TESTS=ON -DTPL_ENABLE_VTK=ON -Dradix_ENABLE_radixplot=OFF -Dradix_ENABLE_radixwidgets=OFF .. - cmake -DTasmanian_DIR=/opt/tasmanian/6.0 ^
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -DExperimentalMemCheck -D ExperimentalSubmit -DBUILDNAME=$(uname -s)-GCC-4.8.5-Debug-${CI_BUILD_REF_NAME} ^
-DCMAKE_BUILD_TYPE=DEBUG ^
-Dradix_ENABLE_TESTS=ON ^
-Dradix_ENABLE_SECONDARY_TESTED_CODE=ON ^
-Dradix_ENABLE_TESTS=ON ^
-DTPL_ENABLE_VTK=ON ^
-Dradix_ENABLE_radixplot=OFF ^
-Dradix_ENABLE_radixwidgets=OFF ..
- ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
mac_llvm_testing: mac_llvm_testing:
tags: tags:
...@@ -32,7 +38,6 @@ mac_llvm_testing: ...@@ -32,7 +38,6 @@ mac_llvm_testing:
script: script:
- which git - which git
- git --version - git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- module load cmake qt/5.9.1 vtk/8.1.0 - module load cmake qt/5.9.1 vtk/8.1.0
- which python - which python
- python --version - python --version
...@@ -41,9 +46,19 @@ mac_llvm_testing: ...@@ -41,9 +46,19 @@ mac_llvm_testing:
- cd build - cd build
- which cmake - which cmake
- export radix_ENABLE_Fortran=OFF - export radix_ENABLE_Fortran=OFF
- cmake -DTasmanian_DIR=/opt/tasmanian/6.0 -DDEBUG_OUTPUT=1 -DBUILDNAME=$(uname -s)-LLVM-Debug-${CI_BUILD_REF_NAME} -DCMAKE_BUILD_TYPE=DEBUG -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_SECONDARY_TESTED_CODE=ON -Dradix_ENABLE_TESTS=ON -DTPL_ENABLE_VTK=ON -Dradix_ENABLE_radixplot=OFF -Dradix_ENABLE_radixwidgets=OFF .. - cmake -DTasmanian_DIR=/opt/tasmanian/6.0 ^
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -DExperimentalMemCheck -D ExperimentalSubmit -DBUILDNAME=$(uname -s)-LLVM-Debug-${CI_BUILD_REF_NAME} ^
-DCMAKE_BUILD_TYPE=DEBUG ^
-Dradix_ENABLE_TESTS=ON ^
-Dradix_ENABLE_SECONDARY_TESTED_CODE=ON ^
-Dradix_ENABLE_TESTS=ON ^
-DTPL_ENABLE_VTK=ON ^
-Dradix_ENABLE_radixplot=OFF ^
-Dradix_ENABLE_radixwidgets=OFF ..
- ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
linux_gcc_testing: linux_gcc_testing:
tags: tags:
...@@ -51,7 +66,6 @@ linux_gcc_testing: ...@@ -51,7 +66,6 @@ linux_gcc_testing:
script: script:
- which git - which git
- git --version - git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- which python - which python
- python --version - python --version
- python TriBITS/tribits/ci_support/clone_extra_repos.py - python TriBITS/tribits/ci_support/clone_extra_repos.py
...@@ -59,9 +73,19 @@ linux_gcc_testing: ...@@ -59,9 +73,19 @@ linux_gcc_testing:
- cd build - cd build
- module load cmake qt/5.9.0 vtk/8.1.0 - module load cmake qt/5.9.0 vtk/8.1.0
- which cmake - which cmake
- module load valgrind - cmake -DTasmanian_DIR=/opt/vendors/tasmanian/6.0 ^
- cmake -DTasmanian_DIR=/opt/vendors/tasmanian/6.0 -DBUILDNAME=$(uname -s)-GCC-4.8.5-Release-${CI_BUILD_REF_NAME} -DCMAKE_BUILD_TYPE=Release -Dradix_ENABLE_TESTS=ON -DENABLE_PYTHON_WRAPPERS=ON -Dradix_ENABLE_SECONDARY_TESTED_CODE=ON -Dradix_ENABLE_TESTS=ON -DTPL_ENABLE_VTK=ON -Dradix_ENABLE_radixplot=OFF -Dradix_ENABLE_radixwidgets=OFF .. -DBUILDNAME=$(uname -s)-GCC-4.8.5-Release-${CI_BUILD_REF_NAME} ^
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit -DCMAKE_BUILD_TYPE=Release ^
-Dradix_ENABLE_TESTS=ON ^
-DENABLE_PYTHON_WRAPPERS=ON ^
-Dradix_ENABLE_SECONDARY_TESTED_CODE=ON ^
-Dradix_ENABLE_TESTS=ON -DTPL_ENABLE_VTK=ON ^
-Dradix_ENABLE_radixplot=OFF ^
-Dradix_ENABLE_radixwidgets=OFF ..
- ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
linux_analysis: linux_analysis:
stage: analysis stage: analysis
...@@ -70,17 +94,30 @@ linux_analysis: ...@@ -70,17 +94,30 @@ linux_analysis:
script: script:
- which git - which git
- git --version - git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- which python - which python
- python --version - python --version
- python TriBITS/tribits/ci_support/clone_extra_repos.py - python TriBITS/tribits/ci_support/clone_extra_repos.py
- mkdir build - mkdir build
- cd build - cd build
- module load cmake - module load cmake valgrind
- which cmake - which cmake
- module load valgrind - cmake -DTasmanian_DIR=/opt/vendors/tasmanian/6.0/ ^
- cmake -DTasmanian_DIR=/opt/vendors/tasmanian/6.0/ -DDEBUG_OUTPUT=1 -D COVERAGE_EXTRA_FLAGS="-s ${CI_PROJECT_DIR}/googletest -d" -D MEMCHECK_COMMAND=$(which valgrind) -DBUILDNAME=$(uname -s)-GCC-4.8.5-Debug-${CI_BUILD_REF_NAME} -DCMAKE_BUILD_TYPE=DEBUG -Dradix_ENABLE_COVERAGE_TESTING=ON -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_SECONDARY_TESTED_CODE=ON -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_radixplot=OFF -Dradix_ENABLE_radixwidgets=OFF .. -DCOVERAGE_EXTRA_FLAGS="-s ${CI_PROJECT_DIR}/googletest -d" ^
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalMemCheck -D ExperimentalCoverage -D ExperimentalSubmit -DMEMCHECK_COMMAND=$(which valgrind) ^
-DBUILDNAME=$(uname -s)-GCC-4.8.5-Debug-${CI_BUILD_REF_NAME} ^
-DCMAKE_BUILD_TYPE=DEBUG ^
-Dradix_ENABLE_COVERAGE_TESTING=ON ^
-Dradix_ENABLE_TESTS=ON ^
-Dradix_ENABLE_SECONDARY_TESTED_CODE=ON ^
-Dradix_ENABLE_TESTS=ON ^
-Dradix_ENABLE_radixplot=OFF ^
-Dradix_ENABLE_radixwidgets=OFF ..
- ctest --verbose --output-on-failure^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest ^
-D ExperimentalMemCheck ^
-D ExperimentalCoverage
allow_failure: true allow_failure: true
linux_openmpi_testing: linux_openmpi_testing:
...@@ -89,7 +126,6 @@ linux_openmpi_testing: ...@@ -89,7 +126,6 @@ linux_openmpi_testing:
script: script:
- which git - which git
- git --version - git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- which python - which python
- python --version - python --version
- python TriBITS/tribits/ci_support/clone_extra_repos.py - python TriBITS/tribits/ci_support/clone_extra_repos.py
...@@ -97,60 +133,34 @@ linux_openmpi_testing: ...@@ -97,60 +133,34 @@ linux_openmpi_testing:
- cd build_mpi - cd build_mpi
- module load cmake openmpi/1.8.1 - module load cmake openmpi/1.8.1
- which cmake - which cmake
- cmake -DBUILDNAME=$(uname -s)-MPI-1.8.1-Debug-${CI_BUILD_REF_NAME} -DTPL_ENABLE_MPI=ON -DMPI_BASEDIR=`dirname $(dirname $(which mpicc))` -DCMAKE_BUILD_TYPE=DEBUG -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_radixpara=ON -Dradix_ENABLE_googletest=ON -Dradix_ENABLE_radixdl=ON -Dradix_ENABLE_radixcore=ON .. - cmake -DBUILDNAME=$(uname -s)-MPI-1.8.1-Debug-${CI_BUILD_REF_NAME} ^
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit -DTPL_ENABLE_MPI=ON ^
-DMPI_BASEDIR=`dirname $(dirname $(which mpicc))` ^
-DCMAKE_BUILD_TYPE=DEBUG ^
-Dradix_ENABLE_TESTS=ON ^
-Dradix_ENABLE_radixpara=ON ^
-Dradix_ENABLE_googletest=ON ^
-Dradix_ENABLE_radixdl=ON ^
-Dradix_ENABLE_radixcore=ON ..
- ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
windows_mingw_testing: windows_mingw_testing:
tags: tags:
- windows - windows
<<: *windows_before_script
script: script:
- where git - ci\windows_mingw_testing.bat
- git --version
- where cmake
- cmake --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- git clone https://github.com/lefebvre/testframework testframework
- git clone https://github.com/lefebvre/googletest googletest
- mkdir build
- cd build
- cmake -DTasmanian_DIR=c:/vendors/mingw-w64/tasmanian/6.0/ -DDEBUG_OUTPUT=1 -DTPL_LAPACK_LIBRARIES=c:/vendors/mingw-w64/lapack/3.5.0/lib/liblapack.a\\\;c:/vendors/mingw-w64/lapack/3.5.0/lib/libblas.a\\\;-lgfortran -DBUILDNAME=Windows-MinGW-GCC-4.8.5-Debug-%CI_BUILD_REF_NAME% -DCMAKE_BUILD_TYPE=DEBUG -Dradix_ENABLE_COVERAGE_TESTING=ON -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_SECONDARY_TESTED_CODE=ON -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_radixplot=OFF -Dradix_ENABLE_radixwidgets=OFF -G "MinGW Makefiles" ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit
windows_msvc_testing: windows_msvc_testing:
tags: tags:
- nsmwin10 - nsmwin10
<<: *windows_msvc_before_script
script: script:
- 'call "c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/vcvarsall.bat" amd64' - ci\windows_msvc_testing.bat
- where git
- git --version
- cmake --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- git clone https://github.com/lefebvre/testframework testframework
- git clone https://github.com/lefebvre/googletest googletest
- mkdir build
- cd build
- SET VTK_DIR=c:\vendors\cl\vtk\8.1.0\
- SET radix_ENABLE_Fortran=OFF
- cmake -DTasmanian_DIR=c:/vendors/cl/tasmanian/6.0/ -DBUILD_SHARED_LIBS=ON -DBUILDNAME=Windows-CL-18-Release-%CI_BUILD_REF_NAME% -DCMAKE_BUILD_TYPE=RELEASE -Dradix_ENABLE_SECONDARY_TESTED_CODE=ON -Dradix_ENABLE_TESTS=ON -DTPL_ENABLE_VTK=ON -Dradix_ENABLE_radixplot=OFF -Dradix_ENABLE_radixwidgets=OFF -Dradix_ENABLE_radixglls=OFF -G "NMake Makefiles" ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit
windows_intel_shared_testing: windows_intel_shared_testing:
tags: tags:
- nsmwin10 - nsmwin10
<<: *windows_msvc_before_script
script: script:
- 'call "c:/Program Files (x86)/Intel/Composer XE 2015/bin/ipsxe-comp-vars.bat" intel64 vs2013' - ci\windows_intel_testing.bat
- where git
- git --version
- where cmake
- cmake --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- git clone https://github.com/lefebvre/testframework testframework
- git clone https://github.com/lefebvre/googletest googletest
- mkdir build
- cd build
- SET VTK_DIR=c:\vendors\cl\vtk\8.1.0\
- cmake -DTasmanian_DIR=c:/vendors/cl/tasmanian/6.0/ -DBUILD_SHARED_LIBS=ON -DTPL_LAPACK_LIBRARIES=c:/vendors/intel/lapack/3.5.0/lib/lapack.lib\\\;c:/vendors/intel/lapack/3.5.0/lib/blas.lib -DBUILDNAME=Windows-Intel-15-Release-%CI_BUILD_REF_NAME% -DCMAKE_C_COMPILER=icl -DCMAKE_CXX_COMPILER=icl -DCMAKE_BUILD_TYPE=RELEASE -Dradix_ENABLE_SECONDARY_TESTED_CODE=ON -Dradix_ENABLE_TESTS=ON -DTPL_ENABLE_VTK=ON -Dradix_ENABLE_radixplot=OFF -Dradix_ENABLE_radixwidgets=OFF -G "NMake Makefiles" ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit
[submodule "submodules/googletest"]
path = submodules/googletest
url = https://github.com/lefebvre/googletest.git
[submodule "submodules/testframework"]
path = submodules/testframework
url = https://github.com/lefebvre/testframework.git
[submodule "TriBITS"]
path = TriBITS
url = https://github.com/lefebvre/TriBITS.git
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
##---------------------------------------------------------------------------## ##---------------------------------------------------------------------------##
TRIBITS_REPOSITORY_DEFINE_PACKAGES( TRIBITS_REPOSITORY_DEFINE_PACKAGES(
googletest googletest/googletest PT googletest submodules/googletest/googletest PT
testframework testframework PT testframework submodules/testframework PT
radix . PT radix . PT
) )
......
Subproject commit 45a6ab1e69c1e65a8e1d61e4de7db5e53340245d
set PATH=c:\Qt\5.9.1\msvc2013_64\bin;%PATH%;c:\Program Files (x86)\NSIS\Bin
call "c:/Program Files (x86)/Intel/Composer XE 2015/bin/ipsxe-comp-vars.bat" intel64 vs2013
where git
git --version
where qmake
qmake -version
where cmake
cmake --version
mkdir build
cd build
SET VTK_DIR=c:\vendors\cl\vtk\8.1.0\
cmake -DTasmanian_DIR=c:/vendors/cl/tasmanian/6.0/ ^
-DBUILD_SHARED_LIBS=ON ^
-DTPL_LAPACK_LIBRARIES=c:/vendors/intel/lapack/3.5.0/lib/lapack.lib\\\;c:/vendors/intel/lapack/3.5.0/lib/blas.lib ^
-DBUILDNAME=Windows-Intel-15-Release-%CI_BUILD_REF_NAME% ^
-DCMAKE_C_COMPILER=icl ^
-DCMAKE_CXX_COMPILER=icl ^
-DCMAKE_BUILD_TYPE=RELEASE ^
-Dradix_ENABLE_SECONDARY_TESTED_CODE=ON ^
-Dradix_ENABLE_TESTS=ON ^
-DTPL_ENABLE_VTK=ON ^
-Dradix_ENABLE_radixplot=OFF ^
-Dradix_ENABLE_radixwidgets=OFF ^
-G "NMake Makefiles" ..
ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
\ No newline at end of file
set PATH=%PATH%;c:\vendors\mingw-w64\x86_64-4.8.5-posix-seh-rt_v4-rev0\mingw64\bin;c:\vendors\mingw-w64\qt\5.9.1\bin
where git
git --version
where qmake
qmake -version
where cmake
cmake --version
mkdir build
cd build
cmake -DTasmanian_DIR=c:/vendors/mingw-w64/tasmanian/6.0/ ^
-DDEBUG_OUTPUT=1 ^
-DTPL_LAPACK_LIBRARIES=c:/vendors/mingw-w64/lapack/3.5.0/lib/liblapack.a\\\;c:/vendors/mingw-w64/lapack/3.5.0/lib/libblas.a\\\;-lgfortran ^
-DBUILDNAME=Windows-MinGW-GCC-4.8.5-Debug-%CI_BUILD_REF_NAME% ^
-DCMAKE_BUILD_TYPE=DEBUG ^
-Dradix_ENABLE_COVERAGE_TESTING=ON ^
-Dradix_ENABLE_TESTS=ON ^
-Dradix_ENABLE_SECONDARY_TESTED_CODE=ON ^
-Dradix_ENABLE_TESTS=ON ^
-Dradix_ENABLE_radixplot=OFF ^
-Dradix_ENABLE_radixwidgets=OFF ^
-G "MinGW Makefiles" ..
ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
\ No newline at end of file
set PATH=c:\Qt\5.9.1\msvc2013_64\bin;%PATH%;c:\Program Files (x86)\NSIS\Bin
call "c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/vcvarsall.bat" amd64
where git
git --version
where qmake
qmake -version
where cmake
cmake --version
mkdir build
cd build
SET VTK_DIR=c:\vendors\cl\vtk\8.1.0\
SET radix_ENABLE_Fortran=OFF
cmake -DTasmanian_DIR=c:/vendors/cl/tasmanian/6.0/ ^
-DBUILD_SHARED_LIBS=ON ^
-DBUILDNAME=Windows-CL-18-Release-%CI_BUILD_REF_NAME% ^
-DCMAKE_BUILD_TYPE=RELEASE ^
-Dradix_ENABLE_SECONDARY_TESTED_CODE=ON ^
-Dradix_ENABLE_TESTS=ON ^
-DTPL_ENABLE_VTK=ON ^
-Dradix_ENABLE_radixplot=OFF ^
-Dradix_ENABLE_radixwidgets=OFF ^
-Dradix_ENABLE_radixglls=OFF ^
-G "NMake Makefiles" ..
ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
\ No newline at end of file
...@@ -15,7 +15,7 @@ MACRO(TRIBITS_REPOSITORY_SETUP_EXTRA_OPTIONS) ...@@ -15,7 +15,7 @@ MACRO(TRIBITS_REPOSITORY_SETUP_EXTRA_OPTIONS)
# #
# Include the testframework setup # Include the testframework setup
# #
ADD_SUBDIRECTORY(${radix_SOURCE_DIR}/testframework/setup) ADD_SUBDIRECTORY(${radix_SOURCE_DIR}/submodules/testframework/setup)
# Set CXX11 to be enabled by default. # Set CXX11 to be enabled by default.
SET(${PROJECT_NAME}_ENABLE_CXX11_DEFAULT TRUE) SET(${PROJECT_NAME}_ENABLE_CXX11_DEFAULT TRUE)
......
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
#include <algorithm> #include <algorithm>
#ifdef _MSC_VER
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#endif
namespace radix namespace radix
{ {
const std::array<char, 22> UTMZones::letters = { const std::array<char, 22> UTMZones::letters = {
...@@ -213,8 +219,9 @@ void CoordinateConversion::validate(const std::pair<double, double>& point) ...@@ -213,8 +219,9 @@ void CoordinateConversion::validate(const std::pair<double, double>& point)
std::string CoordinateConversion::toString(const UTMCoordinate& utm) std::string CoordinateConversion::toString(const UTMCoordinate& utm)
{ {
char buff[120]; char buff[120];
sprintf(buff, "%02d %c %f %f", utm.longitude_zone, utm.lattitude_zone, snprintf(buff, sizeof(buff), "%02d %c %f %f", utm.longitude_zone,
utm.easting, utm.northing); utm.lattitude_zone, utm.easting, utm.northing);
buff[119] = '\0'; // null terminate
return std::string(buff); return std::string(buff);
} }
...@@ -329,4 +336,4 @@ std::pair<double, double> UTM2LatLon::toLatLon(const UTMCoordinate& c) ...@@ -329,4 +336,4 @@ std::pair<double, double> UTM2LatLon::toLatLon(const UTMCoordinate& c)
} }
// UTMZones::latZone // UTMZones::latZone
} // namespace radix } // namespace radix
\ No newline at end of file
...@@ -6,6 +6,13 @@ ...@@ -6,6 +6,13 @@
#include "radixmath/util.hh" #include "radixmath/util.hh"
#include <fstream> #include <fstream>
#ifdef _MSC_VER
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#endif
namespace radix namespace radix
{ {
class ARLDataStream::PImpl class ARLDataStream::PImpl
...@@ -78,7 +85,7 @@ void ARLDataStream::expand(const std::string& val, ...@@ -78,7 +85,7 @@ void ARLDataStream::expand(const std::string& val,
ARLDataStream::ARLDataStream(const std::string& file, ARLDataStream::ARLDataStream(const std::string& file,
std::ios_base::openmode mode) std::ios_base::openmode mode)
: p(new PImpl(), [](PImpl* impl) { delete impl; }) : p(new PImpl())
{ {
p->file = file; p->file = file;
p->stream = std::make_shared<radix::eafstream>(p->file.c_str(), p->stream = std::make_shared<radix::eafstream>(p->file.c_str(),
...@@ -89,6 +96,8 @@ ARLDataStream::ARLDataStream(const std::string& file, ...@@ -89,6 +96,8 @@ ARLDataStream::ARLDataStream(const std::string& file,
} }
} }
ARLDataStream::~ARLDataStream() { delete p; }
bool ARLDataStream::read_record_header(ARLRecordHeader& rheader) bool ARLDataStream::read_record_header(ARLRecordHeader& rheader)
{ {
bool result = false; bool result = false;
...@@ -128,11 +137,12 @@ bool ARLDataStream::write_record_header(const ARLRecordHeader& rheader) ...@@ -128,11 +137,12 @@ bool ARLDataStream::write_record_header(const ARLRecordHeader& rheader)
// Construct index header string // Construct index header string
char recordHeader[51]; char recordHeader[51];
sprintf(recordHeader, "%2d%2d%2d%2d%2d%2d%2d%4s%4d%14.7E%14.7E", year, snprintf(recordHeader, sizeof(recordHeader),
rheader.month, rheader.day, rheader.hour, rheader.ic, rheader.il, "%2d%2d%2d%2d%2d%2d%2d%4s%4d%14.7E%14.7E", year, rheader.month,
std::stoi(rheader.cgrid.c_str()), rheader.kvar.c_str(), rheader.nexp, rheader.day, rheader.hour, rheader.ic, rheader.il,
rheader.prec, rheader.var1); std::stoi(rheader.cgrid.c_str()), rheader.kvar.c_str(), rheader.nexp,
recordHeader[50] = '\0'; // null-terminate rheader.prec, rheader.var1);
recordHeader[50] = '\0'; // null-terminate
p->stream->writeString(std::string(recordHeader), p->stream->writeString(std::string(recordHeader),
ARLDataStream::PImpl::recordHeaderLength); ARLDataStream::PImpl::recordHeaderLength);
...@@ -222,7 +232,7 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader, ...@@ -222,7 +232,7 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader,
radix_line(" Size of each record = " << p->recordSize); radix_line(" Size of each record = " << p->recordSize);
const size_t MAX_HEADER_LENGTH = 10000; const size_t MAX_HEADER_LENGTH = 10000;
char indexHeaderMain[ARLDataStream::PImpl::indexHeaderLength+1], char indexHeaderMain[ARLDataStream::PImpl::indexHeaderLength + 1],
indexHeaderVars[MAX_HEADER_LENGTH]; indexHeaderVars[MAX_HEADER_LENGTH];
int pos = 0; int pos = 0;
...@@ -251,7 +261,8 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader, ...@@ -251,7 +261,8 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader,
iheader.orient, iheader.tang_lat, iheader.sync_xp, iheader.sync_yp, iheader.orient, iheader.tang_lat, iheader.sync_xp, iheader.sync_yp,
iheader.sync_lat, iheader.sync_lon, iheader.dummy, iheader.nx, iheader.sync_lat, iheader.sync_lon, iheader.dummy, iheader.nx,
iheader.ny, iheader.nz, iheader.z_flag, headerLength); iheader.ny, iheader.nz, iheader.z_flag, headerLength);
indexHeaderMain[ARLDataStream::PImpl::indexHeaderLength] = '\0'; // null-terminate indexHeaderMain[ARLDataStream::PImpl::indexHeaderLength] =
'\0'; // null-terminate
// Write the two elements of the header // Write the two elements of the header
p->stream->writeString(std::string(indexHeaderMain), p->stream->writeString(std::string(indexHeaderMain),
......
...@@ -22,8 +22,7 @@ class RADIX_PUBLIC ARLDataStream ...@@ -22,8 +22,7 @@ class RADIX_PUBLIC ARLDataStream
{ {
// forward declare private implementation // forward declare private implementation
class PImpl; class PImpl;
// unique pointer to private implmentation PImpl* p;
std::unique_ptr<PImpl, void (*)(PImpl*)> p;
private: private:
/** /**
...@@ -46,7 +45,7 @@ class RADIX_PUBLIC ARLDataStream ...@@ -46,7 +45,7 @@ class RADIX_PUBLIC ARLDataStream
public: public:
ARLDataStream() = delete; ARLDataStream() = delete;
ARLDataStream(const std::string& file, std::ios_base::openmode mode); ARLDataStream(const std::string& file, std::ios_base::openmode mode);
~ARLDataStream();
/** /**
* @brief read_index_header Reads a single index header from the stream * @brief read_index_header Reads a single index header from the stream
* @param iheader ARLIndexHeader& * @param iheader ARLIndexHeader&
......
...@@ -412,10 +412,14 @@ void eafstream::writeDouble(double var) ...@@ -412,10 +412,14 @@ void eafstream::writeDouble(double var)
*/ */
int *eafstream::readIntArray(int size) int *eafstream::readIntArray(int size)
{ {
int fortifySize = 0;
while (fortifySize < size &&
fortifySize < std::numeric_limits<int>::max() / int_size)
fortifySize++;
int *array = NULL; int *array = NULL;
try try
{ {
array = new int[size]; array = new int[size_t(fortifySize)];
} }
catch (std::bad_alloc &xa) catch (std::bad_alloc &xa)
{ {
...@@ -424,7 +428,7 @@ int *eafstream::readIntArray(int size) ...@@ -424,7 +428,7 @@ int *eafstream::readIntArray(int size)
exit(1); exit(1);
} }
this->read((char *)(array), size * int_size); this->read((char *)(array), fortifySize * int_size);
if (this->bad() || this->eof()) if (this->bad() || this->eof())
{ {
std::stringstream ss; std::stringstream ss;
...@@ -436,10 +440,10 @@ int *eafstream::readIntArray(int size) ...@@ -436,10 +440,10 @@ int *eafstream::readIntArray(int size)
} }
if (mReverseBytes == true)