From 1a5b7104d20d3bf5afd70b7837a526d34abb8c2d Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sat, 10 Mar 2018 16:59:28 -0700 Subject: Added nullptr checks around file access --- src/survive_default_devices.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/survive_default_devices.c b/src/survive_default_devices.c index 6615f1e..0229c63 100644 --- a/src/survive_default_devices.c +++ b/src/survive_default_devices.c @@ -180,20 +180,24 @@ int survive_load_htc_config_format(char *ct0conf, int len, SurviveObject *so) { sprintf(fname, "calinfo/%s_points.csv", so->codename); FILE *f = fopen(fname, "w"); int j; - for (j = 0; j < so->nr_locations; j++) { - fprintf(f, "%f %f %f\n", so->sensor_locations[j * 3 + 0], - so->sensor_locations[j * 3 + 1], - so->sensor_locations[j * 3 + 2]); + if(f) { + for (j = 0; j < so->nr_locations; j++) { + fprintf(f, "%f %f %f\n", so->sensor_locations[j * 3 + 0], + so->sensor_locations[j * 3 + 1], + so->sensor_locations[j * 3 + 2]); + } + fclose(f); } - fclose(f); - sprintf(fname, "calinfo/%s_normals.csv", so->codename); - f = fopen(fname, "w"); - for (j = 0; j < so->nr_locations; j++) { - fprintf(f, "%f %f %f\n", so->sensor_normals[j * 3 + 0], - so->sensor_normals[j * 3 + 1], so->sensor_normals[j * 3 + 2]); + if(f) { + sprintf(fname, "calinfo/%s_normals.csv", so->codename); + f = fopen(fname, "w"); + for (j = 0; j < so->nr_locations; j++) { + fprintf(f, "%f %f %f\n", so->sensor_normals[j * 3 + 0], + so->sensor_normals[j * 3 + 1], so->sensor_normals[j * 3 + 2]); + } + fclose(f); } - fclose(f); return 0; } -- cgit v1.2.3