Index: uspace/lib/cpp/include/impl/string.hpp
===================================================================
--- uspace/lib/cpp/include/impl/string.hpp	(revision d7f0b3f7505797fc40dc07d18f0dc48fa32f993a)
+++ uspace/lib/cpp/include/impl/string.hpp	(revision 2d302d60f1ff6842a33f985cf08816817ba48f50)
@@ -64,5 +64,5 @@
         /* using state_type = mbstate_t; */
 
-        static void assign(char_type& c1, char_type& c2) noexcept
+        static void assign(char_type& c1, const char_type& c2) noexcept
         {
             c1 = c2;
@@ -86,5 +86,5 @@
         static size_t length(const char_type* s)
         {
-            return std::str_size(s) + 1;
+            return std::str_size(s);
         }
 
@@ -167,5 +167,5 @@
         /* using state_type = mbstate_t; */
 
-        static void assign(char_type& c1, char_type& c2) noexcept
+        static void assign(char_type& c1, const char_type& c2) noexcept
         {
             c1 = c2;
@@ -191,5 +191,5 @@
         static size_t length(const char_type* s)
         {
-            return std::wstr_size(s) + 1;
+            return std::wstr_size(s);
         }
 
@@ -331,5 +331,5 @@
                 : data_{}, size_{}, capacity_{}, allocator_{alloc}
             {
-                init_(str, traits_type::length(str));
+                init_(str, traits_type::length(str) + 1);
             }
 
@@ -661,5 +661,5 @@
             basic_string& append(const value_type* str)
             {
-                return append(str, traits_type::length(str));
+                return append(str, traits_type::length(str) + 1);
             }
 
@@ -764,8 +764,14 @@
             basic_string& insert(size_type pos, const value_type* str, size_type n)
             {
-                ensure_free_space_(size_ + n);
+                // TODO: throw out_of_range if pos > size()
+                // TODO: throw length_error if size() + n > max_size()
+                ensure_free_space_(n);
+
                 copy_backward_(begin() + pos, end(), end() + n);
-                copy_(begin() + pos, begin() + pos + n, str);
-
+                std::printf("|%s|\n", data_);
+                copy_(str, str + n, begin() + pos);
+                size_ += n;
+
+                ensure_null_terminator_();
                 return *this;
             }
@@ -786,5 +792,8 @@
 
                 ensure_free_space_(1);
-                copy_backward_(begin() + pos, end(), end() + 1);
+                copy_backward_(begin() + idx, end(), end() + 1);
+                traits_type::assign(data_[idx], c);
+
+                ++size_;
                 ensure_null_terminator_();
 
@@ -800,9 +809,10 @@
 
                 ensure_free_space_(n);
-                copy_backward_(begin() + pos, end(), end() + n);
-
-                auto it = pos;
+                copy_backward_(begin() + idx, end(), end() + n);
+
+                auto it = begin() + idx;
                 for (size_type i = 0; i < n; ++i)
                     traits_type::assign(*it++, c);
+                size_ += n;
                 ensure_null_terminator_();
 
@@ -814,5 +824,12 @@
                             InputIterator last)
             {
-                return insert(pos - begin(), basic_string(first, last));
+                if (first == last)
+                    return const_cast<iterator>(pos);
+
+                auto idx = static_cast<size_type>(pos - begin());
+                auto str = basic_string{first, last};
+                insert(idx, str);
+
+                return begin() + idx;
             }
 
@@ -1337,21 +1354,21 @@
             }
 
-            iterator copy_(const_iterator first, const_iterator last,
-                           iterator result)
+            template<class Iterator1, class Iterator2>
+            Iterator2 copy_(Iterator1 first, Iterator1 last,
+                            Iterator2 result)
             {
                 while (first != last)
                     traits_type::assign(*result++, *first++);
 
-                ensure_null_terminator_();
                 return result;
             }
 
-            iterator copy_backward_(const_iterator first, const_iterator last,
-                                    iterator result)
-            {
-                while (last-- != first)
-                    traits_type::assign(*result--, *last);
-
-                ensure_null_terminator_();
+            template<class Iterator1, class Iterator2>
+            Iterator2 copy_backward_(Iterator1 first, Iterator1 last,
+                                     Iterator2 result)
+            {
+                while (last != first)
+                    traits_type::assign(*--result, *--last);
+
                 return result;
             }
