From d3083e2eaddbaebffe3abf2386c396f1ff1a3bcc Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 23 Jan 2009 15:30:43 +0100 Subject: [PATCH] fix parsing of s commands for MBCS codes including \x5c 2009-01-23 Paolo Bonzini Hideo AOKI * sed/compile.c (match_slash): Fix MBCS behavior. * sed/sed.h (MBSINIT): New. --- ChangeLog | 6 ++++++ autoboot.conf | 2 +- sed/compile.c | 9 +++------ sed/sed.h | 4 ++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c08b75..83bc080 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-01-23 Paolo Bonzini + Hideo AOKI + + * sed/compile.c (match_slash): Fix MBCS behavior. + * sed/sed.h (MBSINIT): New. + 2009-01-20 Paolo Bonzini * autoboot.conf, bootstrap.sh.in: Remove memchr, memcmp, memmove diff --git a/autoboot.conf b/autoboot.conf index 074e328..43a0d3b 100644 --- a/autoboot.conf +++ b/autoboot.conf @@ -19,7 +19,7 @@ # gnulib modules used by this package. gnulib_modules=" acl alloca btowc extensions getline getopt gettext localcharset \ - mbrlen mbrtowc mkstemp obstack pathmax snprintf stdbool \ + mbrlen mbrtowc mbsinit mkstemp obstack pathmax snprintf stdbool \ stat-macros strerror strverscmp unlocked-io vasnprintf verify wcrtomb wctob" SKIP_PO=t diff --git a/sed/compile.c b/sed/compile.c index bc0416d..f5d51fd 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -535,12 +535,11 @@ match_slash(slash, regex) { struct buffer *b; int ch; - bool pending_mb = false; mbstate_t cur_stat; memset (&cur_stat, 0, sizeof (mbstate_t)); - if (BRLEN (slash, &cur_stat) == -2) + /* We allow only 1 byte characters for a slash. */ if (BRLEN (slash, &cur_stat) == -2) bad_prog (BAD_DELIM); @@ -549,10 +548,8 @@ match_slash(slash, regex) b = init_buffer(); while ((ch = inchar()) != EOF && ch != '\n') { - pending_mb = BRLEN (ch, &cur_stat) != 1; - pending_mb = BRLEN (ch, &cur_stat) != 1; - - if (!pending_mb) + bool pending_mb = !MBSINIT (&cur_stat); + if (BRLEN (ch, &cur_stat) == 1 && !pending_mb) { if (ch == slash) return b; diff --git a/sed/sed.h b/sed/sed.h index 59464b2..4b0329f 100644 --- a/sed/sed.h +++ b/sed/sed.h @@ -261,6 +261,9 @@ extern bool is_utf8; wcrtomb ((s), (wc), (ps)) #endif +#define MBSINIT(s) \ + (mb_cur_max == 1 ? 1 : mbsinit ((s))) + #define MBRLEN(s, n, ps) \ (mb_cur_max == 1 ? 1 : mbrtowc (NULL, s, n, ps)) @@ -268,6 +271,7 @@ extern bool is_utf8; (mb_cur_max == 1 ? 1 : brlen (ch, ps)) #else +#define MBSINIT(s) 1 #define MBRLEN(s, n, ps) 1 #define BRLEN(ch, ps) 1 #endif