From: Pat LaVarre
Subject: [PATCH] fs/udf/inode.c int shift sign extends
Date: 12 Dec 2003 17:41:45 -0700
Sender: linux-fsdevel-owner@vger.kernel.org
Message-ID: <1071276105.4957.8.camel@patibmrh9>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=-/Js+Ew962blNkrAf+uNC"
Cc: linux-fsdevel@vger.kernel.org
Return-path:
Received: from email-out1.iomega.com ([147.178.1.82]:35561 "EHLO
email.iomega.com") by vger.kernel.org with ESMTP id S262228AbTLMAlw
(ORCPT );
Fri, 12 Dec 2003 19:41:52 -0500
To: bfennema@falcon.csc.calpoly.edu
List-Id: linux-fsdevel.vger.kernel.org
--=-/Js+Ew962blNkrAf+uNC
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Ben F:
Oi. fs/udf/inode.c includes an always-false test:
int type = laarr[curr].extLength & ~UDF_EXTENT_LENGTH_MASK;
...
if ((type >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
I say always false because (type >> 30) is in -2 -1 0 1, since type is
int, not unsigned int. (0x... >> 30) is in 0 1 2 3 by definition. -2
-1 never equal 2 3 of course.
Agreed?
If yes, then do you believe the patch below changes source to actually
work more as intended?
Courtesy your past work, I have test cases which provoke type =
EXT_NOT_RECORDED_NOT_ALLOCATED = 0x80000000. Via udf_debug I then see
yes indeed ((type >> 30) != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)).
To confirm my experience of C elsewhere applies here with lk gcc, I also
wrote the attached demo of (type = BITS) failing to imply ((type >> 30)
== (BITS >> 30)).
Pat LaVarre
--- linux-2.6.0-test11/fs/udf/inode.c 2003-11-26 13:46:12.000000000 -0700
+++ linux/fs/udf/inode.c 2003-12-12 17:13:27.946852824 -0700
@@ -612,7 +612,7 @@ static void udf_split_extents(struct ino
if (offset)
{
- if ((type >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
+ if (type == EXT_NOT_RECORDED_ALLOCATED)
{
udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset);
laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
@@ -629,7 +629,7 @@ static void udf_split_extents(struct ino
}
laarr[curr].extLocation.logicalBlockNum = newblocknum;
- if ((type >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
+ if (type == EXT_NOT_RECORDED_NOT_ALLOCATED)
laarr[curr].extLocation.partitionReferenceNum =
UDF_I_LOCATION(inode).partitionReferenceNum;
laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
@@ -638,7 +638,7 @@ static void udf_split_extents(struct ino
if (blen != offset + 1)
{
- if ((type >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
+ if (type == EXT_NOT_RECORDED_ALLOCATED)
laarr[curr].extLocation.logicalBlockNum += (offset + 1);
laarr[curr].extLength = type |
((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits);
--=-/Js+Ew962blNkrAf+uNC
Content-Disposition: attachment; filename=signedshift.c
Content-Type: text/x-c; name=signedshift.c; charset=UTF-8
Content-Transfer-Encoding: 7bit
#include
#define EXT_RECORDED_ALLOCATED 0x00000000
#define EXT_NOT_RECORDED_ALLOCATED 0x40000000
#define EXT_NOT_RECORDED_NOT_ALLOCATED 0x80000000
#define EXT_NEXT_EXTENT_ALLOCDECS 0xC0000000
#define DEMO(BITS) do { \
int type = BITS; \
printf("%d\n", ((type >> 30) == (BITS >> 30))); \
} while (0)
int main(void) {
DEMO(EXT_RECORDED_ALLOCATED);
DEMO(EXT_NOT_RECORDED_ALLOCATED);
DEMO(EXT_NOT_RECORDED_NOT_ALLOCATED);
DEMO(EXT_NEXT_EXTENT_ALLOCDECS);
return 0;
}
--=-/Js+Ew962blNkrAf+uNC--