Blob Blame History Raw
--- a/sed/execute.c	2015-12-28 07:36:47.000000000 +0100
+++ b/sed/execute.c	2019-07-30 10:37:49.369052072 +0200
@@ -213,58 +220,42 @@
   while (length)
     {
       wchar_t wc;
-      size_t n = MBRTOWC (&wc, string, length, &from_stat);
+      int n = MBRTOWC (&wc, string, length, &from_stat);
 
-      /* Treat an invalid sequence like a single-byte character.  */
-      if (n == (size_t) -1)
+      /* An invalid sequence is treated like a singlebyte character. */
+      if (n == -1)
         {
-          type &= ~(REPL_LOWERCASE_FIRST | REPL_UPPERCASE_FIRST);
-          if (type == REPL_ASIS)
-            {
-              str_append(to, string, length);
-              return;
-            }
-
-          str_append (to, string, 1);
           memset (&to->mbstate, 0, sizeof (from_stat));
           n = 1;
-          string += n, length -= n;
-          continue;
-        }
-
-      if (n == 0 || n == (size_t) -2)
-        {
-          /* L'\0' or an incomplete sequence: copy it manually.  */
-          str_append(to, string, length);
-          return;
         }
 
-      string += n, length -= n;
+      if (n > 0)
+        string += n, length -= n;
+      else
+	{
+	  /* Incomplete sequence, copy it manually.  */
+	  str_append(to, string, length);
+	  return;
+	}
 
       /* Convert the first character specially... */
       if (type & (REPL_UPPERCASE_FIRST | REPL_LOWERCASE_FIRST))
-        {
+	{
           if (type & REPL_UPPERCASE_FIRST)
             wc = towupper(wc);
           else
             wc = towlower(wc);
 
           type &= ~(REPL_LOWERCASE_FIRST | REPL_UPPERCASE_FIRST);
-          if (type == REPL_ASIS)
-            {
-              /* Copy the new wide character to the end of the string. */
-              n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
-              to->length += n;
-              if (n == (size_t) -1 || n == (size_t) -2)
-                {
-                  fprintf (stderr,
-                           _("case conversion produced an invalid character"));
-                  abort ();
-                }
-              str_append(to, string, length);
-              return;
-            }
+	  if (type == REPL_ASIS)
+	    {
+	      n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
+	      to->length += n;
+	      str_append(to, string, length);
+	      return;
+	    }
         }
+
       else if (type & REPL_UPPERCASE)
         wc = towupper(wc);
       else
@@ -274,10 +265,10 @@
       n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
       to->length += n;
       if (n == -1 || n == -2)
-        {
-          fprintf (stderr, _("case conversion produced an invalid character"));
-          abort ();
-        }
+	{
+	  fprintf (stderr, "Case conversion produced an invalid character!");
+	  abort ();
+	}
     }
 }