summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-05-10 09:49:02 +0000
committerrubidium <rubidium@openttd.org>2010-05-10 09:49:02 +0000
commit08919d2747b1f6fc9ed702a67a83a3c5867a1188 (patch)
tree4f4eeea94ffa0101bf4973b195f646b13c944c58 /src
parent369dedca896fedf4cc73967f54610a5d96d7e5e6 (diff)
downloadopenttd-08919d2747b1f6fc9ed702a67a83a3c5867a1188.tar.xz
(svn r19779) -Change: add a return type to AppendPathSeparator and use that to determine whether we could append the path separator. If not, do not recurse into that directory as the path would exceed the maximum path length
Diffstat (limited to 'src')
-rw-r--r--src/fileio.cpp13
-rw-r--r--src/fileio_func.h2
2 files changed, 10 insertions, 5 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 9ffa10777..dcaa8309e 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -448,16 +448,21 @@ void FioCreateDirectory(const char *name)
* It does not add the path separator to zero-sized strings.
* @param buf string to append the separator to
* @param buflen the length of the buf
+ * @return true iff the operation succeeded
*/
-void AppendPathSeparator(char *buf, size_t buflen)
+bool AppendPathSeparator(char *buf, size_t buflen)
{
size_t s = strlen(buf);
/* Length of string + path separator + '\0' */
- if (s != 0 && buf[s - 1] != PATHSEPCHAR && s + 2 < buflen) {
+ if (s != 0 && buf[s - 1] != PATHSEPCHAR) {
+ if (s + 2 >= buflen) return false;
+
buf[s] = PATHSEPCHAR;
buf[s + 1] = '\0';
}
+
+ return true;
}
/**
@@ -1109,7 +1114,7 @@ static uint ScanPath(FileScanner *fs, const char *extension, const char *path, s
/* Directory */
if (!recursive) continue;
if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue;
- AppendPathSeparator(filename, lengthof(filename));
+ if (!AppendPathSeparator(filename, lengthof(filename))) continue;
num += ScanPath(fs, extension, filename, basepath_length, recursive);
} else if (S_ISREG(sb.st_mode)) {
/* File */
@@ -1196,6 +1201,6 @@ uint FileScanner::Scan(const char *extension, const char *directory, bool recurs
{
char path[MAX_PATH];
strecpy(path, directory, lastof(path));
- AppendPathSeparator(path, lengthof(path));
+ if (!AppendPathSeparator(path, lengthof(path))) return 0;
return ScanPath(this, extension, path, strlen(path), recursive);
}
diff --git a/src/fileio_func.h b/src/fileio_func.h
index 05253b432..e4137267c 100644
--- a/src/fileio_func.h
+++ b/src/fileio_func.h
@@ -57,7 +57,7 @@ char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory s
char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);
void SanitizeFilename(char *filename);
-void AppendPathSeparator(char *buf, size_t buflen);
+bool AppendPathSeparator(char *buf, size_t buflen);
void DeterminePaths(const char *exe);
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
bool FileExists(const char *filename);