public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: vda <vda@port.imtp.ilyichevsk.odessa.ua>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [BUG] Bad #define, nonportable C, missing {}
Date: 21 Nov 2001 12:10:17 +0100	[thread overview]
Message-ID: <jeu1vobcrq.fsf@sykes.suse.de> (raw)
In-Reply-To: <01112112401703.01961@nemo>
In-Reply-To: <01112112401703.01961@nemo> (vda's message of "Wed, 21 Nov 2001 12:40:17 +0000")

vda <vda@port.imtp.ilyichevsk.odessa.ua> writes:

|> Upon random browsing in the kernel tree I noticed in accel.c:
|>     *a++ = byte_rev[*a]
|> which isn't 100% correct C AFAIK. At least Stroustrup in his C++ book
|> warns that this kind of code has to be avoided.

This is definitely causing undefined behaviour.  AFAIK, gcc 3.1 (current
CVS version) can warn about such errors (-Wsequence-point).

|> ======= bad_c.diff =======
|> diff -u --recursive linux-2.4.13-old/arch/mips/lib/tinycon.c 
|> linux-2.4.13-new/arch/mips/lib/tinycon.c
|> --- linux-2.4.13-old/arch/mips/lib/tinycon.c	Thu Jun 26 17:33:37 1997
|> +++ linux-2.4.13-new/arch/mips/lib/tinycon.c	Wed Nov 21 00:54:05 2001
|> @@ -83,14 +83,18 @@
|>    register int i;
|>  
|>    caddr = vram_addr;
|> -  for(i=0; i<size_x * (size_y-1); i++)
|> -    *(caddr++) = *(caddr + size_x);
|> +  for(i=0; i<size_x * (size_y-1); i++) {
|> +    *caddr = *(caddr + size_x);
|> +    caddr++;
|> +  }

Alternatively you can write:

  for(i=0; i<size_x * (size_y-1); i++, caddr++)
    *caddr = *(caddr + size_x);

or even:

  for(i=0; i<size_x * (size_y-1); i++, caddr++)
    *caddr = caddr[size_x];

Andreas.

-- 
Andreas Schwab                                  "And now for something
Andreas.Schwab@suse.de				completely different."
SuSE Labs, SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5

  reply	other threads:[~2001-11-21 11:10 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 [this message]
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
  -- 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=jeu1vobcrq.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox