Commit affa63e4 authored by Lefebvre, Jordan's avatar Lefebvre, Jordan
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
.vscode
build/
......
variables:
GIT_SUBMODULE_STRATEGY: normal
stages:
- test
- 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:
tags:
- mac
script:
- which git
- 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
- which cmake
- which python
......@@ -23,8 +18,19 @@ mac_gcc_testing:
- python TriBITS/tribits/ci_support/clone_extra_repos.py
- mkdir 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 ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -DExperimentalMemCheck -D ExperimentalSubmit
- cmake -DTasmanian_DIR=/opt/tasmanian/6.0 ^
-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:
tags:
......@@ -32,7 +38,6 @@ mac_llvm_testing:
script:
- which git
- git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- module load cmake qt/5.9.1 vtk/8.1.0
- which python
- python --version
......@@ -41,9 +46,19 @@ mac_llvm_testing:
- cd build
- which cmake
- 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 ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -DExperimentalMemCheck -D ExperimentalSubmit
- cmake -DTasmanian_DIR=/opt/tasmanian/6.0 ^
-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:
tags:
......@@ -51,7 +66,6 @@ linux_gcc_testing:
script:
- which git
- git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- which python
- python --version
- python TriBITS/tribits/ci_support/clone_extra_repos.py
......@@ -59,9 +73,19 @@ linux_gcc_testing:
- cd build
- module load cmake qt/5.9.0 vtk/8.1.0
- which cmake
- module load valgrind
- 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 ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit
- 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 ..
- ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
linux_analysis:
stage: analysis
......@@ -70,17 +94,30 @@ linux_analysis:
script:
- which git
- git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- which python
- python --version
- python TriBITS/tribits/ci_support/clone_extra_repos.py
- mkdir build
- cd build
- module load cmake
- module load cmake valgrind
- which cmake
- module load valgrind
- 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 ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalMemCheck -D ExperimentalCoverage -D ExperimentalSubmit
- cmake -DTasmanian_DIR=/opt/vendors/tasmanian/6.0/ ^
-DCOVERAGE_EXTRA_FLAGS="-s ${CI_PROJECT_DIR}/googletest -d" ^
-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
linux_openmpi_testing:
......@@ -89,7 +126,6 @@ linux_openmpi_testing:
script:
- which git
- git --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
- which python
- python --version
- python TriBITS/tribits/ci_support/clone_extra_repos.py
......@@ -97,60 +133,34 @@ linux_openmpi_testing:
- cd build_mpi
- module load cmake openmpi/1.8.1
- 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 ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit
- 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 ..
- ctest --verbose --output-on-failure ^
-D ExperimentalStart ^
-D ExperimentalBuild ^
-D ExperimentalTest
windows_mingw_testing:
tags:
- windows
<<: *windows_before_script
script:
- 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
- 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
- ci\windows_mingw_testing.bat
windows_msvc_testing:
tags:
- nsmwin10
<<: *windows_msvc_before_script
script:
- 'call "c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/vcvarsall.bat" amd64'
- 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
- ci\windows_msvc_testing.bat
windows_intel_shared_testing:
tags:
- nsmwin10
<<: *windows_msvc_before_script
script:
- 'call "c:/Program Files (x86)/Intel/Composer XE 2015/bin/ipsxe-comp-vars.bat" intel64 vs2013'
- 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
- ci\windows_intel_testing.bat
[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 @@
##---------------------------------------------------------------------------##
TRIBITS_REPOSITORY_DEFINE_PACKAGES(
googletest googletest/googletest PT
testframework testframework PT
googletest submodules/googletest/googletest PT
testframework submodules/testframework 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)
#
# 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(${PROJECT_NAME}_ENABLE_CXX11_DEFAULT TRUE)
......
......@@ -4,6 +4,12 @@
#include <algorithm>
#ifdef _MSC_VER
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#endif
namespace radix
{
const std::array<char, 22> UTMZones::letters = {
......@@ -213,8 +219,9 @@ void CoordinateConversion::validate(const std::pair<double, double>& point)
std::string CoordinateConversion::toString(const UTMCoordinate& utm)
{
char buff[120];
sprintf(buff, "%02d %c %f %f", utm.longitude_zone, utm.lattitude_zone,
utm.easting, utm.northing);
snprintf(buff, sizeof(buff), "%02d %c %f %f", utm.longitude_zone,
utm.lattitude_zone, utm.easting, utm.northing);
buff[119] = '\0'; // null terminate
return std::string(buff);
}
......@@ -329,4 +336,4 @@ std::pair<double, double> UTM2LatLon::toLatLon(const UTMCoordinate& c)
}
// UTMZones::latZone
} // namespace radix
\ No newline at end of file
} // namespace radix
......@@ -6,6 +6,13 @@
#include "radixmath/util.hh"
#include <fstream>
#ifdef _MSC_VER
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#endif
namespace radix
{
class ARLDataStream::PImpl
......@@ -78,7 +85,7 @@ void ARLDataStream::expand(const std::string& val,
ARLDataStream::ARLDataStream(const std::string& file,
std::ios_base::openmode mode)
: p(new PImpl(), [](PImpl* impl) { delete impl; })
: p(new PImpl())
{
p->file = file;
p->stream = std::make_shared<radix::eafstream>(p->file.c_str(),
......@@ -89,6 +96,8 @@ ARLDataStream::ARLDataStream(const std::string& file,
}
}
ARLDataStream::~ARLDataStream() { delete p; }
bool ARLDataStream::read_record_header(ARLRecordHeader& rheader)
{
bool result = false;
......@@ -128,11 +137,12 @@ bool ARLDataStream::write_record_header(const ARLRecordHeader& rheader)
// Construct index header string
char recordHeader[51];
sprintf(recordHeader, "%2d%2d%2d%2d%2d%2d%2d%4s%4d%14.7E%14.7E", year,
rheader.month, rheader.day, rheader.hour, rheader.ic, rheader.il,
std::stoi(rheader.cgrid.c_str()), rheader.kvar.c_str(), rheader.nexp,
rheader.prec, rheader.var1);
recordHeader[50] = '\0'; // null-terminate
snprintf(recordHeader, sizeof(recordHeader),
"%2d%2d%2d%2d%2d%2d%2d%4s%4d%14.7E%14.7E", year, rheader.month,
rheader.day, rheader.hour, rheader.ic, rheader.il,
std::stoi(rheader.cgrid.c_str()), rheader.kvar.c_str(), rheader.nexp,
rheader.prec, rheader.var1);
recordHeader[50] = '\0'; // null-terminate
p->stream->writeString(std::string(recordHeader),
ARLDataStream::PImpl::recordHeaderLength);
......@@ -222,7 +232,7 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader,
radix_line(" Size of each record = " << p->recordSize);
const size_t MAX_HEADER_LENGTH = 10000;
char indexHeaderMain[ARLDataStream::PImpl::indexHeaderLength+1],
char indexHeaderMain[ARLDataStream::PImpl::indexHeaderLength + 1],
indexHeaderVars[MAX_HEADER_LENGTH];
int pos = 0;
......@@ -251,7 +261,8 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader,
iheader.orient, iheader.tang_lat, iheader.sync_xp, iheader.sync_yp,
iheader.sync_lat, iheader.sync_lon, iheader.dummy, iheader.nx,
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
p->stream->writeString(std::string(indexHeaderMain),
......
......@@ -22,8 +22,7 @@ class RADIX_PUBLIC ARLDataStream
{
// forward declare private implementation
class PImpl;
// unique pointer to private implmentation
std::unique_ptr<PImpl, void (*)(PImpl*)> p;
PImpl* p;
private:
/**
......@@ -46,7 +45,7 @@ class RADIX_PUBLIC ARLDataStream
public:
ARLDataStream() = delete;
ARLDataStream(const std::string& file, std::ios_base::openmode mode);
~ARLDataStream();
/**
* @brief read_index_header Reads a single index header from the stream
* @param iheader ARLIndexHeader&
......
......@@ -412,10 +412,14 @@ void eafstream::writeDouble(double var)
*/
int *eafstream::readIntArray(int size)
{
int fortifySize = 0;
while (fortifySize < size &&
fortifySize < std::numeric_limits<int>::max() / int_size)
fortifySize++;
int *array = NULL;
try
{
array = new int[size];
array = new int[size_t(fortifySize)];
}
catch (std::bad_alloc &xa)
{
......@@ -424,7 +428,7 @@ int *eafstream::readIntArray(int size)
exit(1);
}
this->read((char *)(array), size * int_size);
this->read((char *)(array), fortifySize * int_size);
if (this->bad() || this->eof())
{
std::stringstream ss;
......@@ -436,10 +440,10 @@ int *eafstream::readIntArray(int size)
}
if (mReverseBytes == true)
{
reverse_array_int_bytes(array, size);
reverse_array_int_bytes(array, size_t(fortifySize));
}
// increment bytes read
mBytesRead += (size * int_size);
mBytesRead += (fortifySize * int_size);
return array;
} // readIntArray
......@@ -469,10 +473,14 @@ void eafstream::writeIntArray(const std::vector<int> &var)
*/
float *eafstream::readFloatArray(int size)
{
float *array = NULL;
int fortifySize = 0;
while (fortifySize < size &&
fortifySize < std::numeric_limits<int>::max() / float_size)
fortifySize++;
float *array = nullptr;
try
{
array = new float[size];
array = new float[size_t(fortifySize)];
}
catch (std::bad_alloc &xa)
{
......@@ -480,7 +488,7 @@ float *eafstream::readFloatArray(int size)
<< __LINE__ << std::endl;
exit(1);
}
this->read((char *)(array), size * float_size);
this->read((char *)(array), fortifySize * float_size);
if (this->bad() || this->eof())
{
std::stringstream ss;
......@@ -492,10 +500,10 @@ float *eafstream::readFloatArray(int size)
}
if (mReverseBytes == true)
{
reverse_array_float_bytes(array, size);
reverse_array_float_bytes(array, size_t(fortifySize));
}
// increment bytes read
mBytesRead += (size * float_size);
mBytesRead += (fortifySize * float_size);
return array;
}
......@@ -581,9 +589,13 @@ void eafstream::writeDoubleArray(const std::vector<double> &var)
*/
std::string eafstream::readString(int size)
{
char *array = new char[size + 1];
this->read((char *)(array), size);
array[size] = '\0';
int fortifySize = 0;
while (fortifySize < size &&
fortifySize < std::numeric_limits<int>::max() - 1)
fortifySize++;
char *array = new char[size_t(fortifySize + 1)];
this->read(static_cast<char *>(array), fortifySize);
array[fortifySize] = '\0';
if (this->bad() || this->eof())
{
std::stringstream ss;
......@@ -595,12 +607,12 @@ std::string eafstream::readString(int size)
}
// increment bytes read
mBytesRead += size;
mBytesRead += fortifySize;
std::string s;
// we must assign string to avoid
// implicit copy constructor which stops at '\0'
// character in the content of data
s.assign(array, size);
s.assign(array, fortifySize);
delete[] array;
// no need to reverse ascii characters
return s;
......
......@@ -69,9 +69,9 @@ int reverse_int_bytes(int value)
/*!
* Reverses the bytes of all integers in an array
* */
void reverse_array_int_bytes(int *array, int size)
void reverse_array_int_bytes(int *array, size_t size)
{
for (int i = 0; i < size; i++)
for (size_t i = 0; i < size; i++)
{
array[i] = reverse_int_bytes(array[i]);
}
......@@ -100,9 +100,9 @@ float reverse_float_bytes(float value)
/*!
* Reverses the bytes of all float in an array
* */
void reverse_array_float_bytes(float *array, int size)
void reverse_array_float_bytes(float *array, size_t size)
{
for (int i = 0; i < size; i++)
for (size_t i = 0; i < size; i++)
{
array[i] = reverse_float_bytes(array[i]);
}
......
......@@ -13,8 +13,8 @@ void RADIX_PUBLIC reverse_bytes(char *original, void *returnVal, int length);
short RADIX_PUBLIC reverse_short_bytes(short value);
unsigned short RADIX_PUBLIC reverse_ushort_bytes(unsigned short value);
int RADIX_PUBLIC reverse_int_bytes(int value);
void RADIX_PUBLIC reverse_array_int_bytes(int *array, int size);
void RADIX_PUBLIC reverse_array_float_bytes(float *array, int size);
void RADIX_PUBLIC reverse_array_int_bytes(int *array, size_t size);
void RADIX_PUBLIC reverse_array_float_bytes(float *array, size_t size);
long RADIX_PUBLIC reverse_long_bytes(long value);
float RADIX_PUBLIC reverse_float_bytes(float value);
double RADIX_PUBLIC reverse_double_bytes(double value);
......
......@@ -48,12 +48,12 @@ class F71Case::PImpl
float flux;
};
F71Case::F71Case()
: p(new PImpl(), [](PImpl* impl) { delete impl; })
: p(new PImpl())
{
}
F71Case::F71Case(const F71Case& orig)
: p(new PImpl(), [](PImpl* impl) { delete impl; })
: p(new PImpl())