public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: vda <vda@port.imtp.ilyichevsk.odessa.ua>
To: Andreas Dilger <adilger@turbolabs.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Mathijs Mohlmann <mathijs@knoware.nl>, Jan Hudec <bulb@ucw.cz>,
	linux-kernel@vger.kernel.org
Subject: Re: [BUG] Bad #define, nonportable C, missing {}
Date: Wed, 28 Nov 2001 11:19:32 -0200	[thread overview]
Message-ID: <01112811193201.00924@manta> (raw)
In-Reply-To: <E168SMG-0006k2-00@the-village.bc.nu> <01112716035401.00872@manta> <20011127113830.E730@lynx.no>
In-Reply-To: <20011127113830.E730@lynx.no>

On Tuesday 27 November 2001 16:38, Andreas Dilger wrote:
> On Nov 27, 2001  16:03 -0200, vda wrote:
> > On Monday 26 November 2001 18:28, Alan Cox wrote:
> > > 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)
>
> Ugh, clearly the code is broken, so we don't want equivalent code, but
> correct code.  Use the unambiguous "MODINC(x,y) ((x) = ((x) + 1) % (y))"
> form and not "have a bug that has properly defined behaviour under ANSI C".
>
> Just looking at the code, it is fairly clear that the desire is to keep
> q_in and q_out >= 0 and < I20_EVT_Q_LEN, which is the size of the event_q
> array.  With the buggy version, it is possible that you could have q_in or
> q_out == I2O_EVT_Q_LEN, which is overflowing the array.  Bad, bad, bad.

You probably right. I know nothing about what it is intended to do, I just
replaced ugly named nonportable macro with the better named portable one
which is doing the same thing.

If you are confident old macro was also buggy (it yields 1,2,3...N,1,2,3... 
and should 0,1,2,...N-1,0,1,2...) please feel free to post corrected patch.
(I suggest changing macro name too as I did)
--
vda

> --- i2o_config.c.new	Mon Oct 22 13:39:56 2001
> +++ i2o_config.c.orig	Tue Nov 27 16:03:19 2001
> @@ -45,7 +45,7 @@
>  static spinlock_t i2o_config_lock = SPIN_LOCK_UNLOCKED;
>  struct wait_queue *i2o_wait_queue;
>
> -#define MODINC(x,y) (x = x++ % y)
> +#define MODINC(x,y) ((x) = ((x) + 1) % (y))
>
>  struct i2o_cfg_info
>  {

  reply	other threads:[~2001-11-28  9:32 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2001-11-27 19:03 Nathan Myers

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=01112811193201.00924@manta \
    --to=vda@port.imtp.ilyichevsk.odessa.ua \
    --cc=adilger@turbolabs.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=bulb@ucw.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathijs@knoware.nl \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox