[gs-cvs] rev 8435 - trunk/gs/src

giles at ghostscript.com giles at ghostscript.com
Tue Dec 11 13:27:03 PST 2007


Author: giles
Date: 2007-12-11 13:27:02 -0800 (Tue, 11 Dec 2007)
New Revision: 8435

Modified:
   trunk/gs/src/gp_unix_cache.c
Log:
Store the posix persistent cache's last modified line as an unsigned 
long to avoid portability problems when reading and writing. Bug 689604.

DETAILS:

Previously we used time_t directly, but read and wrote it to the 
filesystem using the %ld printf format specifier, which is wrong
on systems where long int and time_t are different widths. Instead
we stort it as an unsigned long int, coercing the return value of
time(). This will be a year 2038 problem on systems with 32 bit longs, 
but seems the better option for portability now. There is no cast,
so the compiler should warn if this loses precision.


Modified: trunk/gs/src/gp_unix_cache.c
===================================================================
--- trunk/gs/src/gp_unix_cache.c	2007-12-11 16:54:05 UTC (rev 8434)
+++ trunk/gs/src/gp_unix_cache.c	2007-12-11 21:27:02 UTC (rev 8435)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2006 Artifex Software, Inc.
+/* Copyright (C) 2001-2007 Artifex Software, Inc.
    All Rights Reserved.
   
    This software is provided AS-IS with no warranty, either express or
@@ -36,7 +36,7 @@
     int len;
     void *buffer;
     int dirty;
-    time_t last_used;
+    ulong last_used;	/* we assume time_t fits in here */
 } gp_cache_entry;
 
 /* initialize a new gp_cache_entry struct */
@@ -288,7 +288,7 @@
     if (line[0] == '#') return 1;
     
     /* otherwise, parse the line */
-    sscanf(line, "%s %ld\n", fn, &item->last_used);
+    sscanf(line, "%s %lu\n", fn, &item->last_used);
     /* unpack the type from the filename */
     item->type = readhexbyte(fn);
     /* unpack the md5 hash from the filename */
@@ -310,7 +310,7 @@
 static int
 gp_cache_write_entry(FILE *file, gp_cache_entry *item)
 {
-    fprintf(file, "%s %ld\n", item->filename, item->last_used);
+    fprintf(file, "%s %lu\n", item->filename, item->last_used);
     return 0;
 }
 



More information about the gs-cvs mailing list