From owner-freebsd-bugs Fri Apr 2 7:30:22 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 3ACCA14D47 for ; Fri, 2 Apr 1999 07:30:21 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.2/8.9.2) id HAA62714; Fri, 2 Apr 1999 07:30:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from u3717a.dorm.ccu.edu.tw (u3717a.dorm.ccu.edu.tw [140.123.220.34]) by hub.freebsd.org (Postfix) with ESMTP id 3C2D614CB3 for ; Fri, 2 Apr 1999 07:22:11 -0800 (PST) (envelope-from winard@u3717a.dorm.ccu.edu.tw) Received: (from winard@localhost) by u3717a.dorm.ccu.edu.tw (8.9.2/8.9.2) id XAA01537; Fri, 2 Apr 1999 23:21:25 +0800 (CST) (envelope-from winard) Message-Id: <199904021521.XAA01537@u3717a.dorm.ccu.edu.tw> Date: Fri, 2 Apr 1999 23:21:25 +0800 (CST) From: Yung-Jen Hung Reply-To: winard@u3717a.dorm.ccu.edu.tw To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: misc/10918: Big5 rune function in libc Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 10918 >Category: misc >Synopsis: _BIG5_sgetrune() in libc doesn't work well >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Apr 2 07:30:01 PST 1999 >Closed-Date: >Last-Modified: >Originator: Yung-Jen Hung >Release: FreeBSD 3.1-STABLE i386 >Organization: Department of Computer Science and Information Engineering, National Chung Cheng University, Taiwan >Environment: None. >Description: the function _BIG5_sgetrune() in /usr/src/lib/libc/locale/big5.c is wrong, as a result it can't convert Big5 multi-byte words into wide-character correctly. >How-To-Repeat: the following program should output 72 75 6e 65 b4fa b8d5, but a segmentation fault occurs now. before run this program, set the environment variable LD_PRELOAD to /usr/lib/libxpg4.so.2 first. /* a program convert characters into rune */ #include #include int main(void) { setrunelocale("zh_TW.BIG5"); const char* src = "rune\xb4\xfa\xb8\xd5"; const char* ld = src; rune_t rune[256]; int num = 0; while( ( rune[num] = sgetrune( ld, 3, &ld ) ) != 0 ) num ++; for( int c = 0; c < num; c ++ ) printf( " %02x", rune[c] ); putchar('\n'); } >Fix: change these five lines in big5.c line #85: while (len-- >= 0) rune = (rune << 8) | ((u_int)(*string++) & 0xff); if (result) *result = string + len; return rune; to these correct codes: while (--len >= 0) rune = (rune << 8) | ((u_int)(*string++) & 0xff); if (result) *result = string; return rune; >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message