Re: [Nautilus-list] PATCH: linefeed problem for librsvg

>>>>> On Sat, 21 Jul 2001 09:20:43 -0700,
>>>>> "DA" == Darin Adler <darin bentspoon com> wrote:

DA> On Thursday, July 19, 2001, at 12:55  AM, Akira TAGOH wrote:
>> Please commit this patch.

>> /* Alloc max length of wide char */
>> wcstr = g_new0 (wchar_t, length);
>> -	wclength = mbstowcs (wcstr, str, length);
>> +	tmpstr = g_strndup (str, length);
>> +	wclength = mbstowcs (wcstr, tmpstr, length);

DA> Could you please explain why making a truncated copy of str (in tmpstr) is 
DA> helpful and necessary? I'd like to understand this fix before I commit it.

3rd argument of mbstowcs function point the length of
wchar_t. so that when the length argument has the length to
linefeed, the wclength doesn't return the location which is

an example is here:
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main (void)
	unsigned char src[32] = "\xA5\xC6\xA5\xB9\xA5\xC8\x0A\xA5\xC6\xA5\xB9\xA5\xC8\x32";
	wchar_t *dst;
	int wclength, i;

	setlocale (LC_ALL, "ja_JP.eucJP");
	dst = malloc (sizeof (wchar_t) * 6);
	for ( i = 0; src[i] != 0; i++ ) printf ("%02X:", src[i]);
	printf ("\n");
	wclength = mbstowcs (dst, src, 6);
	for ( i = 0; dst[i] != 0L; i++ ) printf ("%04X:", dst[i]);
	printf ("\n");

	return 0;

the result of program is here:

correctly this result must:

Akira TAGOH :: at gclab org
               tagoh gnome gr jp  / Japan GNOME Users Group
               tagoh gnome-db org / GNOME-DB Project
               tagoh redhat com   / Red Hat, Inc.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]