]> www.infradead.org Git - users/hch/xfsprogs.git/commit
libxfs: avoid negative (and full-width) shifts in radix-tree.c
authorEric Sandeen <sandeen@sandeen.net>
Wed, 14 Oct 2015 00:00:23 +0000 (11:00 +1100)
committerDave Chinner <david@fromorbit.com>
Wed, 14 Oct 2015 00:00:23 +0000 (11:00 +1100)
commitd781a1bfd0c8fdd7169be10c20d49f8ddf43ea4b
tree1e4f94ecf276499f439b424e8efd2ce7f5b20493
parentb4d947db398c0ed81808d7eeffe2ad162bd07524
libxfs: avoid negative (and full-width) shifts in radix-tree.c

Pull this commit over from the kernel, as libubsan spotted a
bad shift at runtime:

    commit 430d275a399175c7c0673459738979287ec1fd22
    Author: Peter Lund <firefly@vax64.dk>
    Date:   Tue Oct 16 23:29:35 2007 -0700

    avoid negative (and full-width) shifts in radix-tree.c

    Negative shifts are not allowed in C (the result is undefined).  Same thing
    with full-width shifts.

    It works on most platforms but not on the VAX with gcc 4.0.1 (it results in an
    "operand reserved" fault).

    Shifting by more than the width of the value on the left is also not
    allowed.  I think the extra '>> 1' tacked on at the end in the original
    code was an attempt to work around that.  Getting rid of that is an extra
    feature of this patch.

    Here's the chapter and verse, taken from the final draft of the C99
    standard ("6.5.7 Bitwise shift operators", paragraph 3):

      "The integer promotions are performed on each of the operands. The
      type of the result is that of the promoted left operand. If the
      value of the right operand is negative or is greater than or equal
      to the width of the promoted left operand, the behavior is
      undefined."

    Thank you to Jan-Benedict Glaw, Christoph Hellwig, Maciej Rozycki, Pekka
    Enberg, Andreas Schwab, and Christoph Lameter for review.  Special thanks
    to Andreas for spotting that my fix only removed half the undefined
    behaviour.

Signed-off-by: Peter Lund <firefly@vax64.dk>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
libxfs/radix-tree.c