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

Re: Upstream asks: unportable patch for mirrormagic?



> > > =======================================================
> > > --- mirrormagic-2.0.0.orig/src/libgame/gadgets.c
> > > +++ mirrormagic-2.0.0/src/libgame/gadgets.c
> > > @@ -309,7 +309,7 @@
> > >         break;
> > >
> > >        case GDI_CHECKED:
> > > -       gi->checked = va_arg(ap, boolean);
> > > +       gi->checked = (boolean) va_arg(ap, int);
> > >         break;
> > [...]
> >
> > Hm, applying this patch would mess up things for other platforms,
> > because "boolean" is typedef'ed as "unsigned char". If it simply
> > gets replaced by "int", va_arg reads a 16 or 32 bit value instead
> > of a 8 bit value.


Nope, this patch makes va_arg get the proper arguments in the first place.
va_arg may only be called with the data type argument being one of the
data types after default type promotion (char -> int, float -> double).
Any other way of using va_arg is in violation of the language standard
(even though it will run on most architectures and compiler
implementations).

Read /usr/lib/gcc-lib/<yadda>.../include/va-ppc.h for how the va_list data
type on PowerPC differs from other architectures', and ponder the
ramifications of using types of the wrong size in va_arg.

	Michael



Reply to: