From: David Lawrence Ramsey Date: Mon, 13 Jun 2005 14:50:32 +0000 (+0000) Subject: don't work around invalid multibyte sequences in rcfile options anymore, X-Git-Tag: v1.3.8~153 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=30d0a816560100c46aabe78fbed959c94f2e11f7;p=nano.git don't work around invalid multibyte sequences in rcfile options anymore, but generate errors git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2650 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index dc8cb0ef..71ece1b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -58,12 +58,14 @@ CVS code - wrappers; change other ctype wrappers to take wint_t instead of wchar_t; rename some functions for consistency; and don't count matches between valid and invalid multibyte sequences - anymore, as it causes problems when doing a replace. Changes - to is_alnum_mbchar(), is_blank_char() (renamed nisblank()), - is_blank_mbchar(), is_blank_wchar() (renamed niswblank()), - is_cntrl_wchar(), control_rep(), control_mbrep(), - mbstrncasecmp(), mbstrcasestr(), mbrevstrcasestr(), etc.; - removal of is_alnum_char() and is_alnum_wchar(). (DLR) + anymore, as it causes problems when doing a replace. New + function is_valid_mbstring(); changes to is_alnum_mbchar(), + is_blank_char() (renamed nisblank()), is_blank_mbchar(), + is_blank_wchar() (renamed niswblank()), is_cntrl_wchar(), + control_rep(), control_mbrep(), make_mbstring() (renamed + make_valid_mbstring()), mbstrncasecmp(), mbstrcasestr(), + mbrevstrcasestr(), etc.; removal of is_alnum_char() and + is_alnum_wchar(). (DLR) - Implement word count via Meta-D at the main window. Note that this is disabled when NANO_SMALL is defined. New functions do_word_count() and do_next_word_void(); changes to @@ -177,6 +179,9 @@ CVS code - (DLR) - Properly generate an error if we get a color directive without a regex string. (DLR) + parse_rcfile() + - Properly generate an error if we get an invalid multibyte + string for an option, instead of working around it. (DLR) - search.c: do_gotoline() - Properly show an error message if we try to go to line 0, diff --git a/src/chars.c b/src/chars.c index 74f534f1..bd2f0d57 100644 --- a/src/chars.c +++ b/src/chars.c @@ -278,24 +278,50 @@ char *make_mbchar(int chr, int *chr_mb_len) return chr_mb; } -#if defined(ENABLE_NANORC) || defined(NANO_EXTRA) +#ifdef ENABLE_NANORC +/* Check if the string str is a valid multibyte string. Return TRUE if + * it is, and FALSE otherwise. */ +bool is_valid_mbstring(const char *str) +{ + assert(str != NULL); + +#ifdef NANO_WIDE + if (!ISSET(NO_UTF8)) { + while (*str != '\0') { + int chr_mb_len; + bool bad_chr; + + chr_mb_len = parse_mbchar(str, NULL, &bad_chr, NULL); + + if (bad_chr) + return FALSE; + + str += chr_mb_len; + } + } +#endif + + return TRUE; +} +#endif /* ENABLE_NANORC */ + +#ifdef NANO_EXTRA /* Convert the string str to a valid multibyte string with the same wide * character values as str. Return the (dynamically allocated) * multibyte string. */ -char *make_mbstring(const char *str) +char *make_valid_mbstring(const char *str) { assert(str != NULL); #ifdef NANO_WIDE if (!ISSET(NO_UTF8)) { char *chr_mb = charalloc(MB_CUR_MAX); - int chr_mb_len; char *str_mb = charalloc((MB_CUR_MAX * strlen(str)) + 1); size_t str_mb_len = 0; while (*str != '\0') { + int chr_mb_len, i; bool bad_chr; - int i; chr_mb_len = parse_mbchar(str, chr_mb, &bad_chr, NULL); @@ -328,7 +354,7 @@ char *make_mbstring(const char *str) #endif return mallocstrcpy(NULL, str); } -#endif /* ENABLE_NANORC || NANO_EXTRA */ +#endif /* NANO_EXTRA */ /* Parse a multibyte character from buf. Return the number of bytes * used. If chr isn't NULL, store the multibyte character in it. If diff --git a/src/proto.h b/src/proto.h index 38d186cc..a5b4c5fd 100644 --- a/src/proto.h +++ b/src/proto.h @@ -181,8 +181,11 @@ char *control_mbrep(const char *c, char *crep, int *crep_len); int mbwidth(const char *c); int mb_cur_max(void); char *make_mbchar(int chr, int *chr_mb_len); -#if defined(ENABLE_NANORC) || defined(NANO_EXTRA) -char *make_mbstring(const char *str); +#ifdef ENABLE_NANORC +bool is_valid_mbstring(const char *str); +#endif +#ifdef NANO_EXTRA +char *make_valid_mbstring(const char *str); #endif int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t *col); diff --git a/src/rcfile.c b/src/rcfile.c index 1d572d97..de855b64 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -568,12 +568,19 @@ void parse_rcfile(FILE *rcstream) option++; ptr = parse_argument(ptr); - /* Make sure option is a valid multibyte - * string. */ - option = make_mbstring(option); + option = mallocstrcpy(NULL, option); #ifdef DEBUG fprintf(stderr, "option = \"%s\"\n", option); #endif + + /* Make sure option is a valid multibyte + * string. */ + if (!is_valid_mbstring(option)) { + rcfile_error( + N_("Option is not a valid multibyte string")); + break; + } + #ifndef DISABLE_OPERATINGDIR if (strcasecmp(rcopts[i].name, "operatingdir") == 0) operating_dir = option; @@ -593,7 +600,8 @@ void parse_rcfile(FILE *rcstream) #ifndef NANO_SMALL if (strcasecmp(rcopts[i].name, "whitespace") == 0) { whitespace = option; - if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) { + if (mbstrlen(whitespace) != 2 || + strlenpt(whitespace) != 2) { rcfile_error( N_("Two single-column characters required")); free(whitespace); diff --git a/src/winio.c b/src/winio.c index 83a4632d..c7e39726 100644 --- a/src/winio.c +++ b/src/winio.c @@ -4119,7 +4119,7 @@ void do_credits(void) what = mallocstrcpy(NULL, _(xlcredits[xlpos])); xlpos++; } else - what = make_mbstring(credits[crpos]); + what = make_valid_mbstring(credits[crpos]); start_x = COLS / 2 - strlenpt(what) / 2 - 1; mvwaddstr(edit, editwinrows - 1 - (editwinrows % 2),