From: Nathan Myers <ncm-nospam@cantrip.org>
To: linux-kernel@vger.kernel.org
Cc: vda@port.imtp.ilyichevsk.odessa.ua, alan@redhat.com,
torvalds@transmeta.com, marcelo@conectiva.com.br
Subject: Re: [BUG] Bad #define, nonportable C, missing {}
Date: Tue, 27 Nov 2001 19:03:18 +0000 [thread overview]
Message-ID: <20011127190318.A91208@cantrip.org> (raw)
vda wrote in http://marc.theaimsgroup.com/?l=linux-kernel&m=100687040003540&w=2:
> On Monday 26 November 2001 18:28, Alan Cox wrote:
> > > > MODINC(x,y) (x = (x % y) + 1)
> > >
> > > drivers/message/i2o/i2o_config.c:#define MODINC(x,y) (x = x++ % y)
> > >
> > > Alan, can you clarify what this macro is doing?
> > > What about making it less confusing?
> >
> > Nothing to do with me 8). I didnt write that bit of the i2o code. I agree
> > its both confusing and buggy. Send a fix ?
>
> This is a test to be sure my replacement is equivalent:
> --------------------
> #include <stdio.h>
> #define MODINC(x,y) (x = x++ % y)
> #define MODULO_INC(x,y) ((x) = ((x)%(y))+1)
> ...
If they really are equivalent, you have certainly found a bug.
Examining the code in i2o_config.c, it is expected that the q_in argument
ranges from 0 to I2O_EVT_Q_LEN-1, but the result of MODINC can never
be 0, and may equal I2O_EVT_Q_LEN, overindexing the array member
event_q and clobbering all the remaining members (including q_in).
The correct fix appears to be
#define MODULO_INC(x,y) ((x) = ((x)+1)%(y))
Nathan Myers
ncm at cantrip dot org
next reply other threads:[~2001-11-27 19:03 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-27 19:03 Nathan Myers [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-11-21 12:40 [BUG] Bad #define, nonportable C, missing {} vda
2001-11-21 11:10 ` Andreas Schwab
2001-11-21 11:16 ` Tim Waugh
2001-11-21 12:31 ` Ragnar Hojland Espinosa
2001-11-21 13:40 ` Jan Hudec
2001-11-21 14:19 ` Andreas Schwab
2001-11-21 14:52 ` Alexander Viro
2001-11-21 18:23 ` Neil Booth
2001-11-21 12:35 ` Vincent Sweeney
2001-11-21 13:37 ` Jan Hudec
2001-11-21 13:52 ` Mathijs Mohlmann
2001-11-21 17:12 ` vda
2001-11-26 20:28 ` Alan Cox
2001-11-27 18:03 ` vda
2001-11-27 18:38 ` Andreas Dilger
2001-11-28 13:19 ` vda
2001-11-21 14:12 ` Richard B. Johnson
2001-11-21 14:33 ` Eric W. Biederman
2001-11-21 14:56 ` Alexander Viro
2001-11-21 14:59 ` Andreas Schwab
2001-11-21 15:48 ` Momchil Velikov
2001-11-21 16:52 ` vda
2001-11-21 14:24 ` Sean Hunter
2001-11-21 14:25 ` Andreas Schwab
2001-11-22 20:43 ` Chris Gray
2001-11-22 4:24 ` Stevie O
2001-11-22 11:46 ` Horst von Brand
2001-11-22 12:03 ` Alexander Viro
2001-11-22 20:08 ` J.A. Magallon
[not found] ` <01112311540300.00886@manta>
2001-11-23 14:43 ` J.A. Magallon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20011127190318.A91208@cantrip.org \
--to=ncm-nospam@cantrip.org \
--cc=alan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo@conectiva.com.br \
--cc=torvalds@transmeta.com \
--cc=vda@port.imtp.ilyichevsk.odessa.ua \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.