Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit/TEST - check and don't cast malloc return



details:   https://anonhg.NetBSD.org/src/rev/33ccbbb9a354
branches:  trunk
changeset: 767710:33ccbbb9a354
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jul 28 01:08:58 2011 +0000

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

diffstat:

 lib/libedit/TEST/wtc1.c |  9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diffs (33 lines):

diff -r d779d5582b92 -r 33ccbbb9a354 lib/libedit/TEST/wtc1.c
--- a/lib/libedit/TEST/wtc1.c   Thu Jul 28 01:05:20 2011 +0000
+++ b/lib/libedit/TEST/wtc1.c   Thu Jul 28 01:08:58 2011 +0000
@@ -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;



Home | Main Index | Thread Index | Old Index