Re: cppcheck sept 18 redux

2009-09-26 Thread Detlef Riekenberg
On Di, 2009-09-22 at 07:46 -0700, Chris Robinson wrote: > so dmW->dmFormName is the same as &(*dmW).dmFormName, When the target is an array, the address of the first member is returned: dmW->fmFormName is: &(dmW->dmFormName[0]) similar: char buffer[32]; printf("buffer at %p\n", buffer); which

Re: cppcheck sept 18 redux

2009-09-22 Thread Vitaliy Margolen
Henri Verbeet wrote: > 2009/9/22 Vitaliy Margolen : >> It does dereference the pointer. Here is your simple test. Compile it and >> run it. See what happens. >> >> #include >> >> typedef struct _s_test >> { >>void *pointer; >> } s_test; >> >> int main() >> { >>s_test *s = NULL; >>long

Re: cppcheck sept 18 redux

2009-09-22 Thread Ove Kaaven
Chris Robinson skrev: > On Tuesday 22 September 2009 12:32:35 am Mike Kaplinskiy wrote: >> It actually does not dereference anything. > > Does the C standard specify that taking the address of a struct member being > dereferenced doesn't actually cause a dereference, instead just offsetting? It

Re: cppcheck sept 18 redux

2009-09-22 Thread Ove Kaaven
Luke Benstead skrev: > 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 com

Re: cppcheck sept 18 redux

2009-09-22 Thread David Laight
On Tue, Sep 22, 2009 at 02:56:05AM -0400, Mike Kaplinskiy wrote: > On Tue, Sep 22, 2009 at 1:09 AM, Vitaliy Margolen > wrote: > > Ben Klein wrote: > >> The question remains, how exactly does > >> FIELD_OFFSET work, and does it end up dereferencing ca[5]? > > It does pointer arithmetic and does not

Re: cppcheck sept 18 redux

2009-09-22 Thread Mike Kaplinskiy
On Tue, Sep 22, 2009 at 10:48 AM, Luke Benstead wrote: > 2009/9/22 Ben Klein : >> 2009/9/23 Luke Benstead : >>> 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 tha

Re: cppcheck sept 18 redux

2009-09-22 Thread Henri Verbeet
2009/9/22 Henri Verbeet : > "s->pointer" refers to the value of the pointer if "pointer" is a > pointer, but to the address of the first array element if "pointer" is > an array. I.e. "&s->pointer[0]" as Nicolas posted. > To clarify a bit more, if it's an array the actual array elements are stored

Re: cppcheck sept 18 redux

2009-09-22 Thread Henri Verbeet
2009/9/22 Luke Benstead : > 2009/9/22 Ben Klein : >> 2009/9/23 Luke Benstead : >>> 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 >

Re: cppcheck sept 18 redux

2009-09-22 Thread Chris Robinson
On Tuesday 22 September 2009 7:53:08 am Ben Klein wrote: > Worth trying my sample code on non-GCC compilers then: With all optimizations off (if I had non-GCC compilers, I'd try them). But still, I'm not really saying this is a problem (especially since the FIELD_OFFSET macro does this, and is u

Re: cppcheck sept 18 redux

2009-09-22 Thread Henri Verbeet
2009/9/22 Chris Robinson : > On Tuesday 22 September 2009 12:32:35 am Mike Kaplinskiy wrote: >> It actually does not dereference anything. > > Does the C standard specify that taking the address of a struct member being > dereferenced doesn't actually cause a dereference, instead just offsetting? >

Re: cppcheck sept 18 redux

2009-09-22 Thread Ben Klein
2009/9/23 Luke Benstead : > 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 th

Re: cppcheck sept 18 redux

2009-09-22 Thread Ben Klein
2009/9/23 Chris Robinson : > On Tuesday 22 September 2009 12:32:35 am Mike Kaplinskiy wrote: >> It actually does not dereference anything. > > Does the C standard specify that taking the address of a struct member being > dereferenced doesn't actually cause a dereference, instead just offsetting? >

Re: cppcheck sept 18 redux

2009-09-22 Thread Luke Benstead
2009/9/22 Ben Klein : > 2009/9/23 Luke Benstead : >> 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

Re: cppcheck sept 18 redux

2009-09-22 Thread Nicolas Le Cam
2009/9/22 Luke Benstead : > 2009/9/22 Ben Klein : >> 2009/9/22 Vitaliy Margolen : >>> 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 bu

Re: cppcheck sept 18 redux

2009-09-22 Thread Chris Robinson
On Tuesday 22 September 2009 12:32:35 am Mike Kaplinskiy wrote: > It actually does not dereference anything. Does the C standard specify that taking the address of a struct member being dereferenced doesn't actually cause a dereference, instead just offsetting? Doing foo-> is identical to (*foo)

Re: cppcheck sept 18 redux

2009-09-22 Thread Luke Benstead
2009/9/22 Ben Klein : > 2009/9/22 Vitaliy Margolen : >> 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 >>

Re: cppcheck sept 18 redux

2009-09-22 Thread Ben Klein
2009/9/22 Vitaliy Margolen : > 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

Re: cppcheck sept 18 redux

2009-09-22 Thread Henri Verbeet
2009/9/22 Vitaliy Margolen : > It does dereference the pointer. Here is your simple test. Compile it and > run it. See what happens. > > #include > > typedef struct _s_test > { >    void *pointer; > }  s_test; > > int main() > { >    s_test *s = NULL; >    long diff = (const char*)s->pointer - (co

Re: cppcheck sept 18 redux

2009-09-22 Thread Vitaliy Margolen
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

Re: cppcheck sept 18 redux

2009-09-22 Thread Ben Klein
2009/9/22 Mike Kaplinskiy : > On Tue, Sep 22, 2009 at 3:06 AM, Ben Klein wrote: >> 2009/9/22 Mike Kaplinskiy : >>> On Tue, Sep 22, 2009 at 1:09 AM, Vitaliy Margolen >>> wrote: > [/home/cahrendt/wine-git/dlls/wineps.drv/init.c:270]: (error) Possible > null pointer dereference: dmW - otherw

Re: cppcheck sept 18 redux

2009-09-22 Thread Mike Kaplinskiy
On Tue, Sep 22, 2009 at 3:06 AM, Ben Klein wrote: > 2009/9/22 Mike Kaplinskiy : >> On Tue, Sep 22, 2009 at 1:09 AM, Vitaliy Margolen >> wrote: [/home/cahrendt/wine-git/dlls/wineps.drv/init.c:270]: (error) Possible null pointer dereference: dmW - otherwise it is redundant to check if >>>

Re: cppcheck sept 18 redux

2009-09-22 Thread Ben Klein
2009/9/22 Mike Kaplinskiy : > On Tue, Sep 22, 2009 at 1:09 AM, Vitaliy Margolen > wrote: >>> [/home/cahrendt/wine-git/dlls/wineps.drv/init.c:270]: (error) Possible >>> null pointer dereference: dmW - otherwise it is redundant to check if >>> dmW is null at line 272 >> >> This is a real bug and sho

Re: cppcheck sept 18 redux

2009-09-21 Thread Mike Kaplinskiy
On Tue, Sep 22, 2009 at 1:09 AM, Vitaliy Margolen wrote: > Ben Klein wrote: >> The question remains, how exactly does >> FIELD_OFFSET work, and does it end up dereferencing ca[5]? > It does pointer arithmetic and does not dereference anything. "ca[5]" is the > same as "(ca + 5)" or on lower level

Re: cppcheck sept 18 redux

2009-09-21 Thread Vitaliy Margolen
Ben Klein wrote: > The question remains, how exactly does > FIELD_OFFSET work, and does it end up dereferencing ca[5]? It does pointer arithmetic and does not dereference anything. "ca[5]" is the same as "(ca + 5)" or on lower level "((char*)ca + 5*sizeof(ca[0]))" and does not require any dereferen

Re: cppcheck sept 18 redux

2009-09-21 Thread Ben Klein
2009/9/21 chris ahrendt : > False positive ticket created for: > > [/home/cahrendt/wine-git/dlls/wineps.drv/init.c:270]: (error) Possible > null pointer dereference: dmW - otherwise it is redundant to check if > dmW is null at line 272 > > what about the others? or the suggestion of adding an addit

cppcheck sept 18 redux

2009-09-21 Thread chris ahrendt
False positive ticket created for: [/home/cahrendt/wine-git/dlls/wineps.drv/init.c:270]: (error) Possible null pointer dereference: dmW - otherwise it is redundant to check if dmW is null at line 272 what about the others? or the suggestion of adding an additional int to the array? chris

Re: cppcheck Sept 18

2009-09-20 Thread Ben Klein
2009/9/21 James Mckenzie : > > > -Original Message- >>From: Henri Verbeet >>Sent: Sep 20, 2009 12:19 PM >>To: Pauli Nieminen >>Cc: wine-devel@winehq.org, Joris Huizer >>Subject: Re: cppcheck Sept 18 >> >>Not quite. For one, the ca[5] t

Re: cppcheck Sept 18

2009-09-20 Thread James Mckenzie
-Original Message- >From: Henri Verbeet >Sent: Sep 20, 2009 12:19 PM >To: Pauli Nieminen >Cc: wine-devel@winehq.org, Joris Huizer >Subject: Re: cppcheck Sept 18 > >2009/9/20 Pauli Nieminen >> >> On Sat, Sep 19, 2009 at 1:59 PM, Joris Huizer wrote:

Re: cppcheck Sept 18

2009-09-20 Thread Henri Verbeet
2009/9/20 Pauli Nieminen > > On Sat, Sep 19, 2009 at 1:59 PM, Joris Huizer wrote: >> >> [/home/cahrendt/wine-git/dlls/rpcrt4/tests/server.c:1189]: (possible >> error) Array index out of bounds >> >> This one is a false positive, it uses FIELD_OFFSET(cs_t, ca[5]), >> and it found an array: >> int

Re: cppcheck Sept 18

2009-09-20 Thread James Mckenzie
>[/home/cahrendt/wine-git/dlls/rpcrt4/tests/server.c:1189]: (possible >error) Array index out of bounds > >This one is a false positive, it uses FIELD_OFFSET(cs_t, ca[5]), >and it found an array: >int ca[5]; > Actually, if this is a zero offset array, this is out of bounds. It might be better t

Re: cppcheck Sept 18

2009-09-20 Thread Pauli Nieminen
On Sat, Sep 19, 2009 at 1:59 PM, Joris Huizer wrote: > [/home/cahrendt/wine-git/dlls/rpcrt4/tests/server.c:1189]: (possible > error) Array index out of bounds > > This one is a false positive, it uses FIELD_OFFSET(cs_t, ca[5]), > and it found an array: > int ca[5]; > > int ca[5]; has only entries

Re: cppcheck Sept 18

2009-09-20 Thread Nicolas Le Cam
2009/9/19 Joris Huizer > [/home/cahrendt/wine-git/dlls/wineps.drv/init.c:270]: (error) Possible > null pointer dereference: dmW - otherwise it is redundant to check if > dmW is null at line 272 > > That is a bug, sent a patch > > HTH, > > Joris > Joris, As explained in a previous mail, there's no

cppcheck Sept 18

2009-09-20 Thread Joris Huizer
[/home/cahrendt/wine-git/dlls/ntdll/server.c:802]: (error) Resource leak: fd [/home/cahrendt/wine-git/dlls/ntdll/server.c:882]: (error) Resource leak: fd_cwd These two are false positives, as the process ends (calling exit(1) [/home/cahrendt/wine-git/dlls/rpcrt4/tests/server.c:1189]: (possible

cppcheck Sept 18

2009-09-18 Thread chris ahrendt
[/home/cahrendt/wine-git/dlls/ntdll/server.c:802]: (error) Resource leak: fd [/home/cahrendt/wine-git/dlls/ntdll/server.c:882]: (error) Resource leak: fd_cwd [/home/cahrendt/wine-git/dlls/rpcrt4/tests/server.c:1189]: (possible error) Array index out of bounds [/home/cahrendt/wine-git/dlls/wineps.