mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Denis Vlasenko <vda@ilport.com.ua>
To: Jesper Juhl <juhl-lkml@dif.dk>,
	Ben Fennema <bfennema@falcon.csc.calpoly.edu>
Cc: linux_udf@hpesjro.fc.hp.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] udf: uint32_t can't be less than zero
Date: Sun, 24 Apr 2005 12:42:00 +0300	[thread overview]
Message-ID: <200504241242.00619.vda@ilport.com.ua> (raw)
In-Reply-To: <Pine.LNX.4.62.0504232037060.2474@dragon.hyggekrogen.localhost>

On Saturday 23 April 2005 21:48, Jesper Juhl wrote:
> Here's a patch that removes a few bits from fs/udf/balloc.c that 
> test uint32_t values for being less than zero, which is impossible.
> 
> I know not everyone agree with this sort of cleanup, but I figured I'd do 
> the patch in any case, then leave it up to the maintainer to apply it or 
> drop it.
> 
> Please keep me on CC: when replying.
> -	if (bloc.logicalBlockNum < 0 ||
> -		(bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum))
> +	if ((bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum))

It is not immediately visible here that bloc.logicalBlockNum is unsigned.
One needs to check that by looking at the definition.

Also if later someone changes bloc.logicalBlockNum into signed entity, code
becomes buggy. Not good.

gcc already optimizes out such checks:

# gcc -O2 t.c -S -fomit-frame-pointer
# cat t.c t.s
extern unsigned v;

int f() {
    return v<0 || v>100 || v==50;
}
        .file   "t.c"
        .text
        .p2align 2,,3
.globl f
        .type   f, @function
f:
        movl    v, %edx
        xorl    %eax, %eax
        cmpl    $100, %edx
        ja      .L3
        cmpl    $50, %edx
        je      .L3
        ret
        .p2align 2,,3
.L3:
        movl    $1, %eax
        ret
        .size   f, .-f
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.3"
--
vda


      reply	other threads:[~2005-04-24  9:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-23 18:48 Jesper Juhl
2005-04-24  9:42 ` Denis Vlasenko [this message]

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=200504241242.00619.vda@ilport.com.ua \
    --to=vda@ilport.com.ua \
    --cc=bfennema@falcon.csc.calpoly.edu \
    --cc=juhl-lkml@dif.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux_udf@hpesjro.fc.hp.com \
    /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

all inboxes | Powered by JetHome®