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

Bug#657215: [PATCH videoproto] Xvproto: fix xvEncodingInfo to match actual wire protocol



On 06/ 9/13 10:00 AM, Julien Cristau wrote:
The padding is *before* the rate field, so the rate is placed on a 32bit
boundary.  This change adds explicit padding between height and rate,
and removes extraneous padding after the rate field, which the server
never sent and xlib never read.

This changes sizeof(xvEncodingInfo).  Hopefully that's not a big deal as
clients only see the Xlib structure XvEncodingInfo.

Debian bug#657215

Reported-by: Kevin Ryde <user42@zip.com.au>
Signed-off-by: Julien Cristau <jcristau@debian.org>

This looked reasonable to me, but just to be sure, I threw together the
attached test program and confirmed it doesn't change where in the
struct the rate data appears, due to the compiler silently inserting
padding to reach 32-bit alignment.

In both 32-bit & 64-bit, on both SPARC & x86, all 4 returned:

                 OLD  NEW
offsetof(rate):   12  12
offsetof(pad):    20  10
sizeof(struct):   24  20

which matches my expectations, so:

Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>

--
	-Alan Coopersmith-              alan.coopersmith@oracle.com
	 Oracle Solaris Engineering - http://blogs.oracle.com/alanc
#include <stdio.h>
#include <stddef.h>
#include <X11/Xmd.h>

#define XvEncodingID CARD32

typedef struct {
  INT32 numerator B32;
  INT32 denominator B32;
} xvRational;

typedef struct {
  XvEncodingID encoding B32;
  CARD16 name_size B16;
  CARD16 width B16, height B16;
  xvRational rate;
  CARD16 pad B16;
} OLDxvEncodingInfo;

typedef struct {
  XvEncodingID encoding B32;
  CARD16 name_size B16;
  CARD16 width B16, height B16;
  CARD16 pad B16;
  xvRational rate;
} NEWxvEncodingInfo;

int main(int argc, char **argv)
{
    printf("                 OLD  NEW\n");
    printf("offsetof(rate):   %2d  %2d\n",
           offsetof(OLDxvEncodingInfo, rate),
           offsetof(NEWxvEncodingInfo, rate));
    printf("offsetof(pad):    %2d  %2d\n",
           offsetof(OLDxvEncodingInfo, pad),
           offsetof(NEWxvEncodingInfo, pad));
    printf("sizeof(struct):   %2d  %2d\n",
           sizeof(OLDxvEncodingInfo),
           sizeof(NEWxvEncodingInfo));
}

Reply to: