Skip to content

Commit

Permalink
Check for nullptr in debug builds
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Hahn <[email protected]>
  • Loading branch information
quantumsteve committed May 16, 2024
1 parent 8ce0079 commit 2926f18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/korc_c_random.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <random>
#include <chrono>
#include <random>
#include <stdexcept>

class random {
std::mt19937_64 engine;
Expand Down Expand Up @@ -51,10 +52,18 @@ extern "C" {
}

double random_get_number_U(void *r) {
#ifndef NDEBUG
if(r == nullptr)
throw std::runtime_error("random_U object not initialized!");
#endif
return static_cast<class random_U *> (r)->get_number_U();
}

double random_get_number_N(void *r) {
#ifndef NDEBUG
if(r == nullptr)
throw std::runtime_error("random_N object not initialized!");
#endif
return static_cast<class random_N *> (r)->get_number_N();
}

Expand Down
3 changes: 0 additions & 3 deletions src/korc_velocity_distribution.f90
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,9 @@ subroutine gyro_distribution(params,F,spp)
call RANDOM_NUMBER(theta)
call finalize_random_seed
else
call initialize_random(1)
call initialize_random_U(1)
do pp=1_idef,spp%ppp
theta(pp)=get_random_U()
enddo
call finalize_random()
endif
theta = 2.0_rp*C_PI*theta

Expand Down

0 comments on commit 2926f18

Please sign in to comment.