Fix to exceptions in ddtest

Michael Karcher wine at mkarcher.dialup.fu-berlin.de
Tue Oct 14 03:57:54 CDT 2008


Am Montag, den 13.10.2008, 14:30 -0400 schrieb Chris Ahrendt:
> Ok I fixed the code to take this out... however : one section there is 
> something I am not sure of so I left it in to prevent the exception from 
> occuring.
This is an additional explanation in addition to the remarks I made to
your "Try #2" mail.

> here is my change that doesn't cause an exception:

>      ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
>      ok(ret == DD_OK, "Creating a primary surface without width and 
> height info returned %08x\n", ret);
>  >> /* This should be handled but CreateSurface is not returning right */
>  >>    if (FAILED(ret))
>  >>    {
>  >>        skip("Can't create cubemap surface\n");
>  >>        return;
>  >>    }
>      if(dsurface)
>      {
>          ret = IDirectDrawSurface_GetSurfaceDesc(dsurface, &desc);
>          ok(ret == DD_OK, "GetSurfaceDesc returned %x\n", ret);
> 
> 
> If those lines are not there then when it gets to the
>          ret = IDirectDrawSurface_GetSurfaceDesc(dsurface, &desc);
> line it throws and exception because dsurface is null.. so
> I am wondering if  the if should be if(&dsurface) instead of the above?

Sorry, you seem to misunderstand the C language in this regard. Code
flow never gets to the GetSurfaceDesc call if dsurface is NULL, because
  if(dsurface)
means the same as
  if(dsurface != NULL)
so the whole block is only executed if dsurface is not NULL.

You definitely do not want "if(&dsurface)" instead because that would
test if the address of the variable dsurface (that is the memory
location where the pointer to the interface is stored) is not NULL. This
is *always* the case, as the variable "dsurface" is allocated on the
stack and &dsurface is thus pointing into the stack. The check
if(dsurface) checks whether the contents of the variable dsurface, which
should point to the DirectDrawSurface interface, is a NULL value
pointing nowhere instead, which is exactly what we need here.

Regards,
  Michael Karcher




More information about the wine-devel mailing list