diff options
author | CNLohr <charles@cnlohr.com> | 2018-03-10 19:14:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-10 19:14:01 -0500 |
commit | 1d0a7fc7c84ec9977cf9f456dcccd2b69c7ab9e2 (patch) | |
tree | c8e190ad708e55b68739bada3a896a6fa026d6d2 | |
parent | 97c977a295ce61d1d284b51027fb76975b6dd0b8 (diff) | |
parent | 1a5b7104d20d3bf5afd70b7837a526d34abb8c2d (diff) | |
download | libsurvive-1d0a7fc7c84ec9977cf9f456dcccd2b69c7ab9e2.tar.gz libsurvive-1d0a7fc7c84ec9977cf9f456dcccd2b69c7ab9e2.tar.bz2 |
Merge pull request #106 from jdavidberger/fix_file_write_segfault
Added nullptr checks around file access
-rw-r--r-- | src/survive_default_devices.c | 26 |
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; } |