From 7b51537be2341b62795c308c140faca387fa04e6 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 16 Aug 2010 16:01:31 +0000 Subject: Common: Fix bug in lastPathComponent. Prior to this change lastPathComponent would not create a correct result, when the input of lastPathComponent did not contain a single separator. I also added a test case for this in our unit tests. svn-id: r52123 --- common/str.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/str.cpp') diff --git a/common/str.cpp b/common/str.cpp index 744ba46ec7..2a0130dbe4 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -626,7 +626,7 @@ Common::String lastPathComponent(const Common::String &path, const char sep) { // Now scan the whole component const char *first = last - 1; - while (first >= str && *first != sep) + while (first > str && *first != sep) --first; if (*first == sep) -- cgit v1.2.3 From 7dfd8f9ce25ec16255f298127319a3888daa6d60 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 17 Aug 2010 12:47:18 +0000 Subject: COMMON: Remove redundant include from str.cpp If it is needed for your specific platform, then readd it, but for that platform. Although to me it looks all redundant. svn-id: r52155 --- common/str.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'common/str.cpp') diff --git a/common/str.cpp b/common/str.cpp index 2a0130dbe4..cc8e236f4b 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -30,11 +30,6 @@ #include -#if !defined(__SYMBIAN32__) -#include -#endif - - namespace Common { MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now -- cgit v1.2.3 From b480f0f2f093e5606501cca455a77735693ce07e Mon Sep 17 00:00:00 2001 From: Florian Kagerer Date: Tue, 17 Aug 2010 20:58:01 +0000 Subject: COMMON: fix MSVC assert when using umlauts (or other characters > 127) in the global save/load menu svn-id: r52173 --- common/str.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/str.cpp') diff --git a/common/str.cpp b/common/str.cpp index cc8e236f4b..2961a0c61b 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -416,7 +416,7 @@ void String::trim() { // Trim leading whitespace char *t = _str; - while (isspace(*t)) + while (isspace((unsigned char)*t)) t++; if (t != _str) { -- cgit v1.2.3 From 532663c742150b341de22a65da4fd761da6f497a Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 7 Sep 2010 11:40:44 +0000 Subject: COMMON: Fix edge case for wildcard in matchString svn-id: r52618 --- common/str.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'common/str.cpp') diff --git a/common/str.cpp b/common/str.cpp index 2961a0c61b..4585905d62 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -691,9 +691,18 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod switch (*pat) { case '*': - // Record pattern / string position for backtracking - p = ++pat; - q = str; + if (*str) { + // Record pattern / string position for backtracking + p = ++pat; + q = str; + } else { + // If we've reached the end of str, we can't backtrack further + // NB: We can't simply check if pat also ended here, because + // the pattern might end with any number of *s. + ++pat; + p = 0; + q = 0; + } // If pattern ended with * -> match if (!*pat) return true; -- cgit v1.2.3 From 426d6749cf534dec673e958f98711ac64a04f9a6 Mon Sep 17 00:00:00 2001 From: Joost Peters Date: Sun, 10 Oct 2010 22:36:03 +0000 Subject: COMMON: work around different vsnprintf behaviour on IRIX The return value of vsnprintf when the provided buffer is not large enough to hold the formatted string is implementation-dependent: C99: The size the formatted string would take up. MSVC: -1, with no indication of how large the buffer should be. IRIX: The number of characters actually written, which is at most the size of the buffer minus one, as the string is truncated to fit. This means the only way to be sure the entire string is written is if the return value is less than the capacity - 1. This change means that whenever we try to format a string where the size is 1 below the built-in capacity, that the capacity will be needlessly increased. If this turns out to be problematic we could make this behaviour __sgi conditional. svn-id: r53143 --- common/str.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'common/str.cpp') diff --git a/common/str.cpp b/common/str.cpp index 4585905d62..c3c19adfe6 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -439,12 +439,20 @@ String String::printf(const char *fmt, ...) { int len = vsnprintf(output._str, _builtinCapacity, fmt, va); va_end(va); - if (len == -1) { - // MSVC doesn't return the size the full string would take up. - // Try increasing the size of the string until it fits. + if (len == -1 || len == _builtinCapacity - 1) { + // MSVC and IRIX don't return the size the full string would take up. + // MSVC returns -1, IRIX returns the number of characters actually written, + // which is at the most the size of the buffer minus one, as the string is + // truncated to fit. // We assume MSVC failed to output the correct, null-terminated string // if the return value is either -1 or size. + // For IRIX, because we lack a better mechanism, we assume failure + // if the return value equals size - 1. + // The downside to this is that whenever we try to format a string where the + // size is 1 below the built-in capacity, the size is needlessly increased. + + // Try increasing the size of the string until it fits. int size = _builtinCapacity; do { size *= 2; @@ -455,7 +463,7 @@ String String::printf(const char *fmt, ...) { va_start(va, fmt); len = vsnprintf(output._str, size, fmt, va); va_end(va); - } while (len == -1 || len >= size); + } while (len == -1 || len >= size - 1); output._size = len; } else if (len < (int)_builtinCapacity) { // vsnprintf succeeded -- cgit v1.2.3