summaryrefslogtreecommitdiff
path: root/lib/sh/casemod.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sh/casemod.c')
-rw-r--r--lib/sh/casemod.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/sh/casemod.c b/lib/sh/casemod.c
index 5edc08aa..bbcffa6f 100644
--- a/lib/sh/casemod.c
+++ b/lib/sh/casemod.c
@@ -39,6 +39,7 @@
#include <shmbchar.h>
#include <shmbutil.h>
#include <chartypes.h>
+#include <typemax.h>
#include <glob/strmatch.h>
@@ -68,6 +69,10 @@
extern char *substring __P((char *, int, int));
+#ifndef UCHAR_MAX
+# define UCHAR_MAX TYPE_MAXIMUM(unsigned char)
+#endif
+
#if defined (HANDLE_MULTIBYTE)
static wchar_t
cval (s, i)
@@ -141,8 +146,10 @@ sh_modcase (string, pat, flags)
if (iswalnum (wc) == 0)
{
inword = 0;
+#if 0
ADVANCE_CHAR (ret, end, start);
continue;
+#endif
}
if (pat)
@@ -203,8 +210,11 @@ sh_modcase (string, pat, flags)
else
nop = flags;
- if (MB_CUR_MAX == 1 || is_basic ((int)wc))
+ /* Need to check UCHAR_MAX since wc may have already been converted to a
+ wide character by cval() */
+ if (MB_CUR_MAX == 1 || (wc <= UCHAR_MAX && is_basic ((int)wc)))
{
+singlebyte:
switch (nop)
{
default:
@@ -221,7 +231,10 @@ sh_modcase (string, pat, flags)
{
m = mbrtowc (&wc, string + start, end - start, &state);
if (MB_INVALIDCH (m))
- wc = (wchar_t)string[start];
+ {
+ wc = (unsigned char)string[start];
+ goto singlebyte;
+ }
else if (MB_NULLWCH (m))
wc = L'\0';
switch (nop)