From 102785d154c367514c3ec92c2d37474bd94c0a9f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 5 Feb 2015 00:58:27 -0600 Subject: [PATCH] Fix a warning about unused return value when using freopen in admesh. Added another NULL check for safety. --- xs/src/admesh/stlinit.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/xs/src/admesh/stlinit.c b/xs/src/admesh/stlinit.c index a7ab2b6d2..efc4e11ba 100644 --- a/xs/src/admesh/stlinit.c +++ b/xs/src/admesh/stlinit.c @@ -135,7 +135,21 @@ stl_count_facets(stl_file *stl, char *file) { /* Otherwise, if the .STL file is ASCII, then do the following */ else { /* Reopen the file in text mode (for getting correct newlines on Windows) */ - freopen(file, "r", stl->fp); + // fix to silence a warning about unused return value. + // obviously if it fails we have problems.... + stl->fp = freopen(file, "r", stl->fp); + + // do another null check to be safe + if(stl->fp == NULL) { + error_msg = (char*) + malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */ + sprintf(error_msg, "stl_initialize: Couldn't open %s for reading", + file); + perror(error_msg); + free(error_msg); + stl->error = 1; + return; + } /* Find the number of facets */ j = 0;