--- src/motion/estimation_bvop.c.orig 2004-06-22 19:57:46.168910368 +0200 +++ src/motion/estimation_bvop.c 2004-06-22 19:57:50.802206000 +0200 @@ -573,16 +573,26 @@ b_dy = (b_dy >> 3) + roundtab_76[b_dy & 0xf]; b_dx = (b_dx >> 3) + roundtab_76[b_dx & 0xf]; + /* 64-bit Fix: + * The variables y, stride and x are unsigned, while dy and dy are signed. If + * e.g. dy is < -1, the factor dy/2 becomes < 0. But because y is unsigned, the + * -1 value will be 'promoted' to the unsigned 0xffffffff. This is no problem on + * 32 bit platforms, because adding 0xffffffff to a char pointer or adding -1 + * the same. But on 64bit this is no longer the case. So we have to really use + * signed variables here (note that we assume that the unsiged values are + * below 0x80000000, which should be true, because otherwise all kind of + * other problems will additionally pop up). + */ sum = sad8bi(pCur->u + 8 * x + 8 * y * stride, - f_Ref->u + (y*8 + dy/2) * stride + x*8 + dx/2, - b_Ref->u + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, + f_Ref->u + ((int) y*8 + dy/2) * (int) stride + (int) x*8 + dx/2, + b_Ref->u + ((int) y*8 + b_dy/2) * (int) stride + (int) x*8 + b_dx/2, stride); if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */ sum += sad8bi(pCur->v + 8*x + 8 * y * stride, - f_Ref->v + (y*8 + dy/2) * stride + x*8 + dx/2, - b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, + f_Ref->v + ((int) y*8 + dy/2) * (int) stride + (int) x*8 + dx/2, + b_Ref->v + ((int) y*8 + b_dy/2) * (int) stride + (int) x*8 + b_dx/2, stride); if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */