Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] Re: (PR#2262) [Bug][Patch] Really call put_conv
Home

[Freeciv-Dev] Re: (PR#2262) [Bug][Patch] Really call put_conv

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2262) [Bug][Patch] Really call put_conv
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 3 Nov 2002 11:07:17 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Sun, Nov 03, 2002 at 10:36:21AM -0800, Vasco Alexandre da Silva Costa via RT 
wrote:
> 
> [vasc - Sun Nov  3 17:59:17 2002]:

> Index: client/gui-gtk-2.0/gui_main.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
> retrieving revision 1.29
> diff -u -r1.29 gui_main.c
> --- client/gui-gtk-2.0/gui_main.c     2002/11/02 21:27:43     1.29
> +++ client/gui-gtk-2.0/gui_main.c     2002/11/03 18:34:49
> @@ -168,21 +168,24 @@
>  /**************************************************************************
>  ...
>  **************************************************************************/
> -static unsigned char *put_conv(unsigned char *dst, const char *src)
> +static unsigned char *put_conv(const char *src, size_t *length)
>  {
>    gsize len;

Why the extra variable?

> -  gchar *out = g_convert(src, -1, network_charset, "UTF-8", NULL, &len, 
> NULL);
> +  gchar *out =
> +    g_convert(src, -1, network_charset, "UTF-8", NULL, &len, NULL);
>  
>    if (out) {
> +    unsigned char *dst = fc_malloc(len);
> +
>      memcpy(dst, out, len);
>      g_free(out);
>      dst[len] = '\0';
>  
> -    return dst + len + 1;
> +    *length = len;
> +    return dst;
>    } else {
> -    dst[0] = '\0';
> -
> -    return dst + 1;
> +    *length = 0;
> +    return NULL;
>    }
>  }
>  
> Index: common/dataio.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/common/dataio.c,v
> retrieving revision 1.4
> diff -u -r1.4 dataio.c
> --- common/dataio.c   2002/10/09 13:31:09     1.4
> +++ common/dataio.c   2002/11/03 18:34:50
> @@ -59,22 +59,11 @@
>  /**************************************************************************
>  ...
>  **************************************************************************/
> -static unsigned char *put_conv(unsigned char *dst, const char *src)
> -{
> -  size_t len = strlen(src) + 1;
> -
> -  memcpy(dst, src, len);
> -  return dst + len;
> -}
> +static DIO_PUT_CONV_FUN put_conv_callback = NULL;
>  
>  /**************************************************************************
>  ...
>  **************************************************************************/
> -static DIO_PUT_CONV_FUN put_conv_callback = put_conv;
> -
> -/**************************************************************************
> -...
> -**************************************************************************/
>  void dio_set_put_conv_callback(DIO_PUT_CONV_FUN fun)
>  {
>    put_conv_callback = fun;
> @@ -329,7 +318,17 @@
>  **************************************************************************/
>  void dio_put_string(struct data_out *dout, const char *value)
>  {
> -  dio_put_memory(dout, value, strlen(value) + 1);
> +  if (put_conv_callback) {
> +    size_t length;

> +    unsigned char *buffer;
> +
> +    if ((buffer = (*put_conv_callback) (value, &length))) {

Merge.

> +      dio_put_memory(dout, buffer, length + 1);

Wrong. length already contains the whole length.

Also the problem in my patch "don't handle NULL" isn't a problem since
length is 0 and so the pointer doesn't matter.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Just because you put a flag on the moon doesn't make it yours, it just
  puts a hole in the moon."



[Prev in Thread] Current Thread [Next in Thread]