diff --git a/ChangeLog b/ChangeLog index 311260e6..a533e01c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -90,6 +90,10 @@ CVS code - allocated, use null_at() to strip the directory from the string. Also, return the stripped path instead of modifying path. (DLR) +- chars.c: + mbstrncasecmp(), mbstrcasestr(), mbrevstrcasestr() + - Don't allocate space for multibyte characters until we've + asserted that the parameters we're using aren't NULL. (DLR) - files.c: do_insertfile() - If we execute a command in a new buffer, move back to the diff --git a/src/chars.c b/src/chars.c index 5f7c3c54..571a5283 100644 --- a/src/chars.c +++ b/src/chars.c @@ -527,12 +527,14 @@ int mbstrncasecmp(const char *s1, const char *s2, size_t n) { #ifdef ENABLE_UTF8 if (use_utf8) { - char *s1_mb = charalloc(MB_CUR_MAX); - char *s2_mb = charalloc(MB_CUR_MAX); + char *s1_mb, *s2_mb; wchar_t ws1, ws2; assert(s1 != NULL && s2 != NULL); + s1_mb = charalloc(MB_CUR_MAX); + s2_mb = charalloc(MB_CUR_MAX); + while (n > 0 && *s1 != '\0' && *s2 != '\0') { bool bad_s1_mb = FALSE, bad_s2_mb = FALSE; int s1_mb_len, s2_mb_len; @@ -620,13 +622,15 @@ const char *mbstrcasestr(const char *haystack, const char *needle) { #ifdef ENABLE_UTF8 if (use_utf8) { - char *r_mb = charalloc(MB_CUR_MAX); - char *q_mb = charalloc(MB_CUR_MAX); + char *r_mb. *q_mb; wchar_t wr, wq; bool found_needle = FALSE; assert(haystack != NULL && needle != NULL); + r_mb = charalloc(MB_CUR_MAX); + q_mb = charalloc(MB_CUR_MAX); + while (*haystack != '\0') { const char *r = haystack, *q = needle; int r_mb_len, q_mb_len; @@ -726,13 +730,15 @@ const char *mbrevstrcasestr(const char *haystack, const char *needle, { #ifdef ENABLE_UTF8 if (use_utf8) { - char *r_mb = charalloc(MB_CUR_MAX); - char *q_mb = charalloc(MB_CUR_MAX); + char *r_mb. *q_mb; wchar_t wr, wq; bool begin_line = FALSE, found_needle = FALSE; assert(haystack != NULL && needle != NULL && rev_start != NULL); + r_mb = charalloc(MB_CUR_MAX); + q_mb = charalloc(MB_CUR_MAX); + while (!begin_line) { const char *r = rev_start, *q = needle; int r_mb_len, q_mb_len;