[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    patch for the 'sgetrune' of EUC encoding
From:       $BEDCfH <mihoko () pa ! yokogawa ! co ! jp>
Date:       1996-07-25 11:20:17
[Download RAW message or body]


Hello all,

I found a problem in sgetrune of EUC encoding.

That is, The library function 'mblen(3)' doesn't return the error
when the second byte is not set MSB.
I make the following patch for this problem.
It is available for 2.1.0R, 2.1.5R, and -current.

How about it ?

--------< patch for /usr/src/lib/libc/locale/euc.c >------------------------
--- euc.c	Thu May 26 22:56:45 1994
+++ euc.c.new	Thu Jul 25 19:12:36 1996
@@ -136,6 +136,7 @@
 {
 	rune_t rune = 0;
 	int len, set;
+	unsigned char c;
 
 	if (n < 1 || (len = CEI->count[set = _euc_set(*string)]) > n) {
 		if (result)
@@ -147,11 +148,20 @@
 	case 2:
 		--len;
 		++string;
-		/* FALLTHROUGH */
 	case 1:
+		while (len-- > 0) {
+			/* '0x80-0x9f' are control codes */
+			if ((c = (unsigned char)*string++) < 0xa0) {
+				if (result)
+					*result = string;
+				return (_INVALID_RUNE);
+			};
+			rune = (rune << 8) | ((u_int)(c) & 0xff);
+		}
+		break;
+		/* FALLTHROUGH */
 	case 0:
-		while (len-- > 0)
-			rune = (rune << 8) | ((u_int)(*string++) & 0xff);
+		rune = (u_int)(*string++) & 0xff;
 		break;
 	}
 	if (result)

------------------- cut cut cut -------------------------------

--
Mihoko Tanaka
<mihoko@pa.yokogawa.co.jp>

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic