Selaa lähdekoodia

Don't leave internal structures temporarily modified before calling an
application callback, so that state is sane if they call into the API
from inside the callback.

Ryan C. Gordon 20 vuotta sitten
vanhempi
commit
499631936f
2 muutettua tiedostoa jossa 23 lisäystä ja 10 poistoa
  1. 3 1
      CHANGELOG
  2. 20 9
      physfs.c

+ 3 - 1
CHANGELOG

@@ -5,7 +5,9 @@
 09182005 - API BREAKAGE: PHYSFS_enumerateFilesCallback() now passes the
 09182005 - API BREAKAGE: PHYSFS_enumerateFilesCallback() now passes the
            original directory name back to the app in the callback. This
            original directory name back to the app in the callback. This
            API was only in 1.1.0, and wasn't promised to be stable at this
            API was only in 1.1.0, and wasn't promised to be stable at this
-           point. Please update your apps.
+           point. Please update your apps! Cleaned out a FIXME in file
+           enumeration that would confuse the library under certain
+           circumstances.
 09092005 - Some tweaks to PHYSFS_Allocator. Apparently configure.in doesn't
 09092005 - Some tweaks to PHYSFS_Allocator. Apparently configure.in doesn't
            work like I thought for version bumps, so it thinks 1.1.0 isn't
            work like I thought for version bumps, so it thinks 1.1.0 isn't
            binary compatible with 1.0...fixed, I think.
            binary compatible with 1.0...fixed, I think.

+ 20 - 9
physfs.c

@@ -1545,6 +1545,25 @@ char **PHYSFS_enumerateFiles(const char *path)
 } /* PHYSFS_enumerateFiles */
 } /* PHYSFS_enumerateFiles */
 
 
 
 
+/*
+ * Broke out to seperate function so we can use alloca() gratuitously.
+ */
+static void enumerateFromMountPoint(DirHandle *i, const char *arcfname,
+                                    PHYSFS_EnumFilesCallback callback,
+                                    const char *_fname, void *data)
+{
+    size_t len = strlen(arcfname);
+    char *mountPoint = (char *) alloca(strlen(i->mountPoint) + 1);
+    strcpy(mountPoint, i->mountPoint);
+    char *ptr = mountPoint + ((len) ? len + 1 : 0);
+    char *end = strchr(ptr, '/');
+    assert(end);  /* should always find a terminating '/'. */
+    *end = '\0';
+    callback(data, _fname, ptr);
+} /* enumerateFromMountPoint */
+
+
+
 void PHYSFS_enumerateFilesCallback(const char *_fname,
 void PHYSFS_enumerateFilesCallback(const char *_fname,
                                    PHYSFS_EnumFilesCallback callback,
                                    PHYSFS_EnumFilesCallback callback,
                                    void *data)
                                    void *data)
@@ -1564,15 +1583,7 @@ void PHYSFS_enumerateFilesCallback(const char *_fname,
     {
     {
         char *arcfname = fname;
         char *arcfname = fname;
         if (partOfMountPoint(i, arcfname))
         if (partOfMountPoint(i, arcfname))
-        {
-            size_t len = strlen(arcfname);
-            char *ptr = i->mountPoint + ((len) ? len + 1 : 0);
-            char *end = strchr(ptr, '/');
-            assert(end);  /* should always find a terminating '/'. */
-            *end = '\0';  /* !!! FIXME: not safe in a callback... */
-            callback(data, _fname, ptr);
-            *end = '/';   /* !!! FIXME: not safe in a callback... */
-        } /* if */
+            enumerateFromMountPoint(i, arcfname, callback, _fname, data);
 
 
         else if (verifyPath(i, &arcfname, 0))
         else if (verifyPath(i, &arcfname, 0))
         {
         {