Re: [gnet] [field_escape function] Still a problem with latin1 characters?



On Monday 01 November 2004 10:43, Emmanuel Saracco wrote:

> It seems that there is still a problem in "field_escape" method with
> latin1 characters. Here is a example:
>
> ----------
> g_print ("ref: %s\n", gnet_uri_get_string (uri));
> gnet_uri_unescape (uri);
> g_print ("unescaped: %s\n", gnet_uri_get_string (uri));
> gnet_uri_escape (uri);
> g_print ("escaped: %s\n", gnet_uri_get_string (uri));
>
> will output (bad):
>
> ref: http://www.easter-eggs.fr:80/index.php/La%20vie%20de%20la%20soci%
> E9t%E9
> unescaped: http://www.easter-eggs.fr:80/index.php/La vie de la société
> escaped: http://www.easter-eggs.fr:80/index.php/La%20vie%20de%20la%
> 20soci%.9t%.9
>
> instead of (good):
>
> ref: http://www.easter-eggs.fr:80/index.php/La%20vie%20de%20la%20soci%
> E9t%E9
> unescaped: http://www.easter-eggs.fr:80/index.php/La vie de la société
> escaped: http://www.easter-eggs.fr:80/index.php/La%20vie%20de%20la%
> 20soci%E9t%E9
>
> which will result in a 400 HTTP error.
> ----------
>
> Any idea?

I seem to get different results depending on whether the code is compiled with 
gcc-2.9x or gcc-3.2/3.3/3.4.

Looks like it comes down to a casting problem:

  gchar c;
  guint  n;

  c = 0xE9;
  n = (guint) c;

  g_print ("n = %u\n", n);

will print 4294967273.

while

   n = (guint) ((guchar) c);

will print 233.

We obviously want the latter as index for neednt_escape_table. Strangely, 
valgrind doesn't show any out-of-bounds memory access though, so maybe I'm 
wrong.

In any case, proposed patch attached.

Cheers 
-Tim


Index: src/uri.c
===================================================================
RCS file: /cvs/gnome/gnet/src/uri.c,v
retrieving revision 1.8
diff -u -r1.8 uri.c
--- src/uri.c	11 Aug 2003 01:20:01 -0000	1.8
+++ src/uri.c	1 Nov 2004 12:07:42 -0000
@@ -474,7 +474,7 @@
   len = 0;
   for (i = 0; str[i]; i++)
     {
-      if (neednt_escape_table[(guint) str[i]] & mask)
+      if (neednt_escape_table[(guint) ((guchar) str[i])] & mask)
 	len++;
       else
 	{
@@ -494,7 +494,7 @@
   for (i = j = 0; str[i]; i++, j++)
     {
       /* Unescaped character */
-      if (neednt_escape_table[(guint) str[i]] & mask)
+      if (neednt_escape_table[(guint) ((guchar) str[i])] & mask)
 	{
 	  dst[j] = str[i];
 	}


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