]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/ctrlcmn.cpp
Fix out of bounds string access in wxMSW wxDirDialog.
[wxWidgets.git] / src / common / ctrlcmn.cpp
old mode 100755 (executable)
new mode 100644 (file)
index ce76a88..fc41159
@@ -402,6 +402,11 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD
                 calc.Init(0, 1);
                 while ( !calc.IsShortEnough() )
                     calc.RemoveFromEnd();
                 calc.Init(0, 1);
                 while ( !calc.IsShortEnough() )
                     calc.RemoveFromEnd();
+
+                // always show at least one character of the string:
+                if ( calc.m_nCharsToRemove == len )
+                    return wxString(wxELLIPSE_REPLACEMENT) + curLine[len-1];
+
                 break;
             }
 
                 break;
             }
 
@@ -444,6 +449,15 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD
                     else
                         calc.RemoveFromEnd();
                 }
                     else
                         calc.RemoveFromEnd();
                 }
+
+                // Always show at least one character of the string.
+                // Additionally, if there's only one character left, prefer
+                // "a..." to "...a":
+                if ( calc.m_nCharsToRemove == len ||
+                     calc.m_nCharsToRemove == len - 1 )
+                {
+                    return curLine[0] + wxString(wxELLIPSE_REPLACEMENT);
+                }
             }
             break;
 
             }
             break;
 
@@ -452,6 +466,11 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD
                 calc.Init(len - 1, 1);
                 while ( !calc.IsShortEnough() )
                     calc.RemoveFromStart();
                 calc.Init(len - 1, 1);
                 while ( !calc.IsShortEnough() )
                     calc.RemoveFromStart();
+
+                // always show at least one character of the string:
+                if ( calc.m_nCharsToRemove == len )
+                    return curLine[0] + wxString(wxELLIPSE_REPLACEMENT);
+
                 break;
             }
 
                 break;
             }