Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/vis use MB_LEN_MAX directly instead of assuming how ...



details:   https://anonhg.NetBSD.org/src/rev/6b884114923c
branches:  trunk
changeset: 785067:6b884114923c
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Feb 20 17:04:45 2013 +0000

description:
use MB_LEN_MAX directly instead of assuming how large it is.

diffstat:

 usr.bin/vis/vis.c |  17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diffs (59 lines):

diff -r c473031e2079 -r 6b884114923c usr.bin/vis/vis.c
--- a/usr.bin/vis/vis.c Wed Feb 20 17:01:15 2013 +0000
+++ b/usr.bin/vis/vis.c Wed Feb 20 17:04:45 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vis.c,v 1.21 2013/02/15 00:29:44 christos Exp $        */
+/*     $NetBSD: vis.c,v 1.22 2013/02/20 17:04:45 christos Exp $        */
 
 /*-
  * Copyright (c) 1989, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)vis.c      8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: vis.c,v 1.21 2013/02/15 00:29:44 christos Exp $");
+__RCSID("$NetBSD: vis.c,v 1.22 2013/02/20 17:04:45 christos Exp $");
 #endif /* not lint */
 
 #include <stdio.h>
@@ -162,8 +162,8 @@
        static char nul[] = "\0";
        char *cp = nul + 1;     /* so *(cp-1) starts out != '\n' */
        wint_t c, c1, rachar;
-       char mbibuff[13]; /* (2 wchars (i.e., c + c1)) * MB_LEN_MAX) */
-       char buff[5]; /* max vis-encoding length for one char + NUL */
+       char mbibuff[2 * MB_LEN_MAX + 1]; /* max space for 2 wchars */
+       char buff[4 * MB_LEN_MAX + 1]; /* max encoding length for one char */
        int mbilen, cerr = 0, raerr = 0;
        
         /*
@@ -189,8 +189,9 @@
                /* Clear multibyte input buffer. */
                memset(mbibuff, 0, sizeof(mbibuff));
                /* Read-ahead next multibyte character. */
-               rachar = getwc(fp);
-               if (rachar == WEOF && errno == EILSEQ) {
+               if (!cerr)
+                       rachar = getwc(fp);
+               if (cerr || (rachar == WEOF && errno == EILSEQ)) {
                        /* Error in multibyte data.  Read one byte. */
                        rachar = (wint_t)getc(fp);
                        raerr = 1;
@@ -245,7 +246,8 @@
                        else
                                wctomb(mbibuff + mbilen, c1);
                        /* Perform encoding on just first character. */
-                       (void)strsvisx(buff, mbibuff, 1, eflags, extra);
+                       (void) strsenvisx(buff, 4 * MB_LEN_MAX, mbibuff,
+                           1, eflags, extra, &cerr);
                }
 
                cp = buff;
@@ -265,7 +267,6 @@
                } while (*++cp);
                c = rachar;
                cerr = raerr;
-               raerr = 0;
        }
        /*
         * terminate partial line with a hidden newline



Home | Main Index | Thread Index | Old Index