summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/skel/crossplatform.cpp49
-rw-r--r--src/text/Messages.cpp7
2 files changed, 29 insertions, 27 deletions
diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp
index ac4bbe85..e9320c05 100644
--- a/src/skel/crossplatform.cpp
+++ b/src/skel/crossplatform.cpp
@@ -26,34 +26,39 @@ void GetLocalTime_CP(SYSTEMTIME *out) {
// Compatible with Linux/POSIX and MinGW on Windows
#ifndef _WIN32
HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) {
- char newpathname[32];
-
- strncpy(newpathname, pathname, 32);
- char* path = strtok(newpathname, "*");
-
+ char pathCopy[32];
+
+ strncpy(pathCopy, pathname, 32);
+ char* folder = strtok(pathCopy, "*");
+
// Case-sensitivity and backslashes...
- char *real = casepath(path);
- if (real) {
- real[strlen(real)] = '*';
- char *extension = strtok(NULL, "*");
- if (extension)
- strcat(real, extension);
-
- strncpy(newpathname, real, 32);
- free(real);
- path = strtok(newpathname, "*");
+ char *realFolder = casepath(folder);
+ char *extension = nil;
+ if (realFolder) {
+ realFolder[strlen(realFolder)] = '*';
+ extension = strtok(NULL, "*");
+ if (extension) {
+ strcat(realFolder, extension);
+ }
+
+ strncpy(pathCopy, realFolder, 32);
+ free(realFolder);
+ folder = strtok(pathCopy, "*");
+ } else {
+ // Wildcard (*)
+ if (strlen(folder) + 1 != strlen(pathname))
+ extension = strtok(NULL, "*");
}
-
- strncpy(firstfile->folder, path, sizeof(firstfile->folder));
- // Both w/ extension and w/o extension is ok
- if (strlen(path) + 1 != strlen(pathname))
- strncpy(firstfile->extension, strtok(NULL, "*"), sizeof(firstfile->extension));
+ strncpy(firstfile->folder, folder, sizeof(firstfile->folder));
+
+ if (extension)
+ strncpy(firstfile->extension, extension, sizeof(firstfile->extension));
else
- strncpy(firstfile->extension, "", sizeof(firstfile->extension));
+ firstfile->extension[0] = '\0';
HANDLE d;
- if ((d = (HANDLE)opendir(path)) == NULL || !FindNextFile(d, firstfile))
+ if ((d = (HANDLE)opendir(folder)) == NULL || !FindNextFile(d, firstfile))
return NULL;
return d;
diff --git a/src/text/Messages.cpp b/src/text/Messages.cpp
index 70225860..257a47ce 100644
--- a/src/text/Messages.cpp
+++ b/src/text/Messages.cpp
@@ -71,10 +71,7 @@ CMessages::WideStringCompare(wchar *str1, wchar *str2, uint16 size)
if (len1 != len2 && (len1 < size || len2 < size))
return false;
- for (int32 i = 0; i < size; i++) {
- if (FixupChar(str1[i]) == '\0' || i > size)
- break;
-
+ for (int32 i = 0; FixupChar(str1[i]) != '\0' && i < size; i++) {
if (FixupChar(str1[i]) != FixupChar(str2[i]))
return false;
}
@@ -393,7 +390,7 @@ CMessages::InsertNumberInString(wchar *str, int32 n1, int32 n2, int32 n3, int32
if (str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~') {
#endif
c += 3;
- for (int j=0; j<outLen; j++)
+ for (int j = 0; j < outLen; j++)
*(outstr++) = wNumStr[j++];
i++;