bug-texinfo
[Top][All Lists]
Advanced

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

Re: Pointer casts in texinfo-4.7


From: Stepan Kasal
Subject: Re: Pointer casts in texinfo-4.7
Date: Fri, 16 Jul 2004 10:51:03 +0200
User-agent: Mutt/1.4.1i

Hello,
  thank you for your bug report.  Karl, the texinfo maintainer, is out
for a week.

Here is a quick "unofficial" comment from me:

On Wed, Jul 14, 2004 at 08:38:59PM +0200, Havard Eidnes wrote:
>    warning: cast to pointer from integer of different size
...
> BTW, the cast of integer values to pointers in order to fit with
> an argument list declaration leaves me with a somewhat foul taste
> in my mouth...

I agree.  Moreover, I can imagine that on some architectures the printf
parameter for "%s" has different size that that for "%d"; I think that
in that case, the code may not work.  (If there were more parameters,
or if the architecture is big-endian.)

>      info_error ((char *) _("There aren't %d items in this menu."),
> -        (void *) item, NULL);
> +        (void *)((intptr_t)item), NULL);

It would be better to call snprintf to convert the number to a string.

And it would be even better to rewrite the function so that it uses va_list.
The prototype of the function would look like this:
        void info_error (const char *format, ...)
             __attribute__ ((__format__ (__printf__, 1, 2)));
(at leasyt with gcc).  You can see such things in glibc's error.h .

I took the inspiration from libgsf; gsf-output.h contains:
        gboolean gsf_output_printf (GsfOutput *output, char const *format,
                                    ...) G_GNUC_PRINTF (2, 3);
where the macro is defined by glib as:
        #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
        #define G_GNUC_PRINTF( format_idx, arg_idx )    \
          __attribute__((__format__ (__printf__, format_idx, arg_idx)))
        #else
        #define G_GNUC_PRINTF( format_idx, arg_idx )
        #endif

If you are willing to make a patch, I beleive it would be welcome.

Thanks again for pointing this out.
        Stepan Kasal




reply via email to

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