Ver Fonte

prevent crash on some glob.h versions

David Rose há 21 anos atrás
pai
commit
08ea68e8ab
1 ficheiros alterados com 15 adições e 4 exclusões
  1. 15 4
      dtool/src/dtoolutil/filename.cxx

+ 15 - 4
dtool/src/dtoolutil/filename.cxx

@@ -1210,12 +1210,23 @@ scan_directory(vector_string &contents) const {
   glob_t globbuf;
 
   int r = glob(dirname.c_str(), GLOB_ERR, NULL, &globbuf);
+
+  if (r != 0) {
+    // Some error processing the match string.  If our version of
+    // glob.h defines GLOB_NOMATCH, then we can differentiate an empty
+    // return result from some other kind of error.
 #ifdef GLOB_NOMATCH
-  if (r != 0 && r != GLOB_NOMATCH) {
-    perror(dirname.c_str());
-    return false;
-  }
+    if (r != GLOB_NOMATCH) {
+      perror(dirname.c_str());
+      return false;
+    }
 #endif
+
+    // Otherwise, all errors mean the same thing: no matches, but
+    // otherwise no problem.
+    return true;
+  }
+
   size_t offset = dirname.size() - 1;
 
   for (int i = 0; globbuf.gl_pathv[i] != NULL; i++) {