Commit affa63e4 authored by Lefebvre, Jordan's avatar Lefebvre, Jordan

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/
......
This diff is collapsed.
[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())
{
p->light_element_nuclides = orig.p->light_element_nuclides;
p->actinide_nuclides = orig.p->actinide_nuclides;
......@@ -92,6 +92,8 @@ F71Case::F71Case(const F71Case& orig)
p->flux = orig.p->flux;
}
F71Case::~F71Case() { delete p; }
const std::vector<int>& F71Case::lightElementNuclides() const
{
return p->light_element_nuclides;
......
......@@ -76,12 +76,12 @@ class RADIX_PUBLIC F71Case
{
// forward declare private implementation
class PImpl;
// unique pointer to private implmentation
std::unique_ptr<PImpl, void (*)(PImpl*)> p;
PImpl* p;
public:
F71Case();
F71Case(const F71Case& orig);
~F71Case();
const std::vector<int>& lightElementNuclides() const;
void setLightElementNuclides(const std::vector<int>& zaids);
......
......@@ -4,6 +4,13 @@
#include "radixbug/bug.hh"
#include "radixio/eafstream.hh"
#include "radixio/hysplitcdump.hh"
#ifdef _MSC_VER
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#endif
namespace radix
{
template <typename data_type>
......@@ -147,16 +154,9 @@ bool HysplitCDumpStream<data_type>::write_to(const std::string &file) const
std::string id = mData->id();
{
// force string to be only 4 characters
// force string to be no more than 4 characters
char cid[5];
if (id.size() > 4)
{
sprintf(cid, "%4s", id.substr(0, 4).c_str());
}
else
{
sprintf(cid, "%4s", id.c_str());
}
snprintf(cid, sizeof(cid), "%4s", id.c_str());
cid[4] = '\0'; // null terminate
id = cid;
}
......@@ -236,17 +236,10 @@ bool HysplitCDumpStream<data_type>::write_to(const std::string &file) const
{
std::string pol = mData->pollutant(i);
radix_tagged_line("pollutant=" << pol);
// force string to be only 4 characters
// force string to be no more than 4 characters
char icid[5];
if (pol.size() > 4)
{
sprintf(icid, "%4s", pol.substr(0, 4).c_str());
}
else
{
sprintf(icid, "%4s", pol.c_str());
}
icid[4] = '\0';
snprintf(icid, sizeof(icid), "%4s", pol.c_str());
icid[4] = '\0'; // null terminate
std::string tmp = icid;
fstr.writeString(tmp);
local_pols.push_back(tmp);
......
......@@ -375,14 +375,14 @@ bool SpectrumPCFStream<data_type>::write_to(const std::string &file) const
stream.writeString(" ", 512 - stream.bytesWritten());
// Write the pairs themselves
for (size_t column = 0; column < 2; ++column)
for (size_t column = 0; column < 20; ++column)
{
radix(" ");
for (size_t panel = 0; panel < 8; ++panel)
{
for (size_t mca = 0; mca < 8; ++mca)
{
for (size_t pair = 0; pair < 20; ++pair)
for (size_t pair = 0; pair < 2; ++pair)
{
stream.writeFloat(
mData->deviationPairEnergies()[column][panel][mca][pair]);
......
Subproject commit fbc5670a34d8b186f60f6c19183a3772698eec12
Subproject commit f47c3cb7694528fbd17d1226817e5e278fd901e2
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment