Re: Do not misuse Coverity please

2005-04-11 Thread Pavel Machek
Hi! > "Jean Delvare" <[EMAIL PROTECTED]> said: > > > > > No, there is a third case: the pointer can be NULL, but the compiler > > > > > happened to move the dereference down to after the check. > > > > > Wow. Great point. I completely missed that possibility. In fact I didn't > > > > know that

Re: Do not misuse Coverity please

2005-04-11 Thread Pavel Machek
Hi! Jean Delvare [EMAIL PROTECTED] said: No, there is a third case: the pointer can be NULL, but the compiler happened to move the dereference down to after the check. Wow. Great point. I completely missed that possibility. In fact I didn't know that the compiler could

Re: Do not misuse Coverity please

2005-03-30 Thread Patrick McFarland
On Wednesday 30 March 2005 01:55 pm, Olivier Galibert wrote: > Actually it is. Dereferencing a null pointer is either undefined or > implementation-dependant in the standard (don't remember which), and > as such the compiler can do whatever it wants, be it starting nethack Can this be configured

Re: Not a GCC bug (was Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please])

2005-03-30 Thread Kyle Moffett
On Mar 30, 2005, at 20:12, Nick Piggin wrote: Why should this be in the kernel makefiles? If my_struct is NULL, then the kernel will never reach the if statement. Well, I think there is probably some arch code that uses 16-bit that might use a null pointer, or at least a struct that starts at the

Re: Not a GCC bug (was Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please])

2005-03-30 Thread Nick Piggin
Kyle Moffett wrote: On Mar 30, 2005, at 18:38, Jakub Jelinek wrote: This testcase violates ISO C99 6.3.2.3: If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. Except that

Re: Not a GCC bug (was Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please])

2005-03-30 Thread Kyle Moffett
On Mar 30, 2005, at 18:38, Jakub Jelinek wrote: This testcase violates ISO C99 6.3.2.3: If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. Except that the result of

Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please]

2005-03-30 Thread Robert Hancock
Kyle Moffett wrote: Dereferencing null pointers is relied upon by a number of various emulators and such, and is "platform-defined" in the standard, so since Linux allows mmap at NULL, GCC shouldn't optimize that case any differently. From the GCC manual: "The compiler assumes that dereferencing a

Big GCC bug!!! [Was: Re: Do not misuse Coverity please]

2005-03-30 Thread Kyle Moffett
On Mar 30, 2005, at 14:14, Paulo Marques wrote: Just a minor nitpick, though: wouldn't it be possible for an application to catch the SIGSEGV and let the code proceed, making invalid the assumption made by gcc? Uhh, it's even worse than that. Have a look at the following code: #include #include

Re: Do not misuse Coverity please

2005-03-30 Thread Paulo Marques
Shankar Unni wrote: Jean Delvare wrote: v = p->field; if (!p) return; can be seen as equivalent to if (!p) return; v = p->field; Heck, no. You're missing the side-effect of a null pointer dereference crash (for p->field) (even though v is unused before the return). The optimizer

Re: Do not misuse Coverity please

2005-03-30 Thread Olivier Galibert
On Wed, Mar 30, 2005 at 10:29:43AM -0800, Shankar Unni wrote: > Jean Delvare wrote: > > >v = p->field; > >if (!p) return; > > > >can be seen as equivalent to > > > >if (!p) return; > >v = p->field; > > Heck, no. > > You're missing the side-effect of a null pointer dereference

Re: Do not misuse Coverity please

2005-03-30 Thread Shankar Unni
Jean Delvare wrote: v = p->field; if (!p) return; can be seen as equivalent to if (!p) return; v = p->field; Heck, no. You're missing the side-effect of a null pointer dereference crash (for p->field) (even though v is unused before the return). The optimizer is not allowed to

Re: Do not misuse Coverity please

2005-03-30 Thread Horst von Brand
"Jean Delvare" <[EMAIL PROTECTED]> said: > > > > No, there is a third case: the pointer can be NULL, but the compiler > > > > happened to move the dereference down to after the check. > > > Wow. Great point. I completely missed that possibility. In fact I didn't > > > know that the compiler could

Re: Do not misuse Coverity please

2005-03-30 Thread Jean Delvare
Hi Horst, > > > No, there is a third case: the pointer can be NULL, but the compiler > > > happened to move the dereference down to after the check. > > > Wow. Great point. I completely missed that possibility. In fact I didn't > > know that the compiler could possibly alter the order of the > >

Re: Do not misuse Coverity please

2005-03-30 Thread Jean Delvare
Hi Horst, No, there is a third case: the pointer can be NULL, but the compiler happened to move the dereference down to after the check. Wow. Great point. I completely missed that possibility. In fact I didn't know that the compiler could possibly alter the order of the

Re: Do not misuse Coverity please

2005-03-30 Thread Horst von Brand
Jean Delvare [EMAIL PROTECTED] said: No, there is a third case: the pointer can be NULL, but the compiler happened to move the dereference down to after the check. Wow. Great point. I completely missed that possibility. In fact I didn't know that the compiler could possibly alter

Re: Do not misuse Coverity please

2005-03-30 Thread Shankar Unni
Jean Delvare wrote: v = p-field; if (!p) return; can be seen as equivalent to if (!p) return; v = p-field; Heck, no. You're missing the side-effect of a null pointer dereference crash (for p-field) (even though v is unused before the return). The optimizer is not allowed to make

Re: Do not misuse Coverity please

2005-03-30 Thread Olivier Galibert
On Wed, Mar 30, 2005 at 10:29:43AM -0800, Shankar Unni wrote: Jean Delvare wrote: v = p-field; if (!p) return; can be seen as equivalent to if (!p) return; v = p-field; Heck, no. You're missing the side-effect of a null pointer dereference crash (for p-field)

Re: Do not misuse Coverity please

2005-03-30 Thread Paulo Marques
Shankar Unni wrote: Jean Delvare wrote: v = p-field; if (!p) return; can be seen as equivalent to if (!p) return; v = p-field; Heck, no. You're missing the side-effect of a null pointer dereference crash (for p-field) (even though v is unused before the return). The optimizer is

Big GCC bug!!! [Was: Re: Do not misuse Coverity please]

2005-03-30 Thread Kyle Moffett
On Mar 30, 2005, at 14:14, Paulo Marques wrote: Just a minor nitpick, though: wouldn't it be possible for an application to catch the SIGSEGV and let the code proceed, making invalid the assumption made by gcc? Uhh, it's even worse than that. Have a look at the following code: #include stdio.h

Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please]

2005-03-30 Thread Robert Hancock
Kyle Moffett wrote: Dereferencing null pointers is relied upon by a number of various emulators and such, and is platform-defined in the standard, so since Linux allows mmap at NULL, GCC shouldn't optimize that case any differently. From the GCC manual: The compiler assumes that dereferencing a

Re: Not a GCC bug (was Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please])

2005-03-30 Thread Kyle Moffett
On Mar 30, 2005, at 18:38, Jakub Jelinek wrote: This testcase violates ISO C99 6.3.2.3: If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. Except that the result of

Re: Not a GCC bug (was Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please])

2005-03-30 Thread Nick Piggin
Kyle Moffett wrote: On Mar 30, 2005, at 18:38, Jakub Jelinek wrote: This testcase violates ISO C99 6.3.2.3: If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. Except that

Re: Not a GCC bug (was Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please])

2005-03-30 Thread Kyle Moffett
On Mar 30, 2005, at 20:12, Nick Piggin wrote: Why should this be in the kernel makefiles? If my_struct is NULL, then the kernel will never reach the if statement. Well, I think there is probably some arch code that uses 16-bit that might use a null pointer, or at least a struct that starts at the

Re: Do not misuse Coverity please

2005-03-30 Thread Patrick McFarland
On Wednesday 30 March 2005 01:55 pm, Olivier Galibert wrote: Actually it is. Dereferencing a null pointer is either undefined or implementation-dependant in the standard (don't remember which), and as such the compiler can do whatever it wants, be it starting nethack Can this be configured to

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Horst von Brand
"Jean Delvare" <[EMAIL PROTECTED]> said: [Sttributions missing, sorry] > > > Think about it. If the pointer could be NULL, then it's unlikely that > > > the bug would have gone unnoticed so far (unless the code is very > > > recent). Coverity found 3 such bugs in one i2c driver [1], and the >

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Kyle Moffett
On Mar 29, 2005, at 09:22, Daniel Jacobowitz wrote: The thing GCC is most likely to do with this code is discard the NULL check entirely and leave only the oops; the "if (!card)" can not be reached without passing through "card->amplifier", and a pointer which is dereferenced can not be NULL in a

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Daniel Jacobowitz
On Mon, Mar 28, 2005 at 10:23:48PM -0800, Andrew Morton wrote: > > > -int old=card->amplifier; > > > +int old; > > > if(!card) > > > { > > > CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO > > > "cs46xx: amp_hercules()

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Chris Friesen
Jean Delvare wrote: Wow. Great point. I completely missed that possibility. In fact I didn't know that the compiler could possibly alter the order of the instructions. For one thing, I thought it was simply not allowed to. For another, I didn't know that it had been made so aware that it could

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Jean Delvare
Hi Andrew, all, > > Think about it. If the pointer could be NULL, then it's unlikely that > > the bug would have gone unnoticed so far (unless the code is very > > recent). Coverity found 3 such bugs in one i2c driver [1], and the > > correct solution was to NOT check for NULL because it

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Jean Delvare
Hi Andrew, all, Think about it. If the pointer could be NULL, then it's unlikely that the bug would have gone unnoticed so far (unless the code is very recent). Coverity found 3 such bugs in one i2c driver [1], and the correct solution was to NOT check for NULL because it just

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Chris Friesen
Jean Delvare wrote: Wow. Great point. I completely missed that possibility. In fact I didn't know that the compiler could possibly alter the order of the instructions. For one thing, I thought it was simply not allowed to. For another, I didn't know that it had been made so aware that it could

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Daniel Jacobowitz
On Mon, Mar 28, 2005 at 10:23:48PM -0800, Andrew Morton wrote: -int old=card-amplifier; +int old; if(!card) { CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO cs46xx: amp_hercules() called before

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Kyle Moffett
On Mar 29, 2005, at 09:22, Daniel Jacobowitz wrote: The thing GCC is most likely to do with this code is discard the NULL check entirely and leave only the oops; the if (!card) can not be reached without passing through card-amplifier, and a pointer which is dereferenced can not be NULL in a valid

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-29 Thread Horst von Brand
Jean Delvare [EMAIL PROTECTED] said: [Sttributions missing, sorry] Think about it. If the pointer could be NULL, then it's unlikely that the bug would have gone unnoticed so far (unless the code is very recent). Coverity found 3 such bugs in one i2c driver [1], and the correct

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-28 Thread Andrew Morton
Jean Delvare <[EMAIL PROTECTED]> wrote: > > > This patch fixes a check after use found by the Coverity checker. > > (...) > > static void amp_hercules(struct cs_card *card, int change) > > { > > - int old=card->amplifier; > > + int old; > >if(!card) > >{ > >

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-28 Thread Daniel Barkalow
On Mon, 28 Mar 2005, L. A. Walsh wrote: > However, in this case, if the author is _certain_ the > pointer can never be NULL, than an "ASSERT(card!=NULL);" might > be appropriate, where ASSERT is a macro that normally compiles > in the check, but could compile to "nothing" for embedded or >

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-28 Thread L. A. Walsh
Adrian Bunk wrote: On Sun, Mar 27, 2005 at 11:21:58PM +0200, Jean Delvare wrote: There are two cases: 1. NULL is impossible, the check is superfluous 2. this was an actual bug In the first case, my patch doesn't do any harm (a superfluous isn't a real bug). In the second case, it fixed a

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-28 Thread Matthias-Christian Ott
Jean Delvare schrieb: Hi Adrian, There are two cases: 1. NULL is impossible, the check is superfluous 2. this was an actual bug Agreed. In the first case, my patch doesn't do any harm (a superfluous isn't a real bug). The fact that it isn't a bug does not imply that the patch

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-28 Thread Matthias-Christian Ott
Jean Delvare schrieb: Hi Adrian, There are two cases: 1. NULL is impossible, the check is superfluous 2. this was an actual bug Agreed. In the first case, my patch doesn't do any harm (a superfluous isn't a real bug). The fact that it isn't a bug does not imply that the patch

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-28 Thread L. A. Walsh
Adrian Bunk wrote: On Sun, Mar 27, 2005 at 11:21:58PM +0200, Jean Delvare wrote: There are two cases: 1. NULL is impossible, the check is superfluous 2. this was an actual bug In the first case, my patch doesn't do any harm (a superfluous isn't a real bug). In the second case, it fixed a

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-28 Thread Daniel Barkalow
On Mon, 28 Mar 2005, L. A. Walsh wrote: However, in this case, if the author is _certain_ the pointer can never be NULL, than an ASSERT(card!=NULL); might be appropriate, where ASSERT is a macro that normally compiles in the check, but could compile to nothing for embedded or kernels

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-28 Thread Andrew Morton
Jean Delvare [EMAIL PROTECTED] wrote: This patch fixes a check after use found by the Coverity checker. (...) static void amp_hercules(struct cs_card *card, int change) { - int old=card-amplifier; + int old; if(!card) { CS_DBGOUT(CS_ERROR, 2,

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-27 Thread Russell King
On Mon, Mar 28, 2005 at 12:34:01AM +0200, Jean Delvare wrote: > I think that you'd be better just telling the > maintainers about the problem without providing an arbitrary patch, so > that they will actually look into the problem with their advanced > knowledge of the driver FWIW, I agree with

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-27 Thread Jean Delvare
Hi Adrian, > There are two cases: > 1. NULL is impossible, the check is superfluous > 2. this was an actual bug Agreed. > In the first case, my patch doesn't do any harm (a superfluous isn't > a real bug). The fact that it isn't a bug does not imply that the patch doesn't harm. Tricking the

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-27 Thread Adrian Bunk
On Sun, Mar 27, 2005 at 11:21:58PM +0200, Jean Delvare wrote: > Hi Adrian, > > > This patch fixes a check after use found by the Coverity checker. > > (...) > > static void amp_hercules(struct cs_card *card, int change) > > { > > - int old=card->amplifier; > > + int old; > > if(!card) >

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-27 Thread Jean Delvare
Hi Adrian, > This patch fixes a check after use found by the Coverity checker. > (...) > static void amp_hercules(struct cs_card *card, int change) > { > - int old=card->amplifier; > + int old; > if(!card) > { > CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO >

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-27 Thread Jean Delvare
Hi Adrian, This patch fixes a check after use found by the Coverity checker. (...) static void amp_hercules(struct cs_card *card, int change) { - int old=card-amplifier; + int old; if(!card) { CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-27 Thread Jean Delvare
Hi Adrian, There are two cases: 1. NULL is impossible, the check is superfluous 2. this was an actual bug Agreed. In the first case, my patch doesn't do any harm (a superfluous isn't a real bug). The fact that it isn't a bug does not imply that the patch doesn't harm. Tricking the reader

Re: Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use)

2005-03-27 Thread Russell King
On Mon, Mar 28, 2005 at 12:34:01AM +0200, Jean Delvare wrote: I think that you'd be better just telling the maintainers about the problem without providing an arbitrary patch, so that they will actually look into the problem with their advanced knowledge of the driver FWIW, I agree with Jean.