commit 118cb37e63848af1a9d428b79654a39532dc8fb5
parent d3887dc6958c3c956921801f9cb809e12231abb6
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Sat, 22 Jul 2006 16:45:11 +0000
in mbstrncasecmp(), mbstrcasestr(), and mbrevstrcasestr(), don't
allocate space for multibyte characters until we've asserted that the
parameters we're using aren't NULL
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3803 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git 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
@@ -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;