[Expat-checkins] expat/xmlwf unixfilemap.c, 1.8, 1.9 readfilemap.c, 1.11, 1.12
Karl Waclawek
kwaclaw at users.sourceforge.net
Wed Jun 28 04:55:53 CEST 2006
Update of /cvsroot/expat/expat/xmlwf
In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv5756
Modified Files:
unixfilemap.c readfilemap.c
Log Message:
Fix for bug #1513566: filemap() in readfilemap.c doesn't handle zero length
files, and the same issue applies to filemap() in unixfilemap.c
Index: unixfilemap.c
===================================================================
RCS file: /cvsroot/expat/expat/xmlwf/unixfilemap.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- unixfilemap.c 1 Jul 2002 15:13:01 -0000 1.8
+++ unixfilemap.c 28 Jun 2006 02:55:51 -0000 1.9
@@ -44,6 +44,13 @@
}
nbytes = sb.st_size;
+ /* mmap fails for zero length files */
+ if (nbytes == 0) {
+ static const char c = '\0';
+ processor(&c, 0, name, arg);
+ close(fd);
+ return 1;
+ }
p = (void *)mmap((caddr_t)0, (size_t)nbytes, PROT_READ,
MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
if (p == (void *)-1) {
Index: readfilemap.c
===================================================================
RCS file: /cvsroot/expat/expat/xmlwf/readfilemap.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- readfilemap.c 30 Apr 2004 03:44:34 -0000 1.11
+++ readfilemap.c 28 Jun 2006 02:55:51 -0000 1.12
@@ -57,9 +57,17 @@
return 0;
}
nbytes = sb.st_size;
+ /* malloc will return NULL with nbytes == 0, handle files with size 0 */
+ if (nbytes == 0) {
+ static const char c = '\0';
+ processor(&c, 0, name, arg);
+ close(fd);
+ return 1;
+ }
p = malloc(nbytes);
if (!p) {
fprintf(stderr, "%s: out of memory\n", name);
+ close(fd);
return 0;
}
n = read(fd, p, nbytes);
More information about the Expat-checkins
mailing list