[PATCH] Multiple & vs. && and | vs. || bugs in 2.5.63

Norbert Kiesel (nkiesel@tbdnetworks.com)
Sun, 2 Mar 2003 04:19:23 -0800


Hi,

here are patches for some | vs. || and & vs. && bugs I found with
find ${1:-.} -name \*.c | xargs grep -En \
'![a-zA-Z0-9_ ]+(\|[^|]|\&[^&])|([^|]\||[^&]\&) *!'

I also emailed them to the maintainers/authors if I could find them, but
failed for some (e.g. uart00.c).

so long
Norbert

--- linux-2.5.63/drivers/pnp/pnpbios/core.c~ 2003-02-24 11:05:05.000000000 -0800
+++ linux-2.5.63/drivers/pnp/pnpbios/core.c 2003-03-02 03:03:34.000000000 -0800
@@ -322,7 +322,7 @@
u16 status;
if (!pnp_bios_present())
return PNP_FUNCTION_NOT_SUPPORTED;
- if ( !boot & pnpbios_dont_use_current_config )
+ if ( !boot && pnpbios_dont_use_current_config )
return PNP_FUNCTION_NOT_SUPPORTED;
status = call_pnp_bios(PNP_GET_SYS_DEV_NODE, 0, PNP_TS1, 0, PNP_TS2, boot ? 2 : 1, PNP_DS, 0,
nodenum, sizeof(char), data, 65536);
@@ -350,7 +350,7 @@
u16 status;
if (!pnp_bios_present())
return PNP_FUNCTION_NOT_SUPPORTED;
- if ( !boot & pnpbios_dont_use_current_config )
+ if ( !boot && pnpbios_dont_use_current_config )
return PNP_FUNCTION_NOT_SUPPORTED;
status = call_pnp_bios(PNP_SET_SYS_DEV_NODE, nodenum, 0, PNP_TS1, boot ? 2 : 1, PNP_DS, 0, 0,
data, 65536, 0, 0);
--- linux-2.5.63/drivers/media/dvb/dvb-core/dvb_demux.c~ 2003-02-24 11:05:11.000000000 -0800
+++ linux-2.5.63/drivers/media/dvb/dvb-core/dvb_demux.c 2003-03-02 03:26:22.000000000 -0800
@@ -221,7 +221,7 @@
return 0;
neq|=f->maskandnotmode[i]&xor;
}
- if (f->doneq & !neq)
+ if (f->doneq && !neq)
return 0;

return dvbdmxfeed->cb.sec(dvbdmxfeed->secbuf, dvbdmxfeed->seclen,
--- linux-2.5.63/drivers/video/console/fbcon.c~ 2003-02-24 11:05:37.000000000 -0800
+++ linux-2.5.63/drivers/video/console/fbcon.c 2003-03-02 03:03:34.000000000 -0800
@@ -456,7 +456,7 @@
region.color = attr_bgcol_ec(p, vc);
region.rop = ROP_COPY;

- if (rw & !bottom_only) {
+ if (rw && !bottom_only) {
region.dx = info->var.xoffset + rs;
region.dy = 0;
region.width = rw;
--- linux-2.5.63/sound/oss/gus_midi.c~ 2003-03-02 01:33:31.000000000 -0800
+++ linux-2.5.63/sound/oss/gus_midi.c 2003-03-02 03:03:33.000000000 -0800
@@ -179,7 +179,7 @@
qhead++;
}
spin_unlock_irqrestore(&lock,flags);
- return (qlen > 0) | !(GUS_MIDI_STATUS() & MIDI_XMIT_EMPTY);
+ return (qlen > 0) || !(GUS_MIDI_STATUS() & MIDI_XMIT_EMPTY);
}

#define MIDI_SYNTH_NAME "Gravis Ultrasound Midi"
--- linux-2.5.63/mm/slab.c~ 2003-02-24 11:05:39.000000000 -0800
+++ linux-2.5.63/mm/slab.c 2003-03-02 03:03:33.000000000 -0800
@@ -1643,7 +1643,7 @@
if (cachep->ctor && cachep->flags & SLAB_POISON) {
unsigned long ctor_flags = SLAB_CTOR_CONSTRUCTOR;

- if (!flags & __GFP_WAIT)
+ if (!(flags & __GFP_WAIT))
ctor_flags |= SLAB_CTOR_ATOMIC;

cachep->ctor(objp, cachep, ctor_flags);
--- linux-2.5.63/net/sctp/tsnmap.c~ 2003-02-24 11:06:01.000000000 -0800
+++ linux-2.5.63/net/sctp/tsnmap.c 2003-03-02 03:03:34.000000000 -0800
@@ -246,7 +246,7 @@
/* The Gap Ack Block happens to end at the end of the
* overflow map.
*/
- if (started & !ended) {
+ if (started && !ended) {
ended++;
_end = map->len + map->len - 1;
}
--- linux-2.5.63/drivers/serial/uart00.c~ 2003-02-24 11:05:16.000000000 -0800
+++ linux-2.5.63/drivers/serial/uart00.c 2003-03-02 03:03:34.000000000 -0800
@@ -235,8 +235,8 @@

status = UART_GET_MSR(port);

- if (!status & (UART_MSR_DCTS_MSK | UART_MSR_DDSR_MSK |
- UART_MSR_TERI_MSK | UART_MSR_DDCD_MSK))
+ if (!(status & (UART_MSR_DCTS_MSK | UART_MSR_DDSR_MSK |
+ UART_MSR_TERI_MSK | UART_MSR_DDCD_MSK)))
return;

if (status & UART_MSR_DDCD_MSK)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/