Index: /trunk/include/iprt/cpp/ministring.h
===================================================================
--- /trunk/include/iprt/cpp/ministring.h	(revision 33804)
+++ /trunk/include/iprt/cpp/ministring.h	(revision 33805)
@@ -76,11 +76,11 @@
      * This allocates s.length() + 1 bytes for the new instance, unless s is empty.
      *
-     * @param   s               The source string.
+     * @param   a_rSrc          The source string.
      *
      * @throws  std::bad_alloc
      */
-    MiniString(const MiniString &s)
-    {
-        copyFrom(s);
+    MiniString(const MiniString &a_rSrc)
+    {
+        copyFromN(a_rSrc.m_psz, a_rSrc.m_cch);
     }
 
@@ -96,5 +96,32 @@
     MiniString(const char *pcsz)
     {
-        copyFrom(pcsz);
+        copyFromN(pcsz, strlen(pcsz));
+    }
+
+    /**
+     * Create a partial copy of another MiniString.
+     *
+     * @param   a_cchSrc        The max number of chars (encoded UTF-8 bytes)
+     *                          to copy from the source string.
+     * @param   a_rSrc          The source string.
+     */
+    MiniString(size_t a_cchSrc, const MiniString &a_rSrc)
+    {
+        Assert(a_cchSrc <= a_rSrc.m_cch);
+        copyFromN(a_rSrc.m_psz, RT_MIN(a_cchSrc, a_rSrc.m_cch));
+    }
+
+    /**
+     * Create a partial copy of a C string.
+     *
+     * @param   a_cchSrc        The max number of chars (encoded UTF-8 bytes)
+     *                          to copy from the source string.
+     * @param   a_pszSrc        The source string (UTF-8).
+     */
+    MiniString(size_t a_cchSrc, const char *a_pszSrc)
+    {
+        size_t cchMax = a_pszSrc ? RTStrNLen(a_pszSrc, a_cchSrc) : 0;
+        Assert(a_cchSrc <= cchMax);
+        copyFromN(a_pszSrc, RT_MIN(a_cchSrc, cchMax));
     }
 
@@ -204,5 +231,5 @@
         {
             cleanup();
-            copyFrom(pcsz);
+            copyFromN(pcsz, pcsz ? strlen(pcsz) : 0);
         }
         return *this;
@@ -224,5 +251,5 @@
         {
             cleanup();
-            copyFrom(s);
+            copyFromN(s.m_psz, s.m_cch);
         }
         return *this;
@@ -731,28 +758,31 @@
 
     /**
-     * Protected internal helper to copy a string. This ignores the previous object
-     * state, so either call this from a constructor or call cleanup() first.
-     *
-     * copyFrom() unconditionally sets the members to a copy of the given other
-     * strings and makes no assumptions about previous contents. Can therefore be
-     * used both in copy constructors, when member variables have no defined value,
-     * and in assignments after having called cleanup().
-     *
-     * This variant copies from another MiniString and is fast since
-     * the length of the source string is known.
-     *
-     * @param   s               The source string.
-     *
-     * @throws  std::bad_alloc  On allocation failure. The object is left describing
-     *             a NULL string.
-     */
-    void copyFrom(const MiniString &s)
-    {
-        if ((m_cch = s.m_cch))
-        {
-            m_cbAllocated = m_cch + 1;
-            m_psz = (char *)RTStrAlloc(m_cbAllocated);
+     * Protected internal helper to copy a string.
+     *
+     * This ignores the previous object state, so either call this from a
+     * constructor or call cleanup() first.  copyFromN() unconditionally sets
+     * the members to a copy of the given other strings and makes no
+     * assumptions about previous contents.  Can therefore be used both in copy
+     * constructors, when member variables have no defined value, and in
+     * assignments after having called cleanup().
+     *
+     * @param   pcszSrc         The source string.
+     * @param   cchSrc          The number of chars (bytes) to copy from the
+     *                          source strings.
+     *
+     * @throws  std::bad_alloc  On allocation failure.  The object is left
+     *                          describing a NULL string.
+     */
+    void copyFromN(const char *pcszSrc, size_t cchSrc)
+    {
+        if (cchSrc)
+        {
+            m_psz = RTStrAlloc(cchSrc + 1);
             if (RT_LIKELY(m_psz))
-                memcpy(m_psz, s.m_psz, m_cbAllocated);      // include 0 terminator
+            {
+                m_cch = cchSrc;
+                m_cbAllocated = cchSrc + 1;
+                memcpy(m_psz, pcszSrc, cchSrc + 1);
+            }
             else
             {
@@ -766,43 +796,4 @@
         else
         {
-            m_cbAllocated = 0;
-            m_psz = NULL;
-        }
-    }
-
-    /**
-     * Protected internal helper to copy a string. This ignores the previous object
-     * state, so either call this from a constructor or call cleanup() first.
-     *
-     * See copyFrom() above.
-     *
-     * This variant copies from a C string and needs to call strlen()
-     * on it. It's therefore slower than the one above.
-     *
-     * @param   pcsz            The source string.
-     *
-     * @throws  std::bad_alloc  On allocation failure. The object is left describing
-     *             a NULL string.
-     */
-    void copyFrom(const char *pcsz)
-    {
-        if (pcsz && *pcsz)
-        {
-            m_cch = strlen(pcsz);
-            m_cbAllocated = m_cch + 1;
-            m_psz = (char *)RTStrAlloc(m_cbAllocated);
-            if (RT_LIKELY(m_psz))
-                memcpy(m_psz, pcsz, m_cbAllocated);     // include 0 terminator
-            else
-            {
-                m_cch = 0;
-                m_cbAllocated = 0;
-#ifdef RT_EXCEPTIONS_ENABLED
-                throw std::bad_alloc();
-#endif
-            }
-        }
-        else
-        {
             m_cch = 0;
             m_cbAllocated = 0;
Index: /trunk/src/VBox/Main/glue/string.cpp
===================================================================
--- /trunk/src/VBox/Main/glue/string.cpp	(revision 33804)
+++ /trunk/src/VBox/Main/glue/string.cpp	(revision 33805)
@@ -74,8 +74,13 @@
     if (length())
     {
-        char *pcszFilename = ::RTStrDup(::RTPathFilename(m_psz));
-        cleanup();
-        MiniString::copyFrom(pcszFilename);
-        RTStrFree(pcszFilename);
+        char *pszName = ::RTPathFilename(m_psz);
+        if (pszName)
+        {
+            size_t cchName = length() - (pszName - m_psz);
+            memmove(m_psz, pszName, cchName + 1);
+            jolt();
+        }
+        else
+            cleanup();
     }
     return *this;
