]> granicus.if.org Git - clang/commitdiff
Test for errors during fread() inside c-index-test and handle them
authorChandler Carruth <chandlerc@gmail.com>
Thu, 17 Dec 2009 09:18:43 +0000 (09:18 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 17 Dec 2009 09:18:43 +0000 (09:18 +0000)
appropriately. This also silences some pedantic GCC warnings.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91596 91177308-0d34-0410-b5e6-96231b3b80d8

tools/c-index-test/c-index-test.c

index 7300585a1d8836408b8a7401ad4bf4430754c913..7040a7288a118193a3ed00efca5a4bf083049363 100644 (file)
@@ -461,7 +461,15 @@ int parse_remapped_files(int argc, const char **argv, int start_arg,
     
     /* Read the contents of the file we're remapping to. */
     contents = (char *)malloc(unsaved->Length + 1);
-    fread(contents, 1, unsaved->Length, to_file);
+    if (fread(contents, 1, unsaved->Length, to_file) != unsaved->Length) {
+      fprintf(stderr, "error: unexpected %s reading 'to' file %s\n",
+              (feof(to_file) ? "EOF" : "error"), semi + 1);
+      fclose(to_file);
+      free_remapped_files(*unsaved_files, i);
+      *unsaved_files = 0;
+      *num_unsaved_files = 0;
+      return -1;
+    }
     contents[unsaved->Length] = 0;
     unsaved->Contents = contents;