Adding null pointer checks in bank.cpp

This commit is contained in:
Paul Romano 2020-04-23 07:00:56 -05:00
parent fd24191d31
commit 9ff0deda75

View file

@ -72,7 +72,7 @@ void sort_fission_bank()
// TODO: C++17 introduces the exclusive_scan() function which could be
// used to replace everything above this point in this function.
// We need a scratch vector to make permutation of the fission bank into
// sorted order easy. Under normal usage conditions, the fission bank is
// over provisioned, so we can use that as scratch space.
@ -106,6 +106,11 @@ void sort_fission_bank()
extern "C" int openmc_source_bank(void** ptr, int64_t* n)
{
if (!ptr || !n) {
set_errmsg("Received null pointer.");
return OPENMC_E_INVALID_ARGUMENT;
}
if (simulation::source_bank.size() == 0) {
set_errmsg("Source bank has not been allocated.");
return OPENMC_E_ALLOCATE;
@ -118,6 +123,11 @@ extern "C" int openmc_source_bank(void** ptr, int64_t* n)
extern "C" int openmc_fission_bank(void** ptr, int64_t* n)
{
if (!ptr || !n) {
set_errmsg("Received null pointer.");
return OPENMC_E_INVALID_ARGUMENT;
}
if (simulation::fission_bank.size() == 0) {
set_errmsg("Fission bank has not been allocated.");
return OPENMC_E_ALLOCATE;