#include <string.h>
 #include <stdlib.h>
 
-#ifdef __SALFORDC__
-    #include <clib.h>
-#endif
-
 // allocating extra space for each string consumes more memory but speeds up
 // the concatenation operations (nLen is the current string's length)
 // NB: EXTRA_ALLOC must be >= 0!
 {
   if ( last >= first )
   {
-    InitWith(first, 0, last - first);
+    InitWith(first.GetPtr(), 0, last - first);
   }
   else
   {
     wxASSERT_MSG( nStart <= lenOld,
                   _T("index out of bounds in wxStringImpl::replace") );
     size_t nEnd = nStart + nLen;
-    if ( nEnd > lenOld )
+    if ( nLen > lenOld - nStart )
     {
         // nLen may be out of range, as it can be npos, just clump it down
         nLen = lenOld - nStart;