Module Name:    src
Committed By:   christos
Date:           Thu Jul 28 01:08:58 UTC 2011

Modified Files:
        src/lib/libedit/TEST: wtc1.c

Log Message:
- check and don't cast malloc return
- more wide function use


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libedit/TEST/wtc1.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/TEST/wtc1.c
diff -u src/lib/libedit/TEST/wtc1.c:1.3 src/lib/libedit/TEST/wtc1.c:1.4
--- src/lib/libedit/TEST/wtc1.c:1.3	Tue Jul 26 22:18:00 2011
+++ src/lib/libedit/TEST/wtc1.c	Wed Jul 27 21:08:58 2011
@@ -62,6 +62,7 @@
 	const LineInfoW *lf = el_wline(el);
 	int len, mblen, i;
 	unsigned char res;
+	wchar_t dir[1024];
 
 	/* Find the last word */
 	for (ptr = lf->cursor -1; !iswspace(*ptr) && ptr > lf->buffer; --ptr)
@@ -71,7 +72,9 @@
 	/* Convert last word to multibyte encoding, so we can compare to it */
 	wctomb(NULL, 0); /* Reset shift state */
 	mblen = MB_LEN_MAX * len + 1;
-	buf = bptr =(char *)malloc(mblen);
+	buf = bptr = malloc(mblen);
+	if (buf == NULL)
+		err(1, "malloc");
 	for (i = 0; i < len; ++i) {
 		/* Note: really should test for -1 return from wctomb */
 		bptr += wctomb(bptr, ptr[i]);
@@ -84,7 +87,9 @@
 		if (mblen > strlen(dp->d_name))
 			continue;
 		if (strncmp(dp->d_name, buf, mblen) == 0) {
-			if (el_insertstr(el, &dp->d_name[mblen]) == -1)
+			mbstowcs(dir, &dp->d_name[mblen],
+			    sizeof(dir) / sizeof(*dir));
+			if (el_winsertstr(el, dir) == -1)
 				res = CC_ERROR;
 			else
 				res = CC_REFRESH;

Reply via email to