[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in find's -size (+patch)

From: Amir Sela
Subject: Bug in find's -size (+patch)
Date: Sat, 5 Feb 2005 16:00:08 -0500
User-agent: Mutt/1.3.28i

I encountered this bug while trying to find files in a directory which
are smaller than 2kbytes. I was using -size -2k and it did't find the
files with sizes 1024 bytes < file < 2048 bytes. The reason for this (As
I saw), was that the b and k suffixes to -size's argument caused a
rounding up. This rounding up occurs because the current code takes the
files's bytecount and changes it to the user's choice of block size, and
then compares the two. I see no reason for this. A more logical approach
(To my opinion) Would be to normalize the *user's* choice of blocksize
into a bytecount. By doing that all comparisons are bytecount based and
don't exhibit the bug when b and k are used.

PS - This is my first attempt at submitting a patch. If I did something
wrong here, please go easy on me :).

#### BEGIN PATCH ####
diff -uprN findutils_orig/find/parser.c findutils_patched/find/parser.c
--- findutils_orig/find/parser.c        2005-02-01 01:20:06.000000000 +0200
+++ findutils_patched/find/parser.c     2005-02-05 23:52:08.000000000 +0200
@@ -1414,7 +1414,7 @@ parse_size (char **argv, int *arg_ptr)
   our_pred = insert_primary (pred_size);
   our_pred->args.size.kind = c_type;
   our_pred->args.size.blocksize = blksize;
-  our_pred->args.size.size = num;
+  our_pred->args.size.size = num*blksize;
   return (true);
diff -uprN findutils_orig/find/pred.c findutils_patched/find/pred.c
--- findutils_orig/find/pred.c  2005-02-05 18:33:40.000000000 +0200
+++ findutils_patched/find/pred.c       2005-02-05 23:51:27.000000000 +0200
@@ -1229,8 +1229,7 @@ pred_size (char *pathname, struct stat *
   uintmax_t f_val;
   (void) pathname;
-  f_val = ((stat_buf->st_size / pred_ptr->args.size.blocksize)
-          + (stat_buf->st_size % pred_ptr->args.size.blocksize != 0));
+  f_val = stat_buf->st_size;
   switch (pred_ptr->args.size.kind)
     case COMP_GT:
#### END PATCH ####

reply via email to

[Prev in Thread] Current Thread [Next in Thread]