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