//
 // ATTN: you can _not_ use both of these in the same program!
 
+#include <iostream>
+
 wxSTD istream& operator>>(wxSTD istream& is, wxString& WXUNUSED(str))
 {
 #if 0
   #define STATISTICS_ADD(av, val)
 #endif // WXSTRING_STATISTICS
 
+#if !wxUSE_STL
+
 // ===========================================================================
 // wxStringData class deallocation
 // ===========================================================================
 }
 #endif
 
-#if !wxUSE_STL
-
 // ===========================================================================
 // wxStringBase
 // ===========================================================================
             {
                 return cursor - c_str();
             }
-            --cursor;
-        } while ( cursor > c_str() );
+        } while ( cursor-- > c_str() );
     }
     
     return npos;
             buf[size] = _T('\0');
         }
 
-        if ( len >= 0 )
+        // vsnprintf() may return either -1 (traditional Unix behaviour) or the
+        // total number of characters which would have been written if the
+        // buffer were large enough
+        if ( len >= 0 && len <= size )
         {
             // ok, there was enough space
             break;
 
 #endif // !wxUSE_STL
 
-int wxStringSortAscending(wxString* s1, wxString* s2)
+int wxCMPFUNC_CONV wxStringSortAscending(wxString* s1, wxString* s2)
 {
     return wxStrcmp(s1->c_str(), s2->c_str());
 }
 
-int wxStringSortDescending(wxString* s1, wxString* s2)
+int wxCMPFUNC_CONV wxStringSortDescending(wxString* s1, wxString* s2)
 {
     return -wxStrcmp(s1->c_str(), s2->c_str());
 }