cppcheck sept 18 redux

Nicolas Le Cam niko.lecam at gmail.com
Tue Sep 22 09:48:29 CDT 2009


2009/9/22 Luke Benstead <kazade at gmail.com>:
> 2009/9/22 Ben Klein <shacklein at gmail.com>:
>> 2009/9/22 Vitaliy Margolen <wine-devel at kievinfo.com>:
>>> Mike Kaplinskiy wrote:
>>>> It actually does not dereference anything. Try passing null into the
>>>> function - it will work just fine. This is a special case because the
>>>> array isn't dynamically allocated but is part of the struct, which
>>>> means that dmW->dmFormName == (dmW+__offset of dmFormName) and not
>>>> *(dmW+__offset of dmFormName). You can try writing a test program
>>>> yourself - it will run just fine.
>>> It does dereference the pointer. Here is your simple test. Compile it and
>>> run it. See what happens.
>>>
>>> #include <stdio.h>
>>>
>>> typedef struct _s_test
>>> {
>>>    void *pointer;
>>
>> No. Array, not pointer. E.g.:
>>    int array[1];
>>
>>> }  s_test;
>>
>>
>>
>
> If it IS the case that this doesn't cause a crash and is perfectly
> valid, can someone explain to me how/why this works? Or point me (no
> pun intended) to the bit in the C spec that explains it? Coz the way I
> read it, it has to dereference dmW, otherwise how would the compiler
> find the address of the array? ... so confused :)
>
> Luke.
>
>
>
Luke,

Wine's current code is basically equivalent to the one above, where
there's no dereference :
#include <stdio.h>

typedef struct _s_test
{
   char pointer[5];
}  s_test;

int main()
{
   s_test *s = NULL;
   long diff = (const char*)(&s->pointer[0]) - (const char*)s;
   printf("diff=%ld\n", diff);

   return 0;
}

-- 
Nicolas Le Cam



More information about the wine-devel mailing list