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
intended.

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:
A5:C6:A5:B9:A5:C8:0A:A5:C6:A5:B9:A5:C8:32:
30C6:30B9:30C8:000A:30C6:30B9:

correctly this result must:
30C6:30B9:30C8:

Cheers,
--
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]