bug-findutils
[Top][All Lists]
Advanced

[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: Sun, 6 Feb 2005 05:56:54 -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 didn'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
file's byte count 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 byte count. By doing that all the comparisons are byte
count-based and don't exhibit the bug when b and k are used.

 -Amir
 PS1 - This is my first attempt at a bug+patch submission, so if I did
 something wrong here please go easy on me :).
 PS2 - I've sent this message when I wasn't registered to the mailing
 list, so if the moderator sees it, please discard it.

#### 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;
   (*arg_ptr)++;
   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]