From f2c01c2ab9d2ff43bee6b2be1cc1d46123d89063 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sun, 23 Feb 2014 00:59:39 +0000 Subject: [PATCH] [BUG_FIXED] (Author: visimulator) Fix sorting path in Windows document dialog makes Notepad++ crash. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1188 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../src/WinControls/WindowsDlg/WindowsDlg.cpp | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp index 49829bb90..411b035e1 100644 --- a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp @@ -85,30 +85,39 @@ struct NumericStringEquivalence static int numstrcmp(const TCHAR *str1, const TCHAR *str2) { TCHAR *p1, *p2; - int c1, c2, lcmp; + int c1, c2, lcmp = 0; for(;;) { - c1 = tolower(*str1), c2 = tolower(*str2); - if ( c1 == 0 || c2 == 0 ) + if (*str1 == 0 || *str2 == 0) { + if (*str1 != *str2) + lcmp = *str1 - *str2; break; - else if (isdigit(c1) && isdigit(c2)) + } + if (_istdigit(*str1) && _istdigit(*str2)) { lcmp = generic_strtol(str1, &p1, 10) - generic_strtol(str2, &p2, 10); if ( lcmp == 0 ) lcmp = (p2 - str2) - (p1 - str1); if ( lcmp != 0 ) - return (lcmp > 0 ? 1 : -1); + break; str1 = p1, str2 = p2; } - else + else { + if (_istascii(*str1) && _istupper(*str1)) + c1 = _totlower(*str1); + else + c1 = *str1; + if (_istascii(*str2) && _istupper(*str2)) + c2 = _totlower(*str2); + else + c2 = *str2; lcmp = (c1 - c2); if (lcmp != 0) - return (lcmp > 0 ? 1 : -1); + break; ++str1, ++str2; } } - lcmp = (c1 - c2); return ( lcmp < 0 ) ? -1 : (lcmp > 0 ? 1 : 0); } };