diff options
author | Tim J. Robbins <tjr@FreeBSD.org> | 2004-06-27 10:35:28 +0000 |
---|---|---|
committer | Tim J. Robbins <tjr@FreeBSD.org> | 2004-06-27 10:35:28 +0000 |
commit | d900c38411bbd8b75d877f29e751949f934cb127 (patch) | |
tree | 510573a330ac6923a31c63863e5a688b9e786235 /usr.bin/cut | |
parent | 232a681888e19a50dbf90d9909793d0e5e2f27bb (diff) | |
download | src-d900c38411bbd8b75d877f29e751949f934cb127.tar.gz src-d900c38411bbd8b75d877f29e751949f934cb127.zip |
Make the handling of invalid multibyte sequences more robust by using
mbrlen() instead of mblen().
Notes
Notes:
svn path=/head/; revision=131183
Diffstat (limited to 'usr.bin/cut')
-rw-r--r-- | usr.bin/cut/cut.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c index b8bf0b3b35dd..0447db09b4a6 100644 --- a/usr.bin/cut/cut.c +++ b/usr.bin/cut/cut.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <wchar.h> int bflag; int cflag; @@ -239,15 +240,18 @@ b_n_cut(FILE *fp, const char *fname) size_t col, i, lbuflen; char *lbuf; int canwrite, clen, warned; + mbstate_t mbs; + memset(&mbs, 0, sizeof(mbs)); warned = 0; while ((lbuf = fgetln(fp, &lbuflen)) != NULL) { for (col = 0; lbuflen > 0; col += clen) { - if ((clen = mblen(lbuf, lbuflen)) < 0) { + if ((clen = mbrlen(lbuf, lbuflen, &mbs)) < 0) { if (!warned) { warn("%s", fname); warned = 1; } + memset(&mbs, 0, sizeof(mbs)); clen = 1; } if (clen == 0 || *lbuf == '\n') |