ChangeSet 1.2231.1.190, 2005/03/28 20:09:12-08:00, [EMAIL PROTECTED]

        [PATCH] hfs: fix sign problem in hfs_ext_keycmp
        
        The key values are unsigned, so comparing them using the difference 
doesn't
        always work.
        
        (Problem reported by [EMAIL PROTECTED])
        
        Signed-off-by: Roman Zippel <[EMAIL PROTECTED]>
        Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
        Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>



 extent.c |   29 ++++++++++++++---------------
 1 files changed, 14 insertions(+), 15 deletions(-)


diff -Nru a/fs/hfs/extent.c b/fs/hfs/extent.c
--- a/fs/hfs/extent.c   2005-03-28 21:48:30 -08:00
+++ b/fs/hfs/extent.c   2005-03-28 21:48:30 -08:00
@@ -49,22 +49,21 @@
  *   This function has no side-effects */
 int hfs_ext_keycmp(const btree_key *key1, const btree_key *key2)
 {
-       unsigned int tmp;
-       int retval;
+       __be32 fnum1, fnum2;
+       __be16 block1, block2;
 
-       tmp = be32_to_cpu(key1->ext.FNum) - be32_to_cpu(key2->ext.FNum);
-       if (tmp != 0) {
-               retval = (int)tmp;
-       } else {
-               tmp = (unsigned char)key1->ext.FkType - (unsigned 
char)key2->ext.FkType;
-               if (tmp != 0) {
-                       retval = (int)tmp;
-               } else {
-                       retval = (int)(be16_to_cpu(key1->ext.FABN)
-                                      - be16_to_cpu(key2->ext.FABN));
-               }
-       }
-       return retval;
+       fnum1 = key1->ext.FNum;
+       fnum2 = key2->ext.FNum;
+       if (fnum1 != fnum2)
+               return be32_to_cpu(fnum1) < be32_to_cpu(fnum2) ? -1 : 1;
+       if (key1->ext.FkType != key2->ext.FkType)
+               return key1->ext.FkType < key2->ext.FkType ? -1 : 1;
+
+       block1 = key1->ext.FABN;
+       block2 = key2->ext.FABN;
+       if (block1 == block2)
+               return 0;
+       return be16_to_cpu(block1) < be16_to_cpu(block2) ? -1 : 1;
 }
 
 /*
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to