aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-10-23 15:53:19 +0200
committerThomas White <taw@physics.org>2017-10-23 16:01:37 +0200
commit45038c42847476ce1aee5b09c47fb330a0108cd6 (patch)
tree3979667c80cacc3bd34d0f59fc905a0d4c0b3d0d /tests
parent7b6fa15e761ec0c5ae9010dc21786a1a3dda7076 (diff)
Check return values from fread/fgets
Diffstat (limited to 'tests')
-rw-r--r--tests/integration_check.c7
-rw-r--r--tests/prof2d_check.c7
-rw-r--r--tests/ring_check.c6
3 files changed, 15 insertions, 5 deletions
diff --git a/tests/integration_check.c b/tests/integration_check.c
index 0713d837..65241612 100644
--- a/tests/integration_check.c
+++ b/tests/integration_check.c
@@ -65,9 +65,12 @@ int main(int argc, char *argv[])
rng = gsl_rng_alloc(gsl_rng_mt19937);
fh = fopen("/dev/urandom", "r");
- fread(&seed, sizeof(seed), 1, fh);
+ if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) {
+ gsl_rng_set(rng, seed);
+ } else {
+ ERROR("Failed to seed RNG\n");
+ }
fclose(fh);
- gsl_rng_set(rng, seed);
image.beam = NULL;
image.lambda = ph_eV_to_lambda(9000.0);
diff --git a/tests/prof2d_check.c b/tests/prof2d_check.c
index 8081748c..9fe8b356 100644
--- a/tests/prof2d_check.c
+++ b/tests/prof2d_check.c
@@ -73,9 +73,12 @@ int main(int argc, char *argv[])
rng = gsl_rng_alloc(gsl_rng_mt19937);
fh = fopen("/dev/urandom", "r");
- fread(&seed, sizeof(seed), 1, fh);
+ if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) {
+ gsl_rng_set(rng, seed);
+ } else {
+ ERROR("Failed to seed RNG\n");
+ }
fclose(fh);
- gsl_rng_set(rng, seed);
image.beam = NULL;
image.lambda = ph_eV_to_lambda(9000.0);
diff --git a/tests/ring_check.c b/tests/ring_check.c
index cc8a1c8e..0997447f 100644
--- a/tests/ring_check.c
+++ b/tests/ring_check.c
@@ -176,7 +176,11 @@ int main(int argc, char *argv[])
rng = gsl_rng_alloc(gsl_rng_mt19937);
fh = fopen("/dev/urandom", "r");
- fread(&seed, sizeof(seed), 1, fh);
+ if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) {
+ gsl_rng_set(rng, seed);
+ } else {
+ ERROR("Failed to seed RNG\n");
+ }
fclose(fh);
gsl_rng_set(rng, seed);