[cfe-commits] r91596 - /cfe/trunk/tools/c-index-test/c-index-test.c

Chandler Carruth chandlerc at gmail.com
Thu Dec 17 01:18:43 PST 2009


Author: chandlerc
Date: Thu Dec 17 03:18:43 2009
New Revision: 91596

URL: http://llvm.org/viewvc/llvm-project?rev=91596&view=rev
Log:
Test for errors during fread() inside c-index-test and handle them
appropriately. This also silences some pedantic GCC warnings.

Modified:
    cfe/trunk/tools/c-index-test/c-index-test.c

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=91596&r1=91595&r2=91596&view=diff

==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Dec 17 03:18:43 2009
@@ -461,7 +461,15 @@
     
     /* 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;
 





More information about the cfe-commits mailing list