aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Berger <j.david.berger@gmail.com>2018-03-10 16:59:28 -0700
committerJustin Berger <j.david.berger@gmail.com>2018-03-10 16:59:28 -0700
commit1a5b7104d20d3bf5afd70b7837a526d34abb8c2d (patch)
treec8e190ad708e55b68739bada3a896a6fa026d6d2
parent97c977a295ce61d1d284b51027fb76975b6dd0b8 (diff)
downloadlibsurvive-1a5b7104d20d3bf5afd70b7837a526d34abb8c2d.tar.gz
libsurvive-1a5b7104d20d3bf5afd70b7837a526d34abb8c2d.tar.bz2
Added nullptr checks around file access
-rw-r--r--src/survive_default_devices.c26
1 files 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;
}