Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Apr 1999 23:21:25 +0800 (CST)
From:      Yung-Jen Hung <winard@u3717a.dorm.ccu.edu.tw>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   misc/10918: Big5 rune function in libc
Message-ID:  <199904021521.XAA01537@u3717a.dorm.ccu.edu.tw>

next in thread | raw e-mail | index | archive | help

>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 <rune.h>
#include <stdio.h>
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199904021521.XAA01537>