This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] fix for badly sized header files
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Subject: [patch] fix for badly sized header files
- From: Bruce Korb <bkorb at sco dot COM>
- Date: Tue, 05 Sep 2000 11:27:23 -0700
- Organization: The Santa Cruz Operation
If the size of a header file is a multiple of the page size,
then on some mmap implementations you will seg fault on trying
to access a trailing NUL byte even if you ask for that byte
to be mapped. :-(.
This patch uses read(2) on such poorly chosen file sizes.
2000-09-05 Bruce Korb <bkorb@gnu.org>
* gcc/fixinc/fixincl.c(load_file): always read header files
with sizes that are a multiple of the page size.
Index: fixincl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixincl.c,v
retrieving revision 1.37
diff -u -r1.37 fixincl.c
--- fixincl.c 2000/08/21 16:28:18 1.37
+++ fixincl.c 2000/09/05 18:17:08
@@ -338,6 +338,12 @@
if (stbf.st_size == 0)
return (char*)NULL;
+ /*
+ * Make the data map size one larger than the file size for documentation
+ * purposes. Truth is that there will be a following NUL character if
+ * the file size is not a multiple of the page size. If it is a multiple,
+ * then this adjustment sometimes fails anyway.
+ */
data_map_size = stbf.st_size+1;
data_map_fd = open (fname, O_RDONLY);
ttl_data_size += data_map_size-1;
@@ -352,8 +358,16 @@
#ifdef HAVE_MMAP_FILE
curr_data_mapped = BOOL_TRUE;
- res = (char*)mmap ((void*)NULL, data_map_size, PROT_READ, MAP_PRIVATE,
- data_map_fd, 0);
+
+ /*
+ * IF the file size is a multiple of the page size,
+ * THEN sometimes you will seg fault trying to access a trailing byte
+ */
+ if ((stbf.st_size & (PAGESIZE-1)) == 0)
+ res = (char*)BAD_ADDR;
+ else
+ res = (char*)mmap ((void*)NULL, data_map_size, PROT_READ,
+ MAP_PRIVATE, data_map_fd, 0);
if (res == (char*)BAD_ADDR)
{
curr_data_mapped = BOOL_FALSE;