CVS: intermezzo/utils kmlprint.c,1.7,1.8

Chen Yang <[email protected]> Wed, 25 Jun 2003 00:25:55 -0700
Newsgroups gmane.comp.file-systems.intermezzo.cvs
Message-ID <[email protected]>
Update of /cvsroot/intermezzo/intermezzo/utils
In directory sc8-pr-cvs1:/tmp/cvs-serv17925/intermezzo/utils

Modified Files:
	kmlprint.c 
Log Message:
Renaud Duhaut [[email protected]]'s patch for kmlprint.c 
Fix the segment fault problem.



Index: kmlprint.c
===================================================================
RCS file: /cvsroot/intermezzo/intermezzo/utils/kmlprint.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -U2 -r1.7 -r1.8
--- kmlprint.c	13 Feb 2002 07:36:55 -0000	1.7
+++ kmlprint.c	25 Jun 2003 07:25:53 -0000	1.8
@@ -37,5 +37,5 @@
 int main(int argc, char **argv)
 {
-        char *buf, *end, *str, *ptr, *filename;
+        char *buf, *tmpbuf,*end, *str, *ptr, *filename;
         int fd, recno, brief = 0;
 	struct stat st;
@@ -76,12 +76,20 @@
 	}
 
-	buf = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
-	if ( !buf ) { 
+	tmpbuf = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+	if ( !tmpbuf ) { 
 		perror("mmap fails");
 		exit(1);
 	}
 
+        /* Copy the KML, because kml_unpack want to write */
+        buf = g_malloc(st.st_size);
+        memcpy(buf,tmpbuf,st.st_size);
+        
+        munmap(tmpbuf,st.st_size);
+        close(fd);
+
 	ptr = buf;
 	end = buf + st.st_size;
+
 	while ( ptr < end ) { 
 		int err;



-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php