Fix handling of epsf file read error in psusershape.c
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sat, 7 Nov 2020 12:39:54 +0000 (13:39 +0100)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sat, 21 Nov 2020 08:04:29 +0000 (09:04 +0100)
Also removes 1 -Wunused-but-set-variable warning

lib/common/psusershape.c

index 515ffc42ef71df48ceb0b4fb45c2b341f0c1b2e1..09268647e001b4c28b4c21cc1e9624876f4ecd5c 100644 (file)
@@ -85,9 +85,17 @@ static usershape_t *user_init(const char *str)
        contents = us->data = N_GNEW(statbuf.st_size + 1, char);
        fseek(fp, 0, SEEK_SET);
        rc = fread(contents, statbuf.st_size, 1, fp);
-       contents[statbuf.st_size] = '\0';
-       dtinsert(EPSF_contents, us);
-       us->must_inline = must_inline;
+       if (rc == 1) {
+            contents[statbuf.st_size] = '\0';
+            dtinsert(EPSF_contents, us);
+            us->must_inline = must_inline;
+        }
+        else {
+            agerr(AGWARN, "couldn't read from epsf file %s\n", str);
+            free(us->data);
+            free(us);
+            us = NULL;
+        }
     } else {
        agerr(AGWARN, "BoundingBox not found in epsf file %s\n", str);
        us = NULL;